Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write this with rspec

I upgraded my version of rspec to the most current version and I have tests breaking 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 will 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)>'
like image 481
Matt Elhotiby Avatar asked Jul 10 '12 21:07

Matt Elhotiby


1 Answers

Here's the doc on using expectations

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

Note the following changes

  1. should becomes to
  2. (Company, :count) becomes {Company.count}
like image 165
Dty Avatar answered Oct 27 '22 04:10

Dty