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?
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
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With