轨道中的NoMethodError和失败/错误

时间:2013-03-06 19:06:39

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2

以下是我在控制器中的搜索方法

@accounts = []
    client = GameAccounts::GameAccountsClient.new



    if params[:name]


      # Try and find a game account by id using the given name
      response = client.get_accounts_by_name(params[:name])

      if response.is_a?(Net::HTTPSuccess)
        account = client.parse_json(response)
        unless account.empty?
          session[:account] = account
          redirect_to game_account_path(params[:name])
        end
      end

      json = client.get_json(params[:limit],params[:offset],params[:name])

      @presenter = GameAccountsPresenter.new(json)

    end
  end

我正在尝试运行以下测试:

require 'spec_helper'

describe GameAccountsController do
  describe 'GET search' do
    it 'finds a named system account directly' do
     get(:search, name: 'test').to be_redirect_to(game_account_path('test'))
    end
  end
end

我一直在

GameAccountsController GET search finds a named system account directly
     Failure/Error: get(:search, name: 'test').to be_redirect_to(game_account_path('test'))
     NoMethodError:
       undefined method `to' for #<ActionController::TestResponse:0x007f8b0beb3e10>
     # ./spec/controllers/game_accounts_controller_spec.rb:6:in `block (3 levels) in <top (required)>'

任何人都可以让我知道我做错了什么? ..尝试做.should redirect_to,我仍然得到相同的错误,但方法'应该'。

1 个答案:

答案 0 :(得分:1)

从这个文档中,看起来您的代码应该更像这样:

it 'finds a named system account directly' do
  get(:search, name: 'test')
  expect(response).to be_redirect_to(game_account_path('test'))
end

来源: https://github.com/rspec/rspec-rails#controller-specs