ind*_*ndb 6 rspec ruby-on-rails capybara rspec-rails rspec3
当我运行这个RSpec示例时,它会通过,但我收到了弃用警告.
context "should have valid detail for signup" do
it "should give error for invalid confirm password" do
find("#usernamesignup").set("Any_name")
find("#mobile_number").set("1234567890")
find("#emailsignup").set("mymail@yopmail.com")
find("#passwordsignup").set("12345678")
find("#passwordsignup_confirm").set("")
find(".signin").click
sleep 2
page.should have_content "Confirm Password Does not Match"
end
end
Run Code Online (Sandbox Code Playgroud)
这是输出:
弃用警告:
不推荐使用
shouldrspec-expectations的旧:should语法而不显式启用语法.使用新的:expect语法或明确启用:should与config.expect_with(:rspec) { |c| c.syntax = :should }替代.来自/home/rails/rails_nimish/Devise_use/spec/features/users_spec.rb:113:in`block(4 levels)in'
如何解决此警告?
更新: 我刚刚更换的解决方案
page.should have_content"确认密码不匹配"
有:
expect(page).to have_content "Confirm Password Does not Match"
Run Code Online (Sandbox Code Playgroud)
正如消息所说,您有两种选择:
明确配置RSpec以允许.should.不要使用该选项; .should已被弃用,将来可能不会得到很好的支持..should但是,如果您真的想要允许,可以通过将其添加到spec_helper.rb(或编辑可能已经存在的rspec-mocks的示例配置)来实现:
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.syntax = :should
end
end
Run Code Online (Sandbox Code Playgroud)
如果你想同时使用expect和.should,请设置
expectations.syntax = [:expect, :should]
Run Code Online (Sandbox Code Playgroud)
但是不要这样做,选择一个并在测试套件中的任何地方使用它.
重写你的期望
expect(page).to have_content "Confirm Password Does not Match"
Run Code Online (Sandbox Code Playgroud)
如果您有许多语法需要升级的规范,您可以使用transpec gem自动执行此操作.
旁注:不要sleep 2在你的期望之前.Capybara的have_content匹配器等着你.
我刚换了:
page.should have_content "Confirm Password Does not Match"
Run Code Online (Sandbox Code Playgroud)
有:
expect(page).to have_content "Confirm Password Does not Match"
Run Code Online (Sandbox Code Playgroud)