rspec_candy 0.2.0 now comes with our most popular matchers

Updated . Posted . Visible to the public.

Our rspec_candy Show archive.org snapshot gem now gives you three matchers:

be_same_number_as

Tests if the given number is the "same" as the receiving number, regardless of whether you're comparing Fixnums (integers), Floats and BigDecimals:

100.should be_same_number_as(100.0)
50.4.should be_same_number_as(BigDecimal('50.4'))

Note that "same" means "same for your purposes". Internally the matcher compares normalized results of #to_s.

be_same_second_as

Tests if the given Time or DateTime is the same as the receiving Time or DateTime, ignoring sub-second differences:

Time.parse('2012-12-01 14:00:00.5').should == Time.parse('2012-12-01 14:00')

Note that two times in a different time zones will still be considered different.

include_hash

Matches if the given hash is included in the receiving hash:

{ :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a') # passes
{ :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'b') # fails
{ :foo => 'a', :bar => 'b' }.should include_hash(:foo => 'a', :baz => 'c') # fails
Henning Koch
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2012-08-06 16:06)