Forum: RSpec Forum.count.should, should doesn't work?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zhenning G. (Guest)
on 2009-05-19 19:09
Scenario: List Tasks
  Then I should have 3 forums
-------------

Then /^I should have ([0-9]+) forums$/ do |counts|
  Forum.count.should == counts.to_i
end

====
  When I go to the homepage   #
features/step_definitions/webrat_steps.rb:10
    Then I should have 3 forums #
features/step_definitions/forums_steps.rb:1
      expected: 3,
           got: 0 (using ==)
      Diff:
      @@ -1,2 +1,2 @@
      -3
      +0
       (Spec::Expectations::ExpectationNotMetError)
      features/forums.feature:8:in `Then I should have 3 forums'

1 scenario (1 failed)
2 steps (1 failed, 1 passed)

===
Forum.count == counts.to_i does fine! why Forum.count.should throw a
error?
how could I do?
David C. (Guest)
on 2009-05-19 19:50
(Received via mailing list)
On Tue, May 19, 2009 at 10:09 AM, Zhenning G. 
<removed_email_address@domain.invalid>
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).
Zhenning G. (Guest)
on 2009-05-20 13:11
David C. wrote:
> On Tue, May 19, 2009 at 10:09 AM, Zhenning G. <removed_email_address@domain.invalid>
> 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...
Zhenning G. (Guest)
on 2009-05-20 13:18
Zhenning G. wrote:
> David C. wrote:
>> On Tue, May 19, 2009 at 10:09 AM, Zhenning G. <removed_email_address@domain.invalid>
>> 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.
David C. (Guest)
on 2009-05-20 18:25
(Received via mailing list)
On Wed, May 20, 2009 at 4:18 AM, Zhenning G. 
<removed_email_address@domain.invalid>
wrote:
>>>> Forum.count == counts.to_i does fine
> 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.

HTH,
David
This topic is locked and can not be replied to.