Skip to content

Commit

Permalink
Render the file named in the outer-most example group description.
Browse files Browse the repository at this point in the history
Closes #11.
  • Loading branch information
dchelimsky committed Apr 26, 2010
1 parent 8a4fa5b commit 24ca705
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
53 changes: 53 additions & 0 deletions features/view_specs/view_spec.feature
@@ -0,0 +1,53 @@
Feature: view spec

View specs live in spec/views and render view templates in isolation.

Scenario: passing spec
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
"""
require "spec_helper"
describe "widgets/index.html.erb" do
it "displays all the widgets" do
assign(:widgets, [
stub_model(Widget, :name => "slicer"),
stub_model(Widget, :name => "dicer")
])
render
response.should contain("slicer")
response.should contain("dicer")
end
end
"""
When I run "rspec spec/views"
Then I should see "1 example, 0 failures"

Scenario: passing spec with before and nesting
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
"""
require "spec_helper"
describe "widgets/index.html.erb" do
context "with 2 widgets" do
before(:each) do
assign(:widgets, [
stub_model(Widget, :name => "slicer"),
stub_model(Widget, :name => "dicer")
])
end
it "displays both widgets" do
render
response.should contain("slicer")
response.should contain("dicer")
end
end
end
"""
When I run "rspec spec/views"
Then I should see "1 example, 0 failures"

5 changes: 4 additions & 1 deletion lib/rspec/rails/example/view_example_group.rb
Expand Up @@ -41,7 +41,10 @@ def response
end

def file_to_render
running_example.example_group.description
# TODO - this seems a bit invasive - need a better API from Rspec::Core
# to expose the top level description that is not a class (which is what
# comes from describes()).
running_example.example_group.before_ancestors.first.description
end

def controller_path
Expand Down

0 comments on commit 24ca705

Please sign in to comment.