Permalink
Browse files

Infer controller.request.path_params["controller"] from the file being

rendered in a view spec.

- Closes #172.
  • Loading branch information...
1 parent 290357c commit 732a92220cdc1993ef0dcbf13258a3404768110b @dchelimsky dchelimsky committed Aug 22, 2010
View
@@ -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:
@@ -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"
+
@@ -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

0 comments on commit 732a922

Please sign in to comment.