"nil is not a symbol" for model count in rspec matcher
capybara, rspec, ruby-on-rails, ruby-on-rails-3, tdd
Solution
I don't think you can use the `change` matcher like this on the response object. Try this:
expect {
click_button "Check Prices"
}.to change{ CheckPrice.count }.by(1)
This makes more semantic sense, too, IMO.
See this cheat sheet for more examples.
Problem
I am trying to write an integration test where if a user clicks on a button, it creates a new record in the database (CheckPrice model). I am running into the error `nil is not a symbol` when I try to run my test. ``` require 'spec_helper' describe 'CheckPrice', type: :request, js: true do it "should create a new CheckPrice record when user clicks Check Price on topic page" do city = create :city hotel = create :hotel affiliate_link = create :affiliate_link visit '/hotel-bilboa-hotel' sleep 2 click_button "Check Prices" response.should change(CheckPrice.count).by(1) end end ``` When "Check Prices" is clicked, there is an event listener that triggers the new method in the checkprices_controller. The error seems to occur on the last line `response.should change(CheckPrice.count).by(1)`. It looks like the method does not recognize the model CheckPrice. How do I reference the CheckPrice table? Thanks.