0
行動這是我創造的動作:MINITEST摩卡存根呈現Rails的
def create
if #something then
flash[:sucess] = "sucess!"
redirect_to app_path
else
flash[:error] = "error"
render "template"
end
這是我的控制器測試
should "fail if " do
assert_no_difference '....' do
patch :create, #hash here
end
我一直在使用摩卡掐滅了幾個方法,所以我不能渲染'模板'。我想存根渲染動作,所以沒有模板呈現。東西like this in rspec
stub_template "gadgets/_form.html.erb" => "This content"
到目前爲止,我tried @ controller.expects(:渲染),但沒有奏效。
我也試過any_instance沒有成功
ActionView.any_instance.stubs(:render).returns(false)
*** NoMethodError Exception: undefined method `any_instance' for ActionView:Module
我如何使用存根與摩卡MINITEST渲染動作?
爲什麼要存根渲染方法?視圖不會在控制器測試中呈現,除非您明確使用['render_views'](https://www.relishapp.com/rspec/rspec-rails/v/3-5/docs/controller-specs/render-views) 。 – max
這是回溯的一部分:'app/views/instances/index.html.haml:1:'_app_views_instances_index_html_haml___803308070840349184_59487160''我沒有render_views。 – Gaston
我錯過了你正在使用minitest而不是rspec。你可能想讓它更明顯,因爲措辭有點誤導 – max