Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix bug where 'render_views(false)' in a nested group set value in its

parent group.
  • Loading branch information...
commit 26bd612621b063b04fb70d4a7c9f6e607b97236e 1 parent 78a3307
@dchelimsky dchelimsky authored
View
8 History.md
@@ -1,5 +1,13 @@
## rspec-rails-2 release history
+### 2.4.2 / in dev
+
+[full changelog](http://github.com/rspec/rspec-rails/compare/v2.4.1...master)
+
+* Bug fixes
+ * fixed bug in which `render_views` in a nested group set the value in its
+ parent group.
+
### 2.4.1 / 2011-01-03
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.4.0...v2.4.1)
View
102 features/controller_specs/render_views.feature
@@ -1,9 +1,9 @@
Feature: render_views
You can tell a controller example group to render views with the
- `render_views` declaration.
+ `render_views` declaration in any individual group, or globally.
- Scenario: expect template that exists and is rendered by controller (passes)
+ Scenario: render_views directly in a single group
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""
require "spec_helper"
@@ -11,48 +11,18 @@ Feature: render_views
describe WidgetsController do
render_views
- describe "index" do
- it "renders the index template" do
+ describe "GET index" do
+ it "says 'Listing widgets'" do
get :index
- response.should contain("Listing widgets")
- end
-
- it "renders the widgets/index template" do
- get :index
- response.should contain("Listing widgets")
+ response.body.should =~ /Listing widgets/m
end
end
end
"""
When I run "rspec spec"
- Then the output should contain "2 examples, 0 failures"
+ Then the examples should all pass
- Scenario: expect template that does not exist and is rendered by controller (fails)
- Given a file named "spec/controllers/widgets_controller_spec.rb" with:
- """
- require "spec_helper"
-
- describe WidgetsController do
- render_views
-
- before do
- def controller.index
- render :template => "other"
- end
- end
-
- describe "index" do
- it "renders the other template" do
- get :index
- end
- end
- end
- """
- When I run "rspec spec"
- Then the output should contain "1 example, 1 failure"
- And the output should contain "Missing template"
-
- Scenario: render_views on and off in diff contexts
+ Scenario: render_views on and off in nested groups
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
"""
require "spec_helper"
@@ -61,19 +31,30 @@ Feature: render_views
context "with render_views" do
render_views
- describe "index" do
+ describe "GET index" do
it "renders the actual template" do
get :index
response.body.should =~ /Listing widgets/m
end
end
+
+ context "with render_views(false) nested in a group with render_views" do
+ render_views false
+
+ describe "GET index" do
+ it "renders the RSpec generated template" do
+ get :index
+ response.body.should eq("")
+ end
+ end
+ end
end
context "without render_views" do
- describe "index" do
+ describe "GET index" do
it "renders the RSpec generated template" do
get :index
- response.body.should == ""
+ response.body.should eq("")
end
end
end
@@ -81,26 +62,32 @@ Feature: render_views
context "with render_views again" do
render_views
- describe "index" do
+ describe "GET index" do
it "renders the actual template" do
get :index
response.body.should =~ /Listing widgets/m
end
end
end
-
- context "without render_views again" do
- describe "index" do
- it "renders the RSpec generated template" do
- get :index
- response.body.should == ""
- end
- end
- end
end
"""
- When I run "rspec spec"
- Then the output should contain "4 examples, 0 failures"
+ When I run "rspec spec --format documentation"
+ Then the output should contain:
+ """
+ WidgetsController
+ with render_views
+ GET index
+ renders the actual template
+ with render_views(false) nested in a group with render_views
+ GET index
+ renders the RSpec generated template
+ without render_views
+ GET index
+ renders the RSpec generated template
+ with render_views again
+ GET index
+ renders the actual template
+ """
Scenario: render_views globally
Given a file named "spec/support/render_views.rb" with:
@@ -114,19 +101,14 @@ Feature: render_views
require "spec_helper"
describe WidgetsController do
- describe "index" do
+ describe "GET index" do
it "renders the index template" do
get :index
- response.should contain("Listing widgets")
- end
-
- it "renders the widgets/index template" do
- get :index
- response.should contain("Listing widgets")
+ response.body.should =~ /Listing widgets/m
end
end
end
"""
When I run "rspec spec"
- Then the output should contain "2 examples, 0 failures"
+ Then the examples should all pass
View
2  lib/rspec/rails/view_rendering.rb
@@ -23,7 +23,7 @@ module ViewRendering
module ClassMethods
def metadata_for_rspec_rails
- metadata[:rspec_rails] ||= {}
+ metadata[:rspec_rails] = metadata[:rspec_rails] ? metadata[:rspec_rails].dup : {}
end
# See RSpec::Rails::ControllerExampleGroup
View
8 spec/rspec/rails/view_rendering_spec.rb
@@ -88,7 +88,13 @@ def example.controller
end
end
- it "overrides the parent group" do
+ it "leaves the parent group as/is" do
+ group.render_views
+ nested_group.render_views false
+ group.new.render_views?.should be_true
+ end
+
+ it "overrides the value inherited from the parent group" do
group.render_views
nested_group.render_views false
nested_group.new.render_views?.should be_false
Please sign in to comment.
Something went wrong with that request. Please try again.