[rspec-users] Forum.count.should, should doesn't work?

David Chelimsky dchelimsky at gmail.com
Wed May 20 10:23:24 EDT 2009

On Wed, May 20, 2009 at 4:18 AM, Zhenning Guan <lists at ruby-forum.com> wrote:
> Zhenning Guan wrote:
>> David Chelimsky wrote:
>>> On Tue, May 19, 2009 at 10:09 AM, Zhenning Guan <lists at ruby-forum.com>
>>> wrote:
>>>> features/step_definitions/webrat_steps.rb:10
>>>> 1 scenario (1 failed)
>>>> 2 steps (1 failed, 1 passed)
>>>> ===
>>>> Forum.count == counts.to_i does fine
>>> That's not an expectation so it won't pass or fail. I'd bet that's
>>> returning false, which is not going to make a step fail (only an error
>>> will).
>> I means....
>> Forum.count == counts.to_i
>> doesn't work...
> correct it
> Forum.count.should == counts.to_i
> doesn't work.

You're confusing me now :)

So, if I understand correctly, this fails:

  Forum.count.should == counts.to_i

and this passes

  Forurm.count == counts.to_i

The fact that the latter is passing is a false positive, because it is
not actually testing anything. It is a boolean statement that returns
true or false, and it doesn't matter whether it returns true or false
because the step will pass in either case. The only thing that makes a
step fail is an error. When you say "Forum.count.should ==
counts.to_i" and those two values are not equal, an ExpectationNotMet
error is raised by RSpec. In that case you get a failure.

The reason "Forum.count.should == counts.to_i" is failing is because
... well, it is failing. Forum.count is returning 0 when you're
expecting 3.


More information about the rspec-users mailing list