我想测试应用程序中的每条路线,并了解到我应该在集成测试中执行此操作:在 ruby on Rails 中测试路线的位置 https://stackoverflow.com/questions/5290245/where-to-test-routes-in-ruby-on-rails
但是我收到以下错误:
NoMethodError: undefined method `authenticate?' for nil:NilClass
/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.2/lib/devise/rails/routes.rb:286:in `block in authenticated'
网上有很多人提到,在集成测试中不能使用 Devise::TestHelpers --设计 Google 群组 https://groups.google.com/forum/?fromgroups=#!topic/plataformatec-devise/QPOzZ1n6mfg,
设计 Github 页面 https://github.com/plataformatec/devise#test-helpers
我如何测试如下路线?
# config/routes.rb
devise_for :users
authenticated :user do
root to: 'static#home'
end
root to: 'static#landing'
我正在运行测试单元测试$ rake test:integration
Devise::TestHelpers 通过将内容直接放入会话中来工作。使用 Capybara 运行集成测试时,您无权访问服务器端会话。您只需访问浏览器即可。
在我们的应用程序中,我们的集成测试使用这样的辅助方法,通过用户界面与 Devise 交互:
def authenticate(user, password = nil)
password ||= FactoryGirl.attributes_for(:user)[:password]
visit new_user_session_path
fill_in 'email', with: user.email
fill_in 'password', with: password
click_on 'Login'
expect(current_path).to eq welcome_path
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)