开发者

How to disable rendering the view in ActionController TestCase (Rails 3.0.9)

What's the prope开发者_运维技巧r way to disable ActionController::TestCase to actually render the views? Alternatively, what'd be the way to render the view without the layout in the tests?

Using rr, I've tried stub(@controller).render { "" }

but this broke the assert_template assertions.

Thanks!


I had the same problem of disabling just layout, while still rendering the main view. With rspec mocks this works for me:

@controller.stub(:layout).and_return(false)

I've never used rr, but I would imagine the syntax might be as follows:

stub(@controller).layout { false }


I wanted to do this in Rails 6. With the the mocha gem:

ActionController::Metal.any_instance.stubs(:process).returns

For other versions of Rails, the easiest way to determine the answer is to add puts caller to your action and scan the backtrace. Find something that looks easy to stub and try it.


It is by default disabled.

If you want to enable you can:

1) call this in spec_helper:

config.render_views

2) put this statement inside your controller test class:

render_views

If you want to disable it, just add a false parameter like:

render_views false

Reference: https://www.relishapp.com/rspec/rspec-rails/v/2-5/docs/controller-specs/render-views

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜