0
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>

有谁知道为什么?

4

2 回答 2

3

我认为是因为匹配器be_redirected_to在 Rspec 中不存在。尝试这样做:

response.should redirect_to(machine_game_path('some_machine_games'))
于 2013-02-28T18:41:30.253 回答
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

结尾

于 2013-02-28T18:42:49.087 回答