[英]NoMethodError and failure/error in rails
The following is my search method from the controller 以下是我从控制器中搜索的方法
@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
I am trying to run the following test : 我正在尝试运行以下测试:
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
I keep getting a 我不断得到
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)>'
can anyone please let me know what i am doing wrong ?? 谁能让我知道我做错了吗? .. tried doing .should redirect_to and i still get the same error but with method 'should'. ..尝试做.should redirect_to,我仍然遇到相同的错误,但使用方法“应该”。
From this documentation, it looks like your code should be a little more like this: 从该文档中,您的代码看起来应该像这样:
it 'finds a named system account directly' do
get(:search, name: 'test')
expect(response).to be_redirect_to(game_account_path('test'))
end
Source: https://github.com/rspec/rspec-rails#controller-specs 来源: https : //github.com/rspec/rspec-rails#controller-specs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.