如何解决RSpec关于新的Expect语法的弃用警告? [英] How to resolve RSpec's deprecation warning about the new expect syntax?
问题描述
当我运行此RSpec示例时,它通过了,但是我收到了弃用警告。
When I run this RSpec example, it passes but I'm getting a deprecation warning.
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
这是输出:
弃用警告:
从rspec-expectations中使用
应该
不推荐使用不带
的旧:应该
语法。使用新的:expect
语法,或使用config显式启用
。从:should
。 Expect_with(:rspec)
{| c | c.syntax =:should}
/home/rails/rails_nimish/Devise_use/spec/features/users_spec.rb:113:在
`block(4个级别)'
Using
should
from rspec-expectations' old:should
syntax without explicitly enabling the syntax is deprecated. Use the new:expect
syntax or explicitly enable:should
withconfig.expect_with(:rspec) { |c| c.syntax = :should }
instead. Called from /home/rails/rails_nimish/Devise_use/spec/features/users_spec.rb:113:in `block (4 levels) in '
中调用
如何解决此警告?
更新:解决方案
我刚刚替换了
Update:solution I just replaced
页面。 have_content确认密码不匹配
page.should have_content "Confirm Password Does not Match"
with:
expect(page).to have_content "Confirm Password Does not Match"
推荐答案
如消息所示,您有两个选择:
As the message says you have two options:
-
将RSpec显式配置为允许
。应该
。不要使用该选项;。应该
已过时,将来可能不会得到很好的支持。但是,如果您确实想允许。应该
,则可以通过将其添加到spec_helper.rb中(或编辑可能已经存在的rspec-mocks的示例配置)来实现。在那里):
Explicitly configure RSpec to allow
.should
. Don't use that option;.should
is deprecated and will likely not be as well supported in the future. If you really wanted to allow.should
, though, you could do it by adding this to your spec_helper.rb (or editing the example configuration of rspec-mocks that is probably already there):
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.syntax = :should
end
end
如果您想同时使用期望
和。应该
,设置
If you want to use both expect
and .should
, set
expectations.syntax = [:expect, :should]
但是不要那样做,选择一个并在测试套件中的任何地方使用它。
But don't do that, pick one and use it everywhere in your tests suite.
将您的期望重写为
expect(page).to have_content "Confirm Password Does not Match"
如果您有许多需要升级其语法的规范,则可以使用 transpec宝石>自动执行。
If you have many specs whose syntax needs upgrading, you can use the transpec gem to do it automatically.
侧面说明:请勿睡眠2
超出您的期望。 水豚属植物的 have_content
匹配器正等着您。
Side note: Don't sleep 2
before your expectation. Capybara's have_content
matcher waits for you.
这篇关于如何解决RSpec关于新的Expect语法的弃用警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!