Question

I'm always writing render_views in all my controller specs:

require 'spec_helper'

describe AwesomeController do
  render_views
end

Is there any way to always render views on all controller specs?

Was it helpful?

Solution

The documented way to do so, as of today is the following

spec/support/render_views.rb

RSpec.configure do |config|
  config.render_views
end

OTHER TIPS

Add this to spec/spec_helper.rb:

config.include(Module.new {
  def self.included(base)
    base.render_views
  end
}, :type => :controller)

It creates an anonymous module, that runs render_views on the class it is included in, and it is included on any describe-block that describes a controller.

Add It To Your spec_helper.rb Config.

You can add render_views to your rspec config, like so:

In Your spec_helper.rb:

RSpec.configure do |config|

  # Renders views in controllers.
  config.render_views

  # Other config setup.

end

Turning Off render_views.

You can turn off view rendering on a per describe/context basis with render_views false, like so:

context "without view rendering even with global render_views on" do
  render_views false

  # specs without view rendering.
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top