[rspec-users] Cucumber ".should contain(expected) does but fails anyway

James Byrne lists at ruby-forum.com
Wed Apr 22 16:22:41 EDT 2009

David Chelimsky wrote:
> On Wed, Apr 22, 2009 at 2:09 PM, James Byrne <lists at ruby-forum.com> 
> wrote:
>>>> � � � (Spec::Expectations::ExpectationNotMetError)
>> Rates</title>"
>> WDYT?
> I like the idea, though I think it's helpful to also have the strings
> in the case of String objects. But having the class and object id
> would really help tell the story we're looking for.
> wdYt?

After I posted I reconsidered the situation.  When equal? is the 
comparison then the first step should be to check for identical objects 
(duhh). If that fails then do a supplementary == check. If that passes 
then append the ", did you mean '==' notice and display the values 
together with the object.metaclass.  Otherwise, just display the objects 
are different warning and the object.metaclass for each.

However, on reconsideration again, it seems best to skip the second 
check and just display this sort of thing for all equal? failures:

  expected: "#<Class:#<String:0x2b6950315300>> => '<title>Bank of 
Canada: Noon Foreign Exchange Rates</title>'"
       got: "#<Class:#<String:0x2b695026e898>> => '<title>Bank of 
Canada: Noon Foreign Exchange Rates</title>'"

   (equal?: expected object is not the object returned, did you mean 

Of course, to support this outside Rails, RSpec will have to provide and 
require the metaclass.rb (shamelessly stolen from Rails).

  unless Object.respond_to? :metaclass do
    class Object
      # Get object's meta (ghost, eigenclass, singleton) class
      def metaclass
        class << self


Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list