>> When you need to check several properties of an object, what is the >> best way to match them all?
In the mail library I use a custom matcher, which lets me do things like: it "should handle |Minero Aoki <[email protected]>|" do address = Mail::Address.new('Minero Aoki <[email protected]>') address.should break_down_to({ :display_name => 'Minero Aoki', :address => '[email protected]', :local => 'aamine', :domain => 'loveruby.net', :format => 'Minero Aoki <[email protected]>', :comments => nil, :raw => 'Minero Aoki <[email protected]>'}) end The matcher in question is: # encoding: utf-8 module CustomMatchers class BreakDownTo def initialize(expected) @expected = expected end def matches?(target) @target = target @failed = false @expected.each_pair do |k,v| unless @target.send(k) == @expected[k] @failed = k end end !...@failed end def failure_message "expected #...@failed} to be |#...@expected[@failed]}| " + "but was |#[email protected](@failed)}|" end def megative_failure_message "expected #...@failed} not to be |#...@expected[@failed]}| " + "and was |#[email protected](@failed)}|" end end # Actual matcher that is exposed. def break_down_to(expected) BreakDownTo.new(expected) end end -- http://rubyx.com/ http://lindsaar.net/
_______________________________________________ rspec-users mailing list [email protected] http://rubyforge.org/mailman/listinfo/rspec-users
