简体   繁体   English

我如何用rspec写这个

[英]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 我将我的rspec版本升级到最新版本,并且测试打破了具有类似语法的测试

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

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 should成为to
  2. (Company, :count) becomes {Company.count} (Company, :count)成为{Company.count}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为包含语言环境的链接编写Rspec测试? - How Do I Write An Rspec Test for A Link Which Includes a Locale? 如果失败,如何编写bash脚本以中止rspec测试 - How do I write a bash script to abort a rspec test if it fails 如何为此before_validation回调编写rspec测试? - How do I write an rspec test for this before_validation callback? 我如何用rspec测试呢? - How do I test this with rspec? 如何为登录编写Omniauth RSpec? - How can I write an Omniauth RSpec for the login? 如何编写RSpec测试以确认密码重置令牌已保存到数据库? - How do I write an RSpec test that confirms Password Reset Token has been Saved to the DB? 如何在Rails 3中编写rspec测试来测试用户在创建后是否使用authlogic进行签名? - How do I write an rspec test in Rails 3 to test if a user is signed with authlogic after being created? Rails 5 / rspec / capybara:如何编写AJAX表单的功能请求? - Rails 5/rspec/capybara: How do I write a feature request for an AJAX form? 如何编写确保发送电子邮件的Rspec控制器测试? - How do I write an Rspec controller test that makes sure an e-mail is sent? 对于 RSpec,如何编写捕获嵌套目录中的 _spec 文件的表达式? - With RSpec, how do I write an expression that captures _spec files in nested directories?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM