Created
September 30, 2022 16:58
-
-
Save kddnewton/65ac65fd1a66fe964d3eeea54c5c9590 to your computer and use it in GitHub Desktop.
Minitest example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "minitest/autorun" | |
class TemplatingTest < Minitest::Test | |
def test_positional_argument_splats | |
assert_templates <<~RUBY, "h1", "*args" | |
@_target << "<h1>" << _output(*args) << "</h1>" | |
RUBY | |
end | |
def test_multiple_positional_argument_splats | |
assert_templates <<~RUBY, "h1", "*a, *b" | |
@_target << "<h1>" << _output(*a, *b) << "</h1>" | |
RUBY | |
end | |
def test_a_variable | |
assert_templates <<~RUBY, "h1", "name" | |
@_target << "<h1>" << _output(name) << "</h1>" | |
RUBY | |
end | |
private | |
def some_compilation_method(tag, args) | |
<<~RUBY | |
@_target << "<#{tag}>" << _output(#{args}) << "</#{tag}>" | |
RUBY | |
end | |
def assert_templates(expected, tag, args) | |
assert_equal expected, some_compilation_method(tag, args) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment