我使用的是rspec-rails 3.5.2,capybara 2.5.0,rails 4.2.4
这是我的测试:
new_user_registration_path
$ rspec spec/features/visitors/sign_up_spec.rb
F
Failures:
1) Sign Up visitor can sign up with valid email address and password
Failure/Error: visit new_user_registration_path
NoMethodError:
undefined method `empty?' for nil:NilClass
# ./spec/features/visitors/sign_up_spec.rb:15:in `block (2 levels) in <top (required)>'
Finished in 0.17765 seconds (files took 3.54 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/features/visitors/sign_up_spec.rb:14 # Sign Up visitor can sign up with valid email address and password
方法不存在,这是错误:
visit '/'
如果我尝试.rspec
就可以了。
这是我的$ cat .rspec
--color
--require rails_helper
文件
14: scenario 'visitor can sign up with valid email address and password' do
15: binding.pry
=> 16: visit new_user_registration_path
17: fill_in 'user_email', with: "#{SecureRandom.hex}}@example.com"
[1] pry(#<RSpec::ExampleGroups::SignUp>)> new_user_registration_path
NoMethodError: undefined method `empty?' for nil:NilClass
from /home/user/.rvm/gems/ruby-2.2.6@project/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:769:in `optimize_routes_generation?'
[2] pry(#<RSpec::ExampleGroups::SignUp>)>
未加载Rails路由。
我用Pry来调查:
$ rake routes | grep "new_user_registration"
new_user_registration GET /users/sign_up(.:format) my_devise/registrations#new
路线:
$ rails c test
Running via Spring preloader in process 5692
Loading test environment (Rails 4.2.4)
2.2.6 :001 > Rails.application.routes.url_helpers.new_user_registration_path
NoMethodError: undefined method `empty?' for nil:NilClass
这是来自控制台:
{{1}}
想法?
答案 0 :(得分:0)
尝试加入spec/rails_helper.rb
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'