Rspec NoMethodError: undefined method `call', yet everything works via rails console-Collection of common programming errors
I’m a rails/rspec newb trying to learn. I’ve setup the following data model (excerpt)
t.string :foo
t.string :bar
t.date :future_date
and I have a web form to create these entries associated with a user, similar to the microposts in this rails tutorial. The web form looks like this (excerpt):
with a button, “Create”, that initiates the post. Everything seems to work fine via rails console; the web form displays correctly, the entries are created correctly, the database is being populated correctly. However, when I run rspec I get
NoMethodError:
undefined method `call' for #
Here is the relevant request spec (excerpt):
it "should not create a foobar" do
expect { click_button "Create" }.should_not change(Foobar, :count)
end
In other words, click “Create” with no info filled in. I have a similar example later with info filled in but nearly the same click_button that also throws this error (should change .by(1)). I have similar click_button tests working fine for the user creation portion (nothing/something entered) which, other than future_date, is very similar. That, plus something I ran across in my endless googling, leads me to believe the date is somehow to blame, perhaps an inconsistency in versions or something. Especially since in actual use everything is working fine. This is with ruby 1.9.3, Rails 3.2.6, and Rspec 2.11.1. Any insight is very much appreciated.
-
In RSpec >= 2.11 you should use
to
method instead ofshould
expect { click_button "Create" }.to_not change(Foobar, :count)
-
That should say…
it "should not create a foobar" do lambda { click_button "Create" }.should_not change(Foobar, :count) end
… so
lambda
, notexpect
.
Originally posted 2013-11-10 00:14:46.