Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Let local render_views override global setting #522

Merged
merged 1 commit into from

2 participants

Martin Svalin Justin Ko
Martin Svalin

If render_views is enabled globally in the spec_helper, it clobbers attempts to disable it locally for specific examples due to the false || true logic.

Instead, only use the global setting if no local render_views was provided.

My use case: I am working on an old project, where render_views has been enabled globally for a long time. I'm trying to isolate new specs as much as possible, so I wanted to disable render_views for some new controller specs. Unfortunately render_views(false) didn't work as I expected it.

Here is a gist with steps to reproduce the behaviour: https://gist.github.com/2249825

I don't think this is the intended behaviour of render_views, so I'm contributing my patch upstream.

Martin Svalin martinsvalin Let local render_views override global setting
If render_views is enabled globally in the spec_helper, it clobbers attempts to disable it locally for specific examples due to the false || true logic.

Instead, only use the global setting if no local render_views was provided.
f7640ad
Justin Ko justinko merged commit 7419039 into from
Justin Ko justinko referenced this pull request from a commit
Justin Ko justinko Changelog for #522 002f1da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 30, 2012
  1. Martin Svalin

    Let local render_views override global setting

    martinsvalin authored
    If render_views is enabled globally in the spec_helper, it clobbers attempts to disable it locally for specific examples due to the false || true logic.
    
    Instead, only use the global setting if no local render_views was provided.
This page is out of date. Refresh to see the latest.
3  lib/rspec/rails/view_rendering.rb
View
@@ -47,7 +47,8 @@ def integrate_views
# @api private
def render_views?
- metadata_for_rspec_rails[:render_views] || RSpec.configuration.render_views?
+ return RSpec.configuration.render_views? unless metadata_for_rspec_rails.key? :render_views
+ metadata_for_rspec_rails[:render_views]
end
end
6 spec/rspec/rails/view_rendering_spec.rb
View
@@ -54,6 +54,12 @@ def example.controller
group.render_views false
group.new.render_views?.should be_false
end
+
+ it "overrides the global config if render_views is enabled there" do
+ RSpec.configuration.stub(:render_views?).and_return true
+ group.render_views false
+ group.new.render_views?.should be_false
+ end
end
context "in a nested group" do
Something went wrong with that request. Please try again.