Wednesday, October 7, 2009

Should.not.equal vs. not should != with test_spec in Ruby

Found out today that a.should != b does not work in the version of test_spec (0.10.0) we were using in a project. Instead, you should use a.should.not.equal b or a.should.not == b.

>> "5".should.not.equal "2"
=> nil
>> "5".should != "2"
Test::Unit::AssertionFailedError: <"2"> expected but was
<"5">.
   from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:48:in `assert_block'
   from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:495:in `_wrap_assertion'
   from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:46:in `assert_block'
   from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:83:in `assert_equal'
   from /path/to/my/project/vendor/gems/test-spec-0.10.0/lib/test/spec.rb:88:in `=='
   from (irb):16

Note that the successor of test/spec from Christian Neukirchen is called Bacon.

No comments: