>> 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 <aam...@loveruby.net>|" do address = Mail::Address.new('Minero Aoki <aam...@loveruby.net>') address.should break_down_to({ :display_name => 'Minero Aoki', :address => 'aam...@loveruby.net', :local => 'aamine', :domain => 'loveruby.net', :format => 'Minero Aoki <aam...@loveruby.net>', :comments => nil, :raw => 'Minero Aoki <aam...@loveruby.net>'}) 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 |#...@target.send(@failed)}|" end def megative_failure_message "expected #...@failed} not to be |#...@expected[@failed]}| " + "and was |#...@target.send(@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 rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users