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

James Byrne lists at ruby-forum.com
Wed Apr 22 12:08:00 EDT 2009


David Chelimsky wrote:

> Ruby. Try this in irb:
> 
> 'this'
> => "this"

This passes:

  assert_equal (expected,
                fx_doc.xpath('//rdf:RDF/xmlns:channel/xmlns:title').to_s,
                "#{expected} not found")

This does not:

  fx_doc.xpath('//rdf:RDF/xmlns:channel/xmlns:title').to_s.should \
                contain(expected)

Or this:

  fx_doc.xpath('//rdf:RDF/xmlns:channel/xmlns:title').to_s.should \
                equal(expected)

gives this lovely, and illogical error:

      expected "<title>Bank of Canada: Noon Foreign Exchange 
Rates</title>"
           got "<title>Bank of Canada: Noon Foreign Exchange 
Rates</title>"

      (compared using equal?)
       (Spec::Expectations::ExpectationNotMetError)

Do not even start on how equal? in Ruby is defined completely at odds 
with common usage. I am just pointing out that this type of thing 
definitely violates the principal of least surprise.

So, test unit it is.
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list