Read more

rspec_candy 0.2.0 now comes with our most popular matchers

Henning Koch
August 06, 2012Software engineer at makandra GmbH

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

be_same_number_as

Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

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
Posted by Henning Koch to makandra dev (2012-08-06 18:06)