5

What's the proper 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!

zoli
  • 469
  • 6
  • 17
  • Why would you want to do that? – p.matsinopoulos Sep 04 '12 at 12:14
  • I can't really remember anymore. It was probably something along the lines of the view trying to access something set up in a before_filter or something that's only properly initialized in a production environment. – zoli Sep 04 '12 at 23:02

3 Answers3

1

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 }
Sanjay Ginde
  • 223
  • 2
  • 3
  • 12
1

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.

Adam
  • 21
  • 1
0

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

hsgubert
  • 2,266
  • 1
  • 22
  • 23