ビルドしていないアプリケーションのコントローラテストを書いていますので、間違いなく学習プロセスでした。これは、AbstractController :: Baseから直接継承するコントローラに初めて遭遇したときです。明らかに、他のコントローラと同じように動作しません。Rspecコントローラは、AbstractController :: Baseを継承するコントローラをRailsでテストします。
そのフォーマットはおおよそ次のとおりです。
class SchwadGenericController < AbstractController::Base
def schwad_method var_one, var_two = nil, var_three = nil
if var_two.blank?
var_one.generic_method
end
render template: "schwad_templates/generic_template", layout: false
end
end
私は私が起こることをANYTHINGを取得する時に、現在午前ところ、これは、通常のテストを試してみました。
require 'rails_helper'
describe SchwadGenericController do
# before(:each) do
# SchwadGenericController.skip_authorize_resource
# end
# login_user
let!(:variable){ create(:my_factory_variable) }
describe 'controller methods' do
it 'should hit this method' do
binding.pry
SchwadGenericController.schwad_method(variable)
# expect(response).to_render template: "schwad_templates/generic_template"
end
end
end
ここでは、おおよその失敗が上陸しています。
Failures:
1) SchwadGenericController controller methods should hit this method
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `request=' for # <SchwadGenericController:0x007f8022db0a20>
私は抽象コントローラと、ここレールにおけるその役割をよく読んで:https://www.mobomo.com/2012/06/and-you-thought-render-farms-were-just-for-pixar/
私はここにドキュメントをよく読んで:http://api.rubyonrails.org/classes/AbstractController/Base.html
私は本当に別の本に目のセットと指導をお願い申し上げますAbstractController :: Baseから継承しているコントローラを使って、コントローラとそのメソッドをどのようにテストしたかについては、どうしたらいいですか? AbstractControllerから直接拡張
-Schwad
ありがとうございます。この方法で実行して報告します。 – Schwad