【发布时间】:2015-08-15 12:22:12
【问题描述】:
将 rspec 更新为 3.3.3 后,我收到了很多弃用警告..
should我改自:
describe "visiting the user index" do
before {visit users_path}
scenario{ should have_title('Sign in')}
end
到:
describe "visiting the user index" do
before {visit users_path}
scenario{ expect have_title('Sign in')}
end
我希望我的重构没问题。
我在shuold_not 上收到了弃用警告,其中expect_not 不起作用。在网络上,我不断访问this 页面,但我无法理解should_not resplacement 中的想法。
无论如何,这个例子已被弃用:
describe "visiting Users#edit page" do
before { visit edit_user_path(wrong_user)}
scenario{ should_not have_title('Edit user')}
end
这确实得到一个未定义的方法错误:
describe "visiting Users#edit page" do
before { visit edit_user_path(wrong_user)}
scenario{ expect_not have_title('Edit user')}
end
【问题讨论】:
-
试试
expect(page).not_to have_title('Edit user')。 -
rspec 返回:
Capybara::RSpecMatchers::HaveTitle implements a legacy RSpec matcher protocol. For the current protocol you should expose the failure messages via the 'failure_message' and 'failure_message_when_negated' methods. -
是的,这是水豚的问题。您需要更新您的 Capybara 版本。
标签: ruby-on-rails ruby-on-rails-4 rspec rspec3