Last active
September 29, 2022 17:19
-
-
Save JoshCheek/04913bacd0f22d0203427b779ac07541 to your computer and use it in GitHub Desktop.
Example code for twitter comment I made about making tests less tedious
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
# https://twitter.com/josh_cheek/status/1575535820945211394 | |
require 'rspec/autorun' | |
def idk(source) | |
tag, args = source.split(" ", 2) | |
[ "@_target", | |
%("<#{tag}>"), | |
"_output(#{args})", | |
%("</#{tag}>"), | |
].join(" << ") | |
end | |
RSpec.configure { _1.formatter = "documentation" } | |
RSpec.describe 'templating lib or smth' do | |
def self.test!(name, source, output) | |
it(name) { expect(idk(source)).to be == output } | |
end | |
test! "positional argument splats", | |
%(h1 *args), | |
%{@_target << "<h1>" << _output(*args) << "</h1>"} | |
test! "multiple positional argument splats", | |
%(h1 *a, *b), | |
%{@_target << "<h1>" << _output(*a, *b) << "</h1>"} | |
test! "a variable", | |
%(h1 name), | |
%{@_target << "<h1>" << _output(name) << "</h1>"} | |
end | |
# >> | |
# >> templating lib or smth | |
# >> positional argument splats | |
# >> multiple positional argument splats | |
# >> a variable | |
# >> | |
# >> Finished in 0.00113 seconds (files took 0.05105 seconds to load) | |
# >> 3 examples, 0 failures | |
# >> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment