2016-02-13 91 views
3

当我运行此RSpec示例时,它会通过,但我收到了弃用警告。如何解决有关新expect语法的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("[email protected]") 
    find("#passwordsignup").set("12345678") 
    find("#passwordsignup_confirm").set("") 
    find(".signin").click 
    sleep 2 
    page.should have_content "Confirm Password Does not Match" 
    end 
end 

这里是输出:

废弃警告:

从rspec的期许老:should语法使用should无 明确允许的语法已经过时了。使用新的:expect 语法或明确启用:should而不是config.expect_with(:rspec) { |c| c.syntax = :should }。从 /home/rails/rails_nimish/Devise_use/spec/features/users_spec.rb:113:in `块调用(4级)'

enter image description here

如何解决此警告?

更新:解决 我刚刚更换

page.should have_content “确认密码不匹配”

有:由于有消息说你

expect(page).to have_content "Confirm Password Does not Match" 
+1

这将是更好的在你的问题的身体进入预警的实际文本。使用Google进行阅读和查找会更容易。 –

+0

做它说什么? –

+0

我不想使用应该,因为它是旧的语法,我正在寻找预期(页面)语法。 – indb

回答

2

有两种选择:

  • 明确配置RSpec以允许.should。不要使用该选项; .should已弃用,未来可能不会得到支持。如果你真的想允许.should,不过,你可以通过添加这对您的spec_helper.rb(或编辑RSpec中,嘲笑的示例配置是可能已经存在)做到这一点:

    RSpec.configure do |config| 
        config.expect_with :rspec do |expectations| 
        expectations.syntax = :should 
        end 
    end 
    

    如果你想同时使用expect.should,设置

    expectations.syntax = [:expect, :should] 
    

    但不这样做,挑一个和你的测试套件任何地方使用它。

  • 重写你的期望,

    expect(page).to have_content "Confirm Password Does not Match" 
    

    如果你有很多规格,其语法需要升级,你可以使用the transpec gem来自动执行。

备注:请勿在您的期望之前使用sleep 2Capybara's have_content matcher waits for you.

+0

是的,你的第二个选项回答了我的问题。谢谢。 – indb

4

我刚刚更换:

页。应该have_content“确认密码不匹配”

有:

expect(page).to have_content "Confirm Password Does not Match"