0
コントローラーテストを作成していて、Controller1のcall_dashboard_functionを確認したかったのです。ダブル、モックまたはスタブのコントローラー側オブジェクトをテストする方法
class Controller1 < ApplicationController
before_action :init_dashb
def call_dashboard_function
@dashb.do_something!
end
def init_dashb
@dashb ||= Dashboard.new(current_user)
end
end
class Dashboard
#... this is a facade class
end
実際のテスト:
test "should do something" do
sign_in @user
patch :call_dashboard_function
end
問題は、私はそれのための分離テストを持っているので、ダッシュボードクラスをテストしたくないです。だから私はこのクラスの振る舞いを模倣したり、スタブしたりしたいと思っています。
私は外からアクセスできれば簡単でしょう。しかし、コントローラの外部からダッシュボードクラスを見ることはできません。
ここおかげで、minitest /モカ構文はDashboard.any_instance.stubs、道である(:CURRENT_USER).returns(ユーザー) – Gaston