I currently dynamically generate tests using a JSON file, like so:
Rakefile:
#...
Rake::TestTask.new(:run_spec_tests) { |t|
t.libs = ['lib']
t.pattern = 'test/test_spec.rb'
t.verbose = true
t.warning = false
}
test/test_spec.rb
class TestSpec < Minitest::Test
cases = JSON.parse(open('test/tests.json', 'r').read)
cases.each do |testcase|
# run hundreds of tests
define_method("test_example_#{testcase['example']}") do
puts "Testing example #{testcase['example']}"
actual = mything.render(testcase['input'])
assert_equal testcase['output'], actual, testcase['output']
end
end
end
Every object in that JSON file has an associated number, so I'd like to be able to reference just one of those tests and have Rake::TestTask do its thing.
Unfortunately, there doesn't seem to be a way to pass arguments to a TestTask like
rake test run_spec_test 123
so that the TestTask can just run one of the previously dynamically defined methods.
Am I missing something?