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
@@ -1,21 +1,15 @@
|
|
1
|
+
require 'action_controller/test_case'
|
2
|
+
|
1
3
|
module Spec
|
2
4
|
module Rails
|
3
5
|
module Example
|
4
|
-
class FunctionalExampleGroup <
|
5
|
-
|
6
|
-
|
6
|
+
class FunctionalExampleGroup < ActionController::TestCase
|
7
|
+
def setup
|
8
|
+
# no-op to override AC::TC's setup w/ conflicts with the before(:each) below
|
9
|
+
end
|
7
10
|
|
8
11
|
attr_reader :request, :response
|
9
|
-
before(:each) do
|
10
|
-
@controller_class = @controller_class_name.split('::').inject(Object) { |k,n| k.const_get n }
|
11
|
-
raise "Can't determine controller class for #{@controller_class_name}" if @controller_class.nil?
|
12
12
|
|
13
|
-
@controller = @controller_class.new
|
14
|
-
@request = ActionController::TestRequest.new
|
15
|
-
@response = ActionController::TestResponse.new
|
16
|
-
@response.session = @request.session
|
17
|
-
end
|
18
|
-
|
19
13
|
def params
|
20
14
|
request.parameters
|
21
15
|
end
|
@@ -25,7 +19,7 @@ module Spec
|
|
25
19
|
end
|
26
20
|
|
27
21
|
def session
|
28
|
-
|
22
|
+
request.session
|
29
23
|
end
|
30
24
|
|
31
25
|
# Overrides the <tt>cookies()</tt> method in
|
@@ -35,15 +29,6 @@ module Spec
|
|
35
29
|
# cookies in examples using the same API with which you set and read
|
36
30
|
# them in controllers.
|
37
31
|
#
|
38
|
-
# == Examples (Rails >= 1.2.6)
|
39
|
-
#
|
40
|
-
# cookies[:user_id] = '1234'
|
41
|
-
# get :index
|
42
|
-
# assigns[:user].id.should == '1234'
|
43
|
-
#
|
44
|
-
# post :login
|
45
|
-
# cookies[:login].expires.should == 1.week.from_now
|
46
|
-
#
|
47
32
|
# == Examples (Rails 2.0 > 2.2)
|
48
33
|
#
|
49
34
|
# cookies[:user_id] = {:value => '1234', :expires => 1.minute.ago}
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Spec
|
2
2
|
module Rails
|
3
3
|
module Example
|
4
|
+
class HelperExampleGroupController < ApplicationController #:nodoc:
|
5
|
+
attr_accessor :request, :url
|
6
|
+
end
|
7
|
+
|
4
8
|
# Helper Specs live in $RAILS_ROOT/spec/helpers/.
|
5
9
|
#
|
6
10
|
# Helper Specs use Spec::Rails::Example::HelperExampleGroup, which allows you to
|
@@ -12,7 +16,7 @@ module Spec
|
|
12
16
|
#
|
13
17
|
# == Example
|
14
18
|
#
|
15
|
-
#
|
19
|
+
# module ThingHelper
|
16
20
|
# def number_of_things
|
17
21
|
# Thing.count
|
18
22
|
# end
|
@@ -26,32 +30,19 @@ module Spec
|
|
26
30
|
# end
|
27
31
|
# end
|
28
32
|
class HelperExampleGroup < FunctionalExampleGroup
|
33
|
+
tests HelperExampleGroupController
|
29
34
|
attr_accessor :output_buffer
|
30
35
|
|
31
36
|
class HelperObject < ActionView::Base
|
37
|
+
def initialize(*args)
|
38
|
+
@template = self
|
39
|
+
super
|
40
|
+
end
|
32
41
|
def protect_against_forgery?
|
33
42
|
false
|
34
43
|
end
|
35
44
|
|
36
|
-
|
37
|
-
@session = session
|
38
|
-
end
|
39
|
-
|
40
|
-
def request=(request)
|
41
|
-
@request = request
|
42
|
-
end
|
43
|
-
|
44
|
-
def flash=(flash)
|
45
|
-
@flash = flash
|
46
|
-
end
|
47
|
-
|
48
|
-
def params=(params)
|
49
|
-
@params = params
|
50
|
-
end
|
51
|
-
|
52
|
-
def controller=(controller)
|
53
|
-
@controller = controller
|
54
|
-
end
|
45
|
+
attr_writer :session, :request, :flash, :params, :controller
|
55
46
|
|
56
47
|
private
|
57
48
|
attr_reader :session, :request, :flash, :params, :controller
|
@@ -108,11 +99,7 @@ module Spec
|
|
108
99
|
ActionView::Base.included_modules.reverse.each do |mod|
|
109
100
|
include mod if mod.parents.include?(ActionView::Helpers)
|
110
101
|
end
|
111
|
-
|
112
|
-
before(:all) do
|
113
|
-
@controller_class_name = 'Spec::Rails::Example::HelperExampleGroupController'
|
114
|
-
end
|
115
|
-
|
102
|
+
|
116
103
|
before(:each) do
|
117
104
|
@controller.request = @request
|
118
105
|
@controller.url = ActionController::UrlRewriter.new @request, {} # url_for
|
@@ -154,18 +141,13 @@ module Spec
|
|
154
141
|
|
155
142
|
Spec::Example::ExampleGroupFactory.register(:helper, self)
|
156
143
|
|
157
|
-
|
144
|
+
protected
|
145
|
+
|
158
146
|
def _assigns_hash_proxy
|
159
|
-
@_assigns_hash_proxy ||= AssignsHashProxy.new
|
160
|
-
helper
|
161
|
-
end
|
147
|
+
@_assigns_hash_proxy ||= AssignsHashProxy.new(self) {helper}
|
162
148
|
end
|
163
149
|
|
164
150
|
end
|
165
|
-
|
166
|
-
class HelperExampleGroupController < ApplicationController #:nodoc:
|
167
|
-
attr_accessor :request, :url
|
168
|
-
end
|
169
151
|
end
|
170
152
|
end
|
171
153
|
end
|
@@ -6,7 +6,7 @@ module Spec
|
|
6
6
|
# Model examples use Spec::Rails::Example::ModelExampleGroup, which
|
7
7
|
# provides support for fixtures and some custom expectations via extensions
|
8
8
|
# to ActiveRecord::Base.
|
9
|
-
class ModelExampleGroup <
|
9
|
+
class ModelExampleGroup < ActiveSupport::TestCase
|
10
10
|
Spec::Example::ExampleGroupFactory.register(:model, self)
|
11
11
|
end
|
12
12
|
end
|
@@ -8,32 +8,6 @@ module Spec
|
|
8
8
|
# and template and view examples
|
9
9
|
module RenderObserver
|
10
10
|
|
11
|
-
# DEPRECATED
|
12
|
-
#
|
13
|
-
# Use should_receive(:render).with(opts) instead
|
14
|
-
def expect_render(opts={})
|
15
|
-
warn_deprecation("expect_render", "should_receive")
|
16
|
-
register_verify_after_each
|
17
|
-
render_proxy.should_receive(:render, :expected_from => caller(1)[0]).with(opts)
|
18
|
-
end
|
19
|
-
|
20
|
-
# DEPRECATED
|
21
|
-
#
|
22
|
-
# Use stub!(:render).with(opts) instead
|
23
|
-
def stub_render(opts={})
|
24
|
-
warn_deprecation("stub_render", "stub!")
|
25
|
-
register_verify_after_each
|
26
|
-
render_proxy.stub!(:render, :expected_from => caller(1)[0]).with(opts)
|
27
|
-
end
|
28
|
-
|
29
|
-
def warn_deprecation(deprecated_method, new_method)
|
30
|
-
Kernel.warn <<-WARNING
|
31
|
-
#{deprecated_method} is deprecated and will be removed from a future version of rspec-rails.
|
32
|
-
|
33
|
-
Please just use object.#{new_method} instead.
|
34
|
-
WARNING
|
35
|
-
end
|
36
|
-
|
37
11
|
def verify_rendered # :nodoc:
|
38
12
|
render_proxy.rspec_verify
|
39
13
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Spec
|
2
|
+
module Rails
|
3
|
+
module Example
|
4
|
+
module RoutingHelpers
|
5
|
+
|
6
|
+
module ParamsFromQueryString # :nodoc:
|
7
|
+
def params_from_querystring(querystring) # :nodoc:
|
8
|
+
params = {}
|
9
|
+
querystring.split('&').each do |piece|
|
10
|
+
key, value = piece.split('=')
|
11
|
+
params[key.to_sym] = value
|
12
|
+
end
|
13
|
+
params
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class RouteFor
|
18
|
+
include ::Spec::Rails::Example::RoutingHelpers::ParamsFromQueryString
|
19
|
+
def initialize(example, options)
|
20
|
+
@example, @options = example, options
|
21
|
+
end
|
22
|
+
|
23
|
+
def ==(expected)
|
24
|
+
if Hash === expected
|
25
|
+
path, querystring = expected[:path].split('?')
|
26
|
+
path = expected.merge(:path => path)
|
27
|
+
else
|
28
|
+
path, querystring = expected.split('?')
|
29
|
+
end
|
30
|
+
params = querystring.blank? ? {} : @example.params_from_querystring(querystring)
|
31
|
+
@example.assert_recognizes(@options, path, params)
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Uses ActionController::Routing::Routes to generate
|
37
|
+
# the correct route for a given set of options.
|
38
|
+
# == Example
|
39
|
+
# route_for(:controller => 'registrations', :action => 'edit', :id => 1)
|
40
|
+
# => '/registrations/1;edit'
|
41
|
+
def route_for(options)
|
42
|
+
RouteFor.new(self, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Uses ActionController::Routing::Routes to parse
|
46
|
+
# an incoming path so the parameters it generates can be checked
|
47
|
+
# == Example
|
48
|
+
# params_from(:get, '/registrations/1/edit')
|
49
|
+
# => :controller => 'registrations', :action => 'edit', :id => 1
|
50
|
+
def params_from(method, path)
|
51
|
+
ensure_that_routes_are_loaded
|
52
|
+
path, querystring = path.split('?')
|
53
|
+
params = ActionController::Routing::Routes.recognize_path(path, :method => method)
|
54
|
+
querystring.blank? ? params : params.merge(params_from_querystring(querystring))
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
include ParamsFromQueryString
|
60
|
+
|
61
|
+
def ensure_that_routes_are_loaded
|
62
|
+
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,6 +1,29 @@
|
|
1
1
|
module Spec
|
2
2
|
module Rails
|
3
3
|
module Example
|
4
|
+
class ViewExampleGroupController < ApplicationController #:nodoc:
|
5
|
+
include Spec::Rails::Example::RenderObserver
|
6
|
+
attr_reader :template
|
7
|
+
|
8
|
+
def add_helper_for(template_path)
|
9
|
+
add_helper(template_path.split('/')[0])
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_helper(name)
|
13
|
+
begin
|
14
|
+
helper_module = "#{name}_helper".camelize.constantize
|
15
|
+
rescue
|
16
|
+
return
|
17
|
+
end
|
18
|
+
(class << template; self; end).class_eval do
|
19
|
+
include helper_module
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def forget_variables_added_to_assigns
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
4
27
|
# View Examples live in $RAILS_ROOT/spec/views/.
|
5
28
|
#
|
6
29
|
# View Specs use Spec::Rails::Example::ViewExampleGroup,
|
@@ -24,24 +47,23 @@ module Spec
|
|
24
47
|
# end
|
25
48
|
# end
|
26
49
|
class ViewExampleGroup < FunctionalExampleGroup
|
27
|
-
|
28
|
-
|
50
|
+
tests ViewExampleGroupController
|
51
|
+
class << self
|
52
|
+
def inherited(klass) # :nodoc:
|
53
|
+
klass.subject { template }
|
54
|
+
super
|
55
|
+
end
|
29
56
|
end
|
30
57
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(defined_description, options={}, &implementation) #:nodoc:
|
36
|
-
super
|
37
|
-
@controller_class_name = "Spec::Rails::Example::ViewExampleGroupController"
|
38
|
-
end
|
58
|
+
before {ensure_that_flash_and_session_work_properly}
|
59
|
+
after {ensure_that_base_view_path_is_not_set_across_example_groups}
|
39
60
|
|
40
61
|
def ensure_that_flash_and_session_work_properly #:nodoc:
|
41
|
-
@controller.
|
42
|
-
@controller.
|
62
|
+
@controller.class.__send__ :public, :flash
|
63
|
+
@controller.__send__ :initialize_template_class, @response
|
64
|
+
@controller.__send__ :assign_shortcuts, @request, @response
|
65
|
+
@controller.__send__ :initialize_current_url
|
43
66
|
@session = @controller.session
|
44
|
-
@controller.class.send :public, :flash
|
45
67
|
end
|
46
68
|
|
47
69
|
def ensure_that_base_view_path_is_not_set_across_example_groups #:nodoc:
|
@@ -97,8 +119,15 @@ module Spec
|
|
97
119
|
# See Spec::Rails::Example::ViewExampleGroup for more information.
|
98
120
|
def render(*args)
|
99
121
|
options = Hash === args.last ? args.pop : {}
|
100
|
-
|
101
|
-
|
122
|
+
|
123
|
+
if args.empty?
|
124
|
+
unless [:partial, :inline, :file, :template, :xml, :json, :update].any? {|k| options.has_key? k}
|
125
|
+
args << self.class.description_parts.first
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
options[:template] = args.first.to_s.sub(/^\//,'') unless args.empty?
|
130
|
+
|
102
131
|
set_base_view_path(options)
|
103
132
|
add_helpers(options)
|
104
133
|
|
@@ -112,9 +141,7 @@ module Spec
|
|
112
141
|
defaults = { :layout => false }
|
113
142
|
options = defaults.merge options
|
114
143
|
|
115
|
-
@controller.
|
116
|
-
|
117
|
-
@controller.send :initialize_current_url
|
144
|
+
@controller.__send__(:params).reverse_merge! @request.parameters
|
118
145
|
|
119
146
|
@controller.class.instance_eval %{
|
120
147
|
def controller_path
|
@@ -126,9 +153,9 @@ module Spec
|
|
126
153
|
end
|
127
154
|
}
|
128
155
|
|
129
|
-
@controller.
|
130
|
-
@controller.
|
131
|
-
@controller.
|
156
|
+
@controller.__send__ :forget_variables_added_to_assigns
|
157
|
+
@controller.__send__ :render, options
|
158
|
+
@controller.__send__ :process_cleanup
|
132
159
|
end
|
133
160
|
|
134
161
|
# This provides the template. Use this to set mock
|
@@ -148,36 +175,12 @@ module Spec
|
|
148
175
|
|
149
176
|
Spec::Example::ExampleGroupFactory.register(:view, self)
|
150
177
|
|
151
|
-
|
178
|
+
protected
|
152
179
|
def _assigns_hash_proxy
|
153
|
-
@_assigns_hash_proxy ||= AssignsHashProxy.new
|
154
|
-
@response.template
|
155
|
-
end
|
180
|
+
@_assigns_hash_proxy ||= AssignsHashProxy.new(self) {@response.template}
|
156
181
|
end
|
157
182
|
end
|
158
183
|
|
159
|
-
class ViewExampleGroupController < ApplicationController #:nodoc:
|
160
|
-
include Spec::Rails::Example::RenderObserver
|
161
|
-
attr_reader :template
|
162
|
-
|
163
|
-
def add_helper_for(template_path)
|
164
|
-
add_helper(template_path.split('/')[0])
|
165
|
-
end
|
166
|
-
|
167
|
-
def add_helper(name)
|
168
|
-
begin
|
169
|
-
helper_module = "#{name}_helper".camelize.constantize
|
170
|
-
rescue
|
171
|
-
return
|
172
|
-
end
|
173
|
-
(class << template; self; end).class_eval do
|
174
|
-
include helper_module
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def forget_variables_added_to_assigns
|
179
|
-
end
|
180
|
-
end
|
181
184
|
end
|
182
185
|
end
|
183
186
|
end
|
@@ -3,8 +3,9 @@ require 'spec'
|
|
3
3
|
require 'spec/rails/extensions/spec/runner/configuration'
|
4
4
|
require 'spec/rails/extensions/spec/matchers/have'
|
5
5
|
|
6
|
+
require 'spec/rails/extensions/active_support/test_case'
|
6
7
|
require 'spec/rails/extensions/active_record/base'
|
7
|
-
require 'spec/rails/extensions/action_controller/base'
|
8
8
|
require 'spec/rails/extensions/action_controller/rescue'
|
9
|
+
require 'spec/rails/extensions/action_controller/test_case'
|
9
10
|
require 'spec/rails/extensions/action_controller/test_response'
|
10
11
|
require 'spec/rails/extensions/action_view/base'
|
@@ -1,25 +1,42 @@
|
|
1
1
|
module ActionController
|
2
2
|
module Rescue
|
3
3
|
def use_rails_error_handling!
|
4
|
-
|
5
|
-
|
4
|
+
Kernel.warn <<-WARNING
|
5
|
+
DEPRECATION NOTICE: controller.use_rails_error_handling! is
|
6
|
+
deprecated and will be removed from a future version of
|
7
|
+
rspec-rails.
|
6
8
|
|
9
|
+
Use rescue_action_in_public!, which is defined directly in
|
10
|
+
rails' testing framework, instead.
|
11
|
+
WARNING
|
12
|
+
if Rails::VERSION::STRING =~ /^2\.0/
|
13
|
+
@use_rails_error_handling = true
|
14
|
+
else
|
15
|
+
# anything but 0.0.0.0 - borrowed from rails own rescue_action_in_public!
|
16
|
+
request.remote_addr = '208.77.188.166'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
def use_rails_error_handling?
|
8
21
|
@use_rails_error_handling ||= false
|
9
22
|
end
|
10
23
|
|
11
24
|
protected
|
12
25
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
26
|
+
if Rails::VERSION::STRING =~ /^2\.0/
|
27
|
+
def rescue_action_in_public?
|
28
|
+
request.respond_to?(:rescue_action_in_public?) and request.rescue_action_in_public?
|
29
|
+
end
|
30
|
+
|
31
|
+
def rescue_action_with_handler_with_fast_errors(exception)
|
32
|
+
if (use_rails_error_handling? || rescue_action_in_public?) & !handler_for_rescue(exception)
|
33
|
+
rescue_action_in_public(exception)
|
17
34
|
else
|
18
|
-
|
35
|
+
rescue_action_with_handler_without_fast_errors(exception)
|
19
36
|
end
|
20
37
|
end
|
38
|
+
alias_method_chain :rescue_action_with_handler, :fast_errors
|
21
39
|
end
|
22
|
-
alias_method_chain :rescue_action, :fast_errors
|
23
40
|
|
24
41
|
end
|
25
42
|
end
|