rspec-rails 1.1.12 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +7 -0
- data/History.txt +55 -0
- data/License.txt +1 -1
- data/Manifest.txt +53 -48
- data/README.txt +5 -4
- data/Rakefile +9 -2
- data/TODO.txt +1 -0
- data/Upgrade.markdown +103 -0
- data/generators/rspec/rspec_generator.rb +1 -0
- data/generators/rspec/templates/rspec.rake +134 -111
- data/generators/rspec/templates/script/autospec +1 -0
- data/generators/rspec/templates/script/spec +21 -4
- data/generators/rspec/templates/script/spec_server +34 -107
- data/generators/rspec/templates/spec_helper.rb +1 -1
- data/generators/rspec_controller/rspec_controller_generator.rb +1 -5
- data/generators/rspec_scaffold/rspec_scaffold_generator.rb +13 -17
- data/generators/rspec_scaffold/templates/controller_spec.rb +27 -29
- data/generators/rspec_scaffold/templates/edit_erb_spec.rb +2 -2
- data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
- data/generators/rspec_scaffold/templates/index_erb_spec.rb +2 -2
- data/generators/rspec_scaffold/templates/new_erb_spec.rb +2 -2
- data/generators/rspec_scaffold/templates/routing_spec.rb +24 -20
- data/generators/rspec_scaffold/templates/show_erb_spec.rb +2 -2
- data/lib/spec/rails.rb +10 -9
- data/lib/spec/rails/example.rb +2 -2
- data/lib/spec/rails/example/assigns_hash_proxy.rb +1 -2
- data/lib/spec/rails/example/controller_example_group.rb +117 -123
- data/lib/spec/rails/example/functional_example_group.rb +7 -22
- data/lib/spec/rails/example/helper_example_group.rb +15 -33
- data/lib/spec/rails/example/model_example_group.rb +1 -1
- data/lib/spec/rails/example/render_observer.rb +0 -26
- data/lib/spec/rails/example/routing_example_group.rb +13 -0
- data/lib/spec/rails/example/routing_helpers.rb +68 -0
- data/lib/spec/rails/example/view_example_group.rb +50 -47
- data/lib/spec/rails/extensions.rb +2 -1
- data/lib/spec/rails/extensions/action_controller/rescue.rb +25 -8
- data/lib/spec/rails/extensions/action_controller/test_case.rb +16 -0
- data/lib/spec/rails/extensions/action_controller/test_response.rb +4 -3
- data/lib/spec/rails/extensions/action_view/base.rb +9 -9
- data/lib/spec/rails/extensions/active_record/base.rb +39 -23
- data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
- data/lib/spec/rails/extensions/spec/matchers/have.rb +8 -6
- data/lib/spec/rails/extensions/spec/runner/configuration.rb +12 -44
- data/lib/spec/rails/matchers/ar_be_valid.rb +8 -5
- data/lib/spec/rails/matchers/assert_select.rb +36 -21
- data/lib/spec/rails/matchers/have_text.rb +3 -3
- data/lib/spec/rails/matchers/include_text.rb +4 -4
- data/lib/spec/rails/matchers/redirect_to.rb +30 -19
- data/lib/spec/rails/matchers/render_template.rb +7 -3
- data/lib/spec/rails/mocks.rb +1 -1
- data/lib/spec/rails/spec_server.rb +97 -0
- data/lib/spec/rails/story_adapter.rb +4 -4
- data/lib/spec/rails/version.rb +2 -2
- data/spec/resources/controllers/controller_spec_controller.rb +14 -6
- data/spec/resources/controllers/example.txt +1 -0
- data/spec/resources/controllers/redirect_spec_controller.rb +4 -0
- data/spec/resources/controllers/render_spec_controller.rb +1 -1
- data/spec/resources/controllers/rjs_spec_controller.rb +1 -1
- data/spec/resources/helpers/explicit_helper.rb +1 -1
- data/spec/resources/views/controller_spec/{_partial.rhtml → _partial.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_setting_flash_after_session_reset.rhtml → action_setting_flash_after_session_reset.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_setting_flash_before_session_reset.rhtml → action_setting_flash_before_session_reset.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_setting_the_assigns_hash.rhtml → action_setting_the_assigns_hash.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_with_errors_in_template.rhtml → action_with_errors_in_template.html.erb} +0 -0
- data/spec/resources/views/controller_spec/{action_with_template.rhtml → action_with_template.html.erb} +0 -0
- data/spec/resources/views/layouts/{application.rhtml → application.html.erb} +0 -0
- data/spec/resources/views/layouts/{simple.rhtml → simple.html.erb} +0 -0
- data/spec/resources/views/render_spec/{_a_partial.rhtml → _a_partial.html.erb} +0 -0
- data/spec/resources/views/render_spec/{action_with_alternate_layout.rhtml → action_with_alternate_layout.html.erb} +0 -0
- data/spec/resources/views/rjs_spec/{_replacement_partial.rhtml → _replacement_partial.html.erb} +0 -0
- data/spec/resources/views/rjs_spec/{hide_div.rjs → hide_div.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{hide_page_element.rjs → hide_page_element.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{insert_html.rjs → insert_html.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{replace.rjs → replace.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{replace_html.rjs → replace_html.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{replace_html_with_partial.rjs → replace_html_with_partial.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{visual_effect.rjs → visual_effect.js.rjs} +0 -0
- data/spec/resources/views/rjs_spec/{visual_toggle_effect.rjs → visual_toggle_effect.js.rjs} +0 -0
- data/spec/resources/views/tag_spec/{no_tags.rhtml → no_tags.html.erb} +0 -0
- data/spec/resources/views/tag_spec/{single_div_with_no_attributes.rhtml → single_div_with_no_attributes.html.erb} +0 -0
- data/spec/resources/views/tag_spec/{single_div_with_one_attribute.rhtml → single_div_with_one_attribute.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_partial.rhtml → _partial.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_partial_used_twice.rhtml → _partial_used_twice.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_partial_with_local_variable.rhtml → _partial_with_local_variable.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_partial_with_sub_partial.rhtml → _partial_with_sub_partial.html.erb} +0 -0
- data/spec/resources/views/view_spec/{_spacer.rhtml → _spacer.html.erb} +0 -0
- data/spec/resources/views/view_spec/{accessor.rhtml → accessor.html.erb} +0 -0
- data/spec/resources/views/view_spec/{block_helper.rhtml → block_helper.html.erb} +0 -0
- data/spec/resources/views/view_spec/{entry_form.rhtml → entry_form.html.erb} +0 -0
- data/spec/resources/views/view_spec/{explicit_helper.rhtml → explicit_helper.html.erb} +0 -0
- data/spec/resources/views/view_spec/foo/{show.rhtml → show.html.erb} +0 -0
- data/spec/resources/views/view_spec/{implicit_helper.rhtml → implicit_helper.html.erb} +0 -0
- data/spec/resources/views/view_spec/{multiple_helpers.rhtml → multiple_helpers.html.erb} +0 -0
- data/spec/resources/views/view_spec/{should_not_receive.rhtml → should_not_receive.html.erb} +0 -0
- data/spec/resources/views/view_spec/{template_with_partial.rhtml → template_with_partial.html.erb} +0 -0
- data/spec/resources/views/view_spec/{template_with_partial_using_collection.rhtml → template_with_partial_using_collection.html.erb} +0 -0
- data/spec/resources/views/view_spec/{template_with_partial_with_array.rhtml → template_with_partial_with_array.html.erb} +0 -0
- data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +18 -5
- data/spec/spec/rails/example/configuration_spec.rb +15 -29
- data/spec/spec/rails/example/{controller_spec_spec.rb → controller_example_group_spec.rb} +40 -96
- data/spec/spec/rails/example/cookies_proxy_spec.rb +32 -36
- data/spec/spec/rails/example/error_handling_spec.rb +90 -0
- data/spec/spec/rails/example/example_group_factory_spec.rb +5 -5
- data/spec/spec/rails/example/{helper_spec_spec.rb → helper_example_group_spec.rb} +45 -13
- data/spec/spec/rails/example/{model_spec_spec.rb → model_example_group_spec.rb} +3 -1
- data/spec/spec/rails/example/routing_example_group_spec.rb +9 -0
- data/spec/spec/rails/example/shared_routing_example_group_examples.rb +45 -0
- data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +1 -1
- data/spec/spec/rails/example/{view_spec_spec.rb → view_example_group_spec.rb} +44 -17
- data/spec/spec/rails/matchers/ar_be_valid_spec.rb +10 -0
- data/spec/spec/rails/matchers/assert_select_spec.rb +59 -60
- data/spec/spec/rails/matchers/have_text_spec.rb +12 -4
- data/spec/spec/rails/matchers/include_text_spec.rb +11 -13
- data/spec/spec/rails/matchers/redirect_to_spec.rb +224 -189
- data/spec/spec/rails/matchers/render_template_spec.rb +169 -158
- data/spec/spec/rails/spec_server_spec.rb +18 -7
- data/spec/spec_helper.rb +21 -9
- metadata +68 -53
- data/lib/spec/rails/example/rails_example_group.rb +0 -28
- data/lib/spec/rails/extensions/action_controller/base.rb +0 -14
- data/rspec-rails.gemspec +0 -36
- data/spec/resources/views/render_spec/some_action.rjs +0 -1
- data/spec/spec/rails/example/shared_behaviour_spec.rb +0 -16
- data/spec/spec/rails/extensions/action_controller_rescue_action_spec.rb +0 -57
@@ -13,8 +13,8 @@ describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
|
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
17
|
-
render
|
16
|
+
it "renders the edit <%= file_name %> form" do
|
17
|
+
render
|
18
18
|
|
19
19
|
response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
|
20
20
|
<% for attribute in output_attributes -%>
|
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
|
|
3
3
|
describe <%= controller_class_name %>Helper do
|
4
4
|
|
5
5
|
#Delete this example and add some real ones or delete this file
|
6
|
-
it "
|
6
|
+
it "is included in the helper object" do
|
7
7
|
included_modules = (class << helper; self; end).send :included_modules
|
8
8
|
included_modules.should include(<%= controller_class_name %>Helper)
|
9
9
|
end
|
@@ -18,8 +18,8 @@ describe "/<%= table_name %>/index.<%= default_file_extension %>" do
|
|
18
18
|
]
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
22
|
-
render
|
21
|
+
it "renders a list of <%= table_name %>" do
|
22
|
+
render
|
23
23
|
<% for attribute in output_attributes -%>
|
24
24
|
response.should have_tag("tr>td", <%= attribute.default_value %>.to_s, 2)
|
25
25
|
<% end -%>
|
@@ -13,8 +13,8 @@ describe "/<%= table_name %>/new.<%= default_file_extension %>" do
|
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
17
|
-
render
|
16
|
+
it "renders new <%= file_name %> form" do
|
17
|
+
render
|
18
18
|
|
19
19
|
response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
|
20
20
|
<% for attribute in output_attributes -%>
|
@@ -2,57 +2,61 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
|
|
2
2
|
|
3
3
|
describe <%= controller_class_name %>Controller do
|
4
4
|
describe "route generation" do
|
5
|
-
it "
|
5
|
+
it "maps #index" do
|
6
6
|
route_for(:controller => "<%= table_name %>", :action => "index").should == "/<%= table_name %>"
|
7
7
|
end
|
8
8
|
|
9
|
-
it "
|
9
|
+
it "maps #new" do
|
10
10
|
route_for(:controller => "<%= table_name %>", :action => "new").should == "/<%= table_name %>/new"
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
14
|
-
route_for(:controller => "<%= table_name %>", :action => "show", :id => 1).should == "/<%= table_name %>/1"
|
13
|
+
it "maps #show" do
|
14
|
+
route_for(:controller => "<%= table_name %>", :action => "show", :id => "1").should == "/<%= table_name %>/1"
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
18
|
-
route_for(:controller => "<%= table_name %>", :action => "edit", :id => 1).should == "/<%= table_name %>/1
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should map #update" do
|
22
|
-
route_for(:controller => "<%= table_name %>", :action => "update", :id => 1).should == "/<%= table_name %>/1"
|
17
|
+
it "maps #edit" do
|
18
|
+
route_for(:controller => "<%= table_name %>", :action => "edit", :id => "1").should == "/<%= table_name %>/1/edit"
|
23
19
|
end
|
20
|
+
|
21
|
+
it "maps #create" do
|
22
|
+
route_for(:controller => "<%= table_name %>", :action => "create").should == {:path => "/<%= table_name %>", :method => :post}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "maps #update" do
|
26
|
+
route_for(:controller => "<%= table_name %>", :action => "update", :id => "1").should == {:path =>"/<%= table_name %>/1", :method => :put}
|
27
|
+
end
|
24
28
|
|
25
|
-
it "
|
26
|
-
route_for(:controller => "<%= table_name %>", :action => "destroy", :id => 1).should == "/<%= table_name %>/1"
|
29
|
+
it "maps #destroy" do
|
30
|
+
route_for(:controller => "<%= table_name %>", :action => "destroy", :id => "1").should == {:path =>"/<%= table_name %>/1", :method => :delete}
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
34
|
describe "route recognition" do
|
31
|
-
it "
|
35
|
+
it "generates params for #index" do
|
32
36
|
params_from(:get, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "index"}
|
33
37
|
end
|
34
38
|
|
35
|
-
it "
|
39
|
+
it "generates params for #new" do
|
36
40
|
params_from(:get, "/<%= table_name %>/new").should == {:controller => "<%= table_name %>", :action => "new"}
|
37
41
|
end
|
38
42
|
|
39
|
-
it "
|
43
|
+
it "generates params for #create" do
|
40
44
|
params_from(:post, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "create"}
|
41
45
|
end
|
42
46
|
|
43
|
-
it "
|
47
|
+
it "generates params for #show" do
|
44
48
|
params_from(:get, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "show", :id => "1"}
|
45
49
|
end
|
46
50
|
|
47
|
-
it "
|
48
|
-
params_from(:get, "/<%= table_name %>/1
|
51
|
+
it "generates params for #edit" do
|
52
|
+
params_from(:get, "/<%= table_name %>/1/edit").should == {:controller => "<%= table_name %>", :action => "edit", :id => "1"}
|
49
53
|
end
|
50
54
|
|
51
|
-
it "
|
55
|
+
it "generates params for #update" do
|
52
56
|
params_from(:put, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "update", :id => "1"}
|
53
57
|
end
|
54
58
|
|
55
|
-
it "
|
59
|
+
it "generates params for #destroy" do
|
56
60
|
params_from(:delete, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "destroy", :id => "1"}
|
57
61
|
end
|
58
62
|
end
|
@@ -13,8 +13,8 @@ describe "/<%= table_name %>/show.<%= default_file_extension %>" do
|
|
13
13
|
<% end -%>
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
17
|
-
render
|
16
|
+
it "renders attributes in <p>" do
|
17
|
+
render
|
18
18
|
<% for attribute in output_attributes -%>
|
19
19
|
response.should have_text(/<%= Regexp.escape(attribute.default_value).gsub(/^"|"$/, '')%>/)
|
20
20
|
<% end -%>
|
data/lib/spec/rails.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
|
1
|
+
RAILS_ENV ||= "test"
|
2
2
|
|
3
3
|
begin
|
4
4
|
require_dependency 'application_controller'
|
5
5
|
rescue MissingSourceFile
|
6
6
|
require_dependency 'application'
|
7
7
|
end
|
8
|
+
require 'rack/utils'
|
8
9
|
|
9
10
|
require 'action_controller/test_process'
|
10
11
|
require 'action_controller/integration'
|
12
|
+
require 'active_support/test_case'
|
11
13
|
require 'active_record/fixtures' if defined?(ActiveRecord::Base)
|
12
|
-
require 'test/unit'
|
13
14
|
|
14
|
-
require 'spec'
|
15
|
+
require 'spec/test/unit'
|
15
16
|
|
16
17
|
require 'spec/rails/matchers'
|
17
18
|
require 'spec/rails/mocks'
|
@@ -19,9 +20,9 @@ require 'spec/rails/example'
|
|
19
20
|
require 'spec/rails/extensions'
|
20
21
|
require 'spec/rails/interop/testcase'
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
Spec::Example::ExampleGroupFactory.default(ActiveSupport::TestCase)
|
24
|
+
|
25
|
+
if ActionView::Base.respond_to?(:cache_template_extension)
|
26
|
+
ActionView::Base.cache_template_extensions = false
|
27
|
+
end
|
28
|
+
|
data/lib/spec/rails/example.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
dir = File.dirname(__FILE__)
|
2
2
|
|
3
|
+
require 'spec/rails/example/routing_helpers'
|
3
4
|
require 'spec/rails/example/assigns_hash_proxy'
|
4
|
-
|
5
5
|
require "spec/rails/example/render_observer"
|
6
|
-
require "spec/rails/example/rails_example_group"
|
7
6
|
require "spec/rails/example/model_example_group"
|
8
7
|
require "spec/rails/example/functional_example_group"
|
9
8
|
require "spec/rails/example/controller_example_group"
|
10
9
|
require "spec/rails/example/helper_example_group"
|
11
10
|
require "spec/rails/example/view_example_group"
|
11
|
+
require "spec/rails/example/routing_example_group"
|
12
12
|
require "spec/rails/example/cookies_proxy"
|
13
13
|
|
14
14
|
module Spec
|
@@ -8,8 +8,7 @@ module Spec
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def [](key)
|
11
|
-
return false if assigns[key] ==
|
12
|
-
return false if assigns[key.to_s] == false
|
11
|
+
return false if false == assigns[key] || false == assigns[key.to_s]
|
13
12
|
assigns[key] || assigns[key.to_s] || @target.instance_variable_get("@#{key}")
|
14
13
|
end
|
15
14
|
|
@@ -3,21 +3,22 @@ module Spec
|
|
3
3
|
module Example
|
4
4
|
# Controller Examples live in $RAILS_ROOT/spec/controllers/.
|
5
5
|
#
|
6
|
-
# Controller Examples use Spec::Rails::Example::ControllerExampleGroup,
|
7
|
-
# Controllers in two modes, which
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# isolation and far enough away from
|
12
|
-
# with minimal changes to the existing
|
6
|
+
# Controller Examples use Spec::Rails::Example::ControllerExampleGroup,
|
7
|
+
# which supports running specs for Controllers in two modes, which
|
8
|
+
# represent the tension between the more granular testing common in TDD
|
9
|
+
# and the more high level testing built into rails. BDD sits somewhere
|
10
|
+
# in between: we want to a balance between specs that are close enough
|
11
|
+
# to the code to enable quick fault isolation and far enough away from
|
12
|
+
# the code to enable refactoring with minimal changes to the existing
|
13
|
+
# specs.
|
13
14
|
#
|
14
15
|
# == Isolation mode (default)
|
15
16
|
#
|
16
|
-
# No dependencies on views because none are ever rendered. The
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
17
|
+
# No dependencies on views because none are ever rendered. The benefit
|
18
|
+
# of this mode is that can spec the controller completely independent of
|
19
|
+
# the view, allowing that responsibility to be handled later, or by
|
20
|
+
# somebody else. Combined w/ separate view specs, this also provides
|
21
|
+
# better fault isolation.
|
21
22
|
#
|
22
23
|
# == Integration mode
|
23
24
|
#
|
@@ -28,13 +29,12 @@ module Spec
|
|
28
29
|
# integrate_views
|
29
30
|
# ...
|
30
31
|
#
|
31
|
-
# In this mode, controller specs are run in the same way that
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# in its benefits.
|
32
|
+
# In this mode, controller specs are run in the same way that rails
|
33
|
+
# functional tests run - one set of tests for both the controllers and
|
34
|
+
# the views. The benefit of this approach is that you get wider coverage
|
35
|
+
# from each spec. Experienced rails developers may find this an easier
|
36
|
+
# approach to begin with, however we encourage you to explore using the
|
37
|
+
# isolation mode and revel in its benefits.
|
38
38
|
#
|
39
39
|
# == Expecting Errors
|
40
40
|
#
|
@@ -44,14 +44,15 @@ module Spec
|
|
44
44
|
class ControllerExampleGroup < FunctionalExampleGroup
|
45
45
|
class << self
|
46
46
|
|
47
|
-
# Use
|
47
|
+
# Use integrate_views to instruct RSpec to render views in
|
48
|
+
# your controller examples in Integration mode.
|
48
49
|
#
|
49
50
|
# describe ThingController do
|
50
51
|
# integrate_views
|
51
52
|
# ...
|
52
53
|
#
|
53
|
-
# See Spec::Rails::Example::ControllerExampleGroup for more
|
54
|
-
# Integration and Isolation modes.
|
54
|
+
# See Spec::Rails::Example::ControllerExampleGroup for more
|
55
|
+
# information about Integration and Isolation modes.
|
55
56
|
def integrate_views(integrate_views = true)
|
56
57
|
@integrate_views = integrate_views
|
57
58
|
end
|
@@ -61,23 +62,33 @@ module Spec
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def inherited(klass) # :nodoc:
|
64
|
-
klass.controller_class_name = controller_class_name
|
65
65
|
klass.integrate_views(integrate_views?)
|
66
|
+
klass.subject { controller }
|
66
67
|
super
|
67
68
|
end
|
69
|
+
|
70
|
+
def set_description(*args) # :nodoc:
|
71
|
+
super
|
72
|
+
if described_class && described_class.ancestors.include?(ActionController::Base)
|
73
|
+
tests described_class
|
74
|
+
end
|
75
|
+
end
|
68
76
|
|
69
|
-
#
|
77
|
+
# When you don't pass a controller to describe, like this:
|
78
|
+
#
|
79
|
+
# describe ThingsController do
|
80
|
+
#
|
81
|
+
# ... then you must provide a controller_name within the context of
|
70
82
|
# your controller specs:
|
71
83
|
#
|
72
84
|
# describe "ThingController" do
|
73
85
|
# controller_name :thing
|
74
86
|
# ...
|
75
87
|
def controller_name(name)
|
76
|
-
|
88
|
+
tests "#{name}_controller".camelize.constantize
|
77
89
|
end
|
78
|
-
attr_accessor :controller_class_name # :nodoc:
|
79
90
|
end
|
80
|
-
|
91
|
+
|
81
92
|
before(:each) do
|
82
93
|
# Some Rails apps explicitly disable ActionMailer in environment.rb
|
83
94
|
if defined?(ActionMailer)
|
@@ -86,19 +97,20 @@ module Spec
|
|
86
97
|
end
|
87
98
|
|
88
99
|
unless @controller.class.ancestors.include?(ActionController::Base)
|
89
|
-
Spec::Expectations.fail_with <<-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
100
|
+
Spec::Expectations.fail_with <<-MESSAGE
|
101
|
+
Controller specs need to know what controller is being specified. You can
|
102
|
+
indicate this by passing the controller to describe():
|
103
|
+
|
104
|
+
describe MyController do
|
105
|
+
|
106
|
+
or by declaring the controller's name
|
107
|
+
|
108
|
+
describe "a MyController" do
|
109
|
+
controller_name :my #invokes the MyController
|
110
|
+
end
|
111
|
+
MESSAGE
|
101
112
|
end
|
113
|
+
@controller.extend ControllerInstanceMethods
|
102
114
|
@controller.integrate_views! if @integrate_views
|
103
115
|
@controller.session = session
|
104
116
|
end
|
@@ -107,92 +119,81 @@ module Spec
|
|
107
119
|
|
108
120
|
def initialize(defined_description, options={}, &implementation) #:nodoc:
|
109
121
|
super
|
110
|
-
controller_class_name = self.class.controller_class_name
|
111
|
-
if controller_class_name
|
112
|
-
@controller_class_name = controller_class_name.to_s
|
113
|
-
else
|
114
|
-
@controller_class_name = self.class.described_type.to_s
|
115
|
-
end
|
116
122
|
@integrate_views = self.class.integrate_views?
|
117
123
|
end
|
118
|
-
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
ensure_that_routes_are_loaded
|
136
|
-
ActionController::Routing::Routes.recognize_path(path, :method => method)
|
124
|
+
|
125
|
+
# Bypasses any error rescues defined with rescue_from. Useful
|
126
|
+
# in cases in which you want to specify errors coming out of
|
127
|
+
# actions that might be caught by a rescue_from clause that is
|
128
|
+
# specified separately.
|
129
|
+
#
|
130
|
+
# Note that this will override the effect of rescue_action_in_public
|
131
|
+
def bypass_rescue
|
132
|
+
if ::Rails::VERSION::STRING >= '2.2'
|
133
|
+
def controller.rescue_action(exception)
|
134
|
+
raise exception
|
135
|
+
end
|
136
|
+
else
|
137
|
+
def controller.rescue_action_with_handler(exception)
|
138
|
+
raise exception
|
139
|
+
end
|
140
|
+
end
|
137
141
|
end
|
142
|
+
|
143
|
+
protected
|
138
144
|
|
139
|
-
protected
|
140
145
|
def _assigns_hash_proxy
|
141
|
-
@_assigns_hash_proxy ||= AssignsHashProxy.new
|
142
|
-
@response.template
|
143
|
-
end
|
146
|
+
@_assigns_hash_proxy ||= AssignsHashProxy.new(self) {@response.template}
|
144
147
|
end
|
145
148
|
|
149
|
+
private
|
150
|
+
|
151
|
+
module TemplateIsolationExtensions
|
152
|
+
def file_exists?(ignore); true; end
|
153
|
+
|
154
|
+
def render_file(*args)
|
155
|
+
@first_render ||= args[0] unless args[0] =~ /^layouts/
|
156
|
+
end
|
157
|
+
|
158
|
+
# Rails 2.2
|
159
|
+
def _pick_template(*args)
|
160
|
+
@_first_render ||= args[0] unless args[0] =~ /^layouts/
|
161
|
+
PickedTemplate.new
|
162
|
+
end
|
163
|
+
|
164
|
+
def render(*args)
|
165
|
+
return super if Hash === args.last && args.last[:inline]
|
166
|
+
@_rendered ? record_render(args[0]) : super
|
167
|
+
end
|
168
|
+
|
146
169
|
private
|
147
|
-
|
148
|
-
|
170
|
+
|
171
|
+
def record_render(opts)
|
172
|
+
(@_rendered[:template] ||= opts[:file]) if opts[:file]
|
173
|
+
(@_rendered[:partials][opts[:partial]] += 1) if opts[:partial]
|
174
|
+
end
|
175
|
+
|
176
|
+
# Returned by _pick_template when running controller examples in isolation mode.
|
177
|
+
class PickedTemplate
|
178
|
+
# Do nothing when running controller examples in isolation mode.
|
179
|
+
def render_template(*ignore_args); end
|
180
|
+
# Do nothing when running controller examples in isolation mode.
|
181
|
+
def render_partial(*ignore_args); end
|
182
|
+
end
|
149
183
|
end
|
150
|
-
|
151
|
-
module ControllerInstanceMethods
|
184
|
+
|
185
|
+
module ControllerInstanceMethods # :nodoc:
|
152
186
|
include Spec::Rails::Example::RenderObserver
|
153
187
|
|
154
|
-
# === render(options = nil,
|
188
|
+
# === render(options = nil, extra_options={}, &block)
|
155
189
|
#
|
156
190
|
# This gets added to the controller's singleton meta class,
|
157
191
|
# allowing Controller Examples to run in two modes, freely switching
|
158
|
-
# from
|
159
|
-
def render(options=nil,
|
160
|
-
if ::Rails::VERSION::STRING >= '2.0.0' && deprecated_status_or_extra_options.nil?
|
161
|
-
deprecated_status_or_extra_options = {}
|
162
|
-
end
|
163
|
-
|
192
|
+
# from example group to example group.
|
193
|
+
def render(options=nil, extra_options={}, &block)
|
164
194
|
unless block_given?
|
165
195
|
unless integrate_views?
|
166
|
-
|
167
|
-
(class << @template.finder; self; end).class_eval do
|
168
|
-
define_method :file_exists? do; true; end
|
169
|
-
end
|
170
|
-
else
|
171
|
-
(class << @template; self; end).class_eval do
|
172
|
-
define_method :file_exists? do; true; end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
(class << @template; self; end).class_eval do
|
176
|
-
define_method :render_file do |*args|
|
177
|
-
@first_render ||= args[0] unless args[0] =~ /^layouts/
|
178
|
-
@_first_render ||= args[0] unless args[0] =~ /^layouts/
|
179
|
-
end
|
180
|
-
|
181
|
-
define_method :_pick_template do |*args|
|
182
|
-
@_first_render ||= args[0] unless args[0] =~ /^layouts/
|
183
|
-
PickedTemplate.new
|
184
|
-
end
|
185
|
-
|
186
|
-
define_method :render do |*args|
|
187
|
-
if @_rendered
|
188
|
-
opts = args[0]
|
189
|
-
(@_rendered[:template] ||= opts[:file]) if opts[:file]
|
190
|
-
(@_rendered[:partials][opts[:partial]] += 1) if opts[:partial]
|
191
|
-
else
|
192
|
-
super
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
+
@template.extend TemplateIsolationExtensions
|
196
197
|
end
|
197
198
|
end
|
198
199
|
|
@@ -203,7 +204,7 @@ module Spec
|
|
203
204
|
if matching_stub_exists(options)
|
204
205
|
@performed_render = true
|
205
206
|
else
|
206
|
-
super
|
207
|
+
super
|
207
208
|
end
|
208
209
|
end
|
209
210
|
end
|
@@ -211,38 +212,31 @@ module Spec
|
|
211
212
|
def response(&block)
|
212
213
|
# NOTE - we're setting @update for the assert_select_spec - kinda weird, huh?
|
213
214
|
@update = block
|
214
|
-
|
215
|
+
super
|
215
216
|
end
|
216
217
|
|
217
218
|
def integrate_views!
|
218
219
|
@integrate_views = true
|
219
220
|
end
|
220
221
|
|
221
|
-
|
222
|
-
|
222
|
+
private
|
223
|
+
|
223
224
|
def integrate_views?
|
224
225
|
@integrate_views
|
225
226
|
end
|
226
227
|
|
227
228
|
def matching_message_expectation_exists(options)
|
228
|
-
render_proxy.
|
229
|
+
render_proxy.__send__(:__mock_proxy).__send__(:find_matching_expectation, :render, options)
|
229
230
|
end
|
230
231
|
|
231
232
|
def matching_stub_exists(options)
|
232
|
-
render_proxy.
|
233
|
+
render_proxy.__send__(:__mock_proxy).__send__(:find_matching_method_stub, :render, options)
|
233
234
|
end
|
234
235
|
|
235
236
|
end
|
236
237
|
|
237
238
|
Spec::Example::ExampleGroupFactory.register(:controller, self)
|
238
|
-
|
239
|
-
|
240
|
-
# Returned by _pick_template when running controller examples in isolation mode.
|
241
|
-
class PickedTemplate
|
242
|
-
# Do nothing when running controller examples in isolation mode.
|
243
|
-
def render_template(*ignore_args); end
|
244
|
-
# Do nothing when running controller examples in isolation mode.
|
245
|
-
def render_partial(*ignore_args); end
|
239
|
+
|
246
240
|
end
|
247
241
|
end
|
248
242
|
end
|