Hello, RSpec fans!
Today I was playing with an idea of negative tests. They are surely a thing one may need while working on a long-term project. For example, you may need negative testing when you plan a future major change. You may want to plan this change as a test, but it should not fail today and it should be quite easy to rewrite it to non-failing test tomorrow.
Of course, you can just create a specification that tests that this planned functionality does not work today. And then, rewrite each test within it to opposite tomorrow.
But what if this could be done easier?
And it could! I’ve spent few minutes to create a quick-n-dirty specify_negatively implementation for rspec. I’m not sure whether it will be useful or even working properly in all cases, but it seems to pass on a simple test:
context "Test context" do
specify "test" do
(2+2).should == 4
end
specify_negatively "negative test" do
(2+2).should == 5
end
specify_negatively "bad negative test" do
(2+2).should == 4
end
end
Test context
- test
- negative test
- bad negative test (FAILED - 1)
1)
'Test context bad negative test' FAILED
This specification was expected to fail, but nothing failed
Finished in 0.041288 seconds
3 specifications, 1 failure
What do you think?




