Skip to content

Commit

Permalink
Infer controller.request.path_params["controller"] from the file being
Browse files Browse the repository at this point in the history
rendered in a view spec.

- Closes #172.
  • Loading branch information
dchelimsky committed Aug 23, 2010
1 parent 290357c commit 732a922
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.markdown
Expand Up @@ -148,6 +148,16 @@ View specs live in spec/views, and mix in ActionView::TestCase::Behavior.
end
end

View specs infer the controller name and path from the path to the view
template. e.g. if the template is "events/index.html.erb" then:

controller.controller_path == "events"
controller.request.path_parameters[:controller] == "events"

This means that most of the time you don't need to set these values. When
spec'ing a partial that is included across different controllers, you _may_
need to override these values before rendering the view.

## `assign(key, val)`

Use this to assign values to instance variables in the view:
Expand Down
21 changes: 21 additions & 0 deletions features/view_specs/inferred_controller_path.feature
@@ -0,0 +1,21 @@
Feature: view spec infers controller path

Scenario:
Given a file named "app/views/widgets/other.html.erb" with:
"""
<%= link_to "new", :action => "new" %>
"""
And a file named "spec/views/widgets/other.html.erb_spec.rb" with:
"""
require "spec_helper"
describe "widgets/other.html.erb" do
it "includes a link to new" do
render
rendered.should have_selector("a", :href => "/widgets/new")
end
end
"""
When I run "rspec spec/views"
Then the output should contain "1 example, 0 failures"

1 change: 1 addition & 0 deletions lib/rspec/rails/example/view_example_group.rb
Expand Up @@ -130,6 +130,7 @@ def _include_controller_helpers
before do
_include_controller_helpers
controller.controller_path = _controller_path
controller.request.path_parameters["controller"] = _controller_path
end
end

Expand Down

0 comments on commit 732a922

Please sign in to comment.