Does anyone know of a nice dry way to run the same group of tests in different contexts. Here is a ridiculous example of wanting to run the same tests with two different setups. I don’t want to have to repeat the same tests just so I can have different setups.
context 'cat' do
setup do
@object = cat
....
end
should 'walk' do
assert @object.walk?
...
end
should 'run' do
assert @object.run?
...
end
end
context 'dog' do
setup do
@object = dog
....
end
should 'walk' do
assert @object.walk?
...
end
should 'run' do
assert @object.run?
...
end
end
I’ve done it with
merge_blockbefore. Define a class method in your test that returns aProcof your shoulds and then merge it in where appropriate.