Skip to content

Instantly share code, notes, and snippets.

@kddnewton
Created September 30, 2022 16:58
Show Gist options
  • Save kddnewton/65ac65fd1a66fe964d3eeea54c5c9590 to your computer and use it in GitHub Desktop.
Save kddnewton/65ac65fd1a66fe964d3eeea54c5c9590 to your computer and use it in GitHub Desktop.
Minitest example
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