Permalink
Browse files

Renders partials with locals inside view specs

May render :partial, :template, :text, :update

Closes rspec#45.
  • Loading branch information...
mattyoho authored and dchelimsky committed May 21, 2010
1 parent d7f39ff commit 0ea6030a94af3744f6671d5c1fd4e2cbae6fd087
Showing with 105 additions and 3 deletions.
  1. +102 −1 features/view_specs/view_spec.feature
  2. +3 −2 lib/rspec/rails/example/view_example_group.rb
@@ -2,7 +2,7 @@ Feature: view spec
View specs live in spec/views and render view templates in isolation.
Scenario: passing spec
Scenario: passing spec that renders the described view file
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
"""
require "spec_helper"
@@ -51,3 +51,104 @@ Feature: view spec
When I run "rspec spec/views"
Then I should see "1 example, 0 failures"
Scenario: passing spec with explicit template rendering
Given a file named "spec/views/widgets/widget.html.erb_spec.rb" with:
"""
require "spec_helper"
describe "rendering the widget template" do
it "displays the widget" do
assign(:widget, stub_model(Widget, :name => "slicer"))
render :template => "widgets/widget.html.erb"
response.should contain("slicer")
end
end
"""
And a file named "app/views/widgets/widget.html.erb" with:
"""
<h2><%= @widget.name %></h2>
"""
When I run "rspec spec/views"
Then I should see "1 example, 0 failures"
Scenario: passing spec with rendering of locals in a partial
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
"""
require "spec_helper"
describe "rendering locals in a partial" do
it "displays the widget" do
widget = stub_model(Widget, :name => "slicer")
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
response.should contain("slicer")
end
end
"""
And a file named "app/views/widgets/_widget.html.erb" with:
"""
<h3><%= widget.name %></h3>
"""
When I run "rspec spec/views"
Then I should see "1 example, 0 failures"
Scenario: passing spec with rendering of locals in an implicit partial
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
"""
require "spec_helper"
describe "rendering locals in a partial" do
it "displays the widget" do
widget = stub_model(Widget, :name => "slicer")
render "widgets/widget", :widget => widget
response.should contain("slicer")
end
end
"""
And a file named "app/views/widgets/_widget.html.erb" with:
"""
<h3><%= widget.name %></h3>
"""
When I run "rspec spec/views"
Then I should see "1 example, 0 failures"
Scenario: passing spec with rendering of text
Given a file named "spec/views/widgets/direct.html.erb_spec.rb" with:
"""
require "spec_helper"
describe "rendering text directly" do
it "displays the given text" do
render :text => "This is directly rendered"
response.should contain("directly rendered")
end
end
"""
When I run "rspec spec/views"
Then I should see "1 example, 0 failures"
Scenario: passing spec with rendering of Prototype helper update
Given a file named "spec/views/widgets/prototype_update.html.erb_spec.rb" with:
"""
require "spec_helper"
describe "render a Prototype helper update" do
it "hides the status indicator" do
render :update do |page|
page.hide 'status-indicator'
end
response.should contain("Element.hide(\"status-indicator\")")
end
end
"""
When I run "rspec spec/views"
Then I should see "1 example, 0 failures"
@@ -50,8 +50,9 @@ def controller_path
parts.join('/')
end
def render
@response = view.render :file => file_to_render
def render(options = nil, locals = {}, &block)
options ||= {:file => file_to_render}
@response = view.render(options, locals, &block)
end
def method_missing(selector, *args)

0 comments on commit 0ea6030

Please sign in to comment.