Zhenning Guan
2009-May-19 15:09 UTC
[rspec-users] Forum.count.should, should doesn''t work?
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? -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2009-May-19 15:19 UTC
[rspec-users] Forum.count.should, should doesn''t work?
On Tue, May 19, 2009 at 10:09 AM, Zhenning Guan <lists at ruby-forum.com> wrote:> 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 fineThat''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).> why Forum.count.should throw a > error? > how could I do? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Zhenning Guan
2009-May-20 09:11 UTC
[rspec-users] Forum.count.should, should doesn''t work?
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... -- Posted via http://www.ruby-forum.com/.
Zhenning Guan
2009-May-20 09:18 UTC
[rspec-users] Forum.count.should, should doesn''t work?
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. -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2009-May-20 14:23 UTC
[rspec-users] Forum.count.should, should doesn''t work?
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. HTH, David