开发者

Rspec 2: How to render_views by default for all controller specs

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

req开发者_Python百科uire '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.


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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜