Ruby on rails RSpec返回';未定义的局部变量或方法“signin#u path'';
当我运行RSpec时,我收到4个错误,所有错误都说明:Ruby on rails RSpec返回';未定义的局部变量或方法“signin#u path'';,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,当我运行RSpec时,我收到4个错误,所有错误都说明: undefined local variable or method `signin_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x4203fa8> Utilities.rb: def sign_in(user) visit signin_path fill_in 'Email', with: user.email.upca
undefined local variable or method `signin_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x4203fa8>
Utilities.rb:
def sign_in(user)
visit signin_path
fill_in 'Email', with: user.email.upcase
fill_in 'Password', with: user.password
click_button 'Sign In'
cookies[:remember_token] = user.remember_token
end
routes.rb:
resources :users do
member do
get :following, :followers
end
end
resources :sessions, only: [:create, :destroy, :new]
resources :microposts, only: [:create, :destroy]
resources :relationships, only: [:create, :destroy]
# Application Root
root to: 'static_pages#home'
# Static Pages
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
# Users
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
控制器规格不能以功能规格相同的方式与页面交互,因此您的
登录
实用程序将不适用于它们
如果您的控制器规格依赖于登录用户,则需要存根您的
当前\u用户
方法。如果您使用Desive,这里有一个来自他们wiki的有用页面:我正在学习Rails教程,它指导我编写该教程,然后说测试应该通过,所以我不确定是他还是我错了,当您说“stub yourcurrent_user
method”是什么意思?我不确定是他还是我错了。是你<代码>访问,填写
等。仅适用于功能/集成规范;它们在控制器规格中不起作用。@Zettetic但教程告诉我,你能建议一个解决方法吗?它不应该是sign_in_path吗?我遇到了类似的问题,下面的问题解决了:
resources :users do
member do
get :following, :followers
end
end
resources :sessions, only: [:create, :destroy, :new]
resources :microposts, only: [:create, :destroy]
resources :relationships, only: [:create, :destroy]
# Application Root
root to: 'static_pages#home'
# Static Pages
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
# Users
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete