Last week I discovered this little new testing framework and I am finding it’s quite intriguing with its unusual syntax.
What I like the most is that you have to explicitly set a subject in the “describe” block and explicitly set a method call with params in the expectation block, thus making pretty clear what’s going on with the tests.
It’s also worth noting that the framework offers different levels of specification via MUST, SHOULD and MAY keywords. Look at the following example:
require 'fix'
person = String.new ('yukihiro matsumoto')
Fix.describe person do
on :split, ' ' do
it { MUST Eql: ['yukihiro', 'matsumoto'] }
end
on :capitalize do
it { SHOULD Eql: 'Yukihiro Matsumoto' }
end
on :to_json do
it { MAY Eql: "{ "name": "yukihiro", "surname": "matsumoto"}" }
end
end
The last two tests report an info rather than an error because their expectations are not strict (MAY allows non existent methods to be called, while SHOULD allows different results but requires the method to exists).
Leave a Reply