require 'spec_helper'
describe MachineGamesController do
describe 'GET search' do
it 'blah blah' do`
get :search, name: 'some_machine_games'
expect(response).to be_redirected_to(machine_game_path('some_machine_games'))
end
end
以上是我用来测试控制器的rspec。它也放在/ spec / controllers /目录中。我正在接受
NoMethodError:
undefined method `redirected_to?' for #<ActionController::TestResponse:0x007fce065ba640>
有人知道为什么吗?
答案 0 :(得分:3)
我认为是因为Rspec中不存在匹配器 be_redirected_to 。试着这样做:
response.should redirect_to(machine_game_path('some_machine_games'))
答案 1 :(得分:1)
redirected_to不是rspec匹配器。你需要改写:
describe MachineGamesController do
describe 'GET search' do
it 'blah blah' do
get(:search, name: 'some_machine_games').should redirect_to(machine_game_path('some_machine_games'))
end
end
end
端