5

我将我的 rspec 版本升级到最新版本,并且我的测试中断具有相似的语法

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

我查看了文档,但在当前版本中看不到任何可以做到这一点的东西......关于如何实现这一点的任何想法

我得到的错误是

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)>'
4

1 回答 1

9

这是关于使用期望的文档

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

请注意以下更改

  1. should变成to
  2. (Company, :count)变成{Company.count}
于 2012-07-10T23:18:22.980 回答