簡體   English   中英

NoMethodError和Rails中的故障/錯誤

[英]NoMethodError and failure/error in rails

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

@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,我仍然遇到相同的錯誤,但使用方法“應該”。

從該文檔中,您的代碼看起來應該像這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM