Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RSpec返回';未定义的局部变量或方法“signin#u path'';_Ruby On Rails_Ruby_Rspec - Fatal编程技术网

Ruby on rails RSpec返回';未定义的局部变量或方法“signin#u path'';

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

当我运行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.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 your
current_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