RSpec 2: as default render_views for all controller specifications

I always write render_views in all my controller specifications:

 require 'spec_helper' describe AwesomeController do render_views end 

Is there a way to always render views in all controller specifications?

+4
source share
3 answers

The documented way to do this is by far the next

Specification / Support / render_views.rb

 RSpec.configure do |config| config.render_views end 
+12
source

Add this to spec/spec_helper.rb :

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

Creates an anonymous module that runs render_views in the class in which it is included, and is included in any description block that describes the controller.

+4
source

Add it to the spec_helper.rb configuration.

You can add render_views to your rspec configuration, for example:

In your spec_helper.rb :

 RSpec.configure do |config| # Renders views in controllers. config.render_views # Other config setup. end 

Disabling render_views .

You can disable rendering based on description / context with render_views false , for example:

 context "without view rendering even with global render_views on" do render_views false # specs without view rendering. end 
+2
source

All Articles