How to write it with rspec

I upgraded my rspec version to the latest version and I have tests that have similar syntax

it "should delete a company" do
  expect { click_link "Delete Company" }.should change(Company, :count).by(-1)
end

I looked at the documentation and I could not see anything that would do this in the current verion ... any ideas on how to achieve this

The error I get is

9) Company Pages Edit page as an admin user should delete a company
   Failure/Error: expect { click_link "Delete Company" }.should change(Company, :count).by(-1)
   NoMethodError:
     undefined method `call' for #<RSpec::Expectations::ExpectationTarget:0x007fccafdfc360>
   # ./spec/requests/companies_spec.rb:79:in `block (3 levels) in <top (required)>'
+5
source share
1 answer

Here's the doc when using expectations

it "should delete a company" do
  expect { click_link "Delete Company" }.to change{Company.count}.by(-1)
end

Please note the following changes.

  • should becomes to
  • (Company, :count) becomes {Company.count}
+9
source

All Articles