rspec-rails 2.14.2 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +4 -2
- data/Capybara.md +2 -4
- data/Changelog.md +592 -34
- data/{License.txt → LICENSE.md} +5 -2
- data/README.md +290 -369
- data/lib/generators/rspec/controller/controller_generator.rb +1 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +5 -5
- data/lib/generators/rspec/controller/templates/view_spec.rb +2 -2
- data/lib/generators/rspec/feature/feature_generator.rb +29 -0
- data/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
- data/lib/generators/rspec/generators/generator_generator.rb +24 -0
- data/lib/generators/rspec/generators/templates/generator_spec.rb +6 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -0
- data/lib/generators/rspec/helper/templates/helper_spec.rb +2 -2
- data/lib/generators/rspec/install/install_generator.rb +44 -5
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +78 -0
- data/lib/generators/rspec/integration/integration_generator.rb +8 -13
- data/lib/generators/rspec/integration/templates/request_spec.rb +4 -9
- data/lib/generators/rspec/job/job_generator.rb +12 -0
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +7 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +7 -7
- data/lib/generators/rspec/mailer/templates/preview.rb +13 -0
- data/lib/generators/rspec/model/model_generator.rb +19 -5
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/model/templates/model_spec.rb +2 -2
- data/lib/generators/rspec/observer/observer_generator.rb +1 -0
- data/lib/generators/rspec/observer/templates/observer_spec.rb +2 -2
- data/lib/generators/rspec/request/request_generator.rb +10 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +68 -138
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +165 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +98 -73
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +9 -13
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -10
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +10 -14
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +21 -12
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +4 -11
- data/lib/generators/rspec/system/system_generator.rb +26 -0
- data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
- data/lib/generators/rspec/view/templates/view_spec.rb +2 -2
- data/lib/generators/rspec/view/view_generator.rb +1 -0
- data/lib/generators/rspec.rb +20 -6
- data/lib/rspec/rails/active_record.rb +25 -0
- data/lib/rspec/rails/adapters.rb +104 -37
- data/lib/rspec/rails/configuration.rb +148 -0
- data/lib/rspec/rails/example/controller_example_group.rb +188 -138
- data/lib/rspec/rails/example/feature_example_group.rb +63 -20
- data/lib/rspec/rails/example/helper_example_group.rb +35 -26
- data/lib/rspec/rails/example/job_example_group.rb +23 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +30 -14
- data/lib/rspec/rails/example/model_example_group.rb +8 -7
- data/lib/rspec/rails/example/rails_example_group.rb +3 -1
- data/lib/rspec/rails/example/request_example_group.rb +23 -16
- data/lib/rspec/rails/example/routing_example_group.rb +49 -40
- data/lib/rspec/rails/example/system_example_group.rb +108 -0
- data/lib/rspec/rails/example/view_example_group.rb +168 -135
- data/lib/rspec/rails/example.rb +2 -33
- data/lib/rspec/rails/extensions/active_record/proxy.rb +0 -1
- data/lib/rspec/rails/extensions.rb +0 -1
- data/lib/rspec/rails/feature_check.rb +64 -0
- data/lib/rspec/rails/file_fixture_support.rb +17 -0
- data/lib/rspec/rails/fixture_file_upload_support.rb +40 -0
- data/lib/rspec/rails/fixture_support.rb +32 -13
- data/lib/rspec/rails/matchers/active_job.rb +317 -0
- data/lib/rspec/rails/matchers/base_matcher.rb +184 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +69 -62
- data/lib/rspec/rails/matchers/be_new_record.rb +24 -21
- data/lib/rspec/rails/matchers/be_valid.rb +42 -33
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +174 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +381 -0
- data/lib/rspec/rails/matchers/have_rendered.rb +54 -31
- data/lib/rspec/rails/matchers/redirect_to.rb +30 -29
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +107 -93
- data/lib/rspec/rails/matchers.rb +13 -14
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/vendor/capybara.rb +10 -4
- data/lib/rspec/rails/version.rb +3 -1
- data/lib/rspec/rails/view_assigns.rb +18 -18
- data/lib/rspec/rails/view_path_builder.rb +29 -0
- data/lib/rspec/rails/view_rendering.rb +89 -63
- data/lib/rspec/rails/view_spec_methods.rb +56 -0
- data/lib/rspec/rails.rb +10 -10
- data/lib/rspec-rails.rb +66 -1
- data.tar.gz.sig +0 -0
- metadata +92 -77
- metadata.gz.sig +0 -0
- data/lib/autotest/rails_rspec2.rb +0 -85
- data/lib/generators/rspec/install/templates/.rspec +0 -1
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +0 -49
- data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
- data/lib/rspec/rails/matchers/have_extension.rb +0 -36
- data/lib/rspec/rails/mocks.rb +0 -274
- data/lib/rspec/rails/module_inclusion.rb +0 -19
- data/lib/rspec/rails/vendor/webrat.rb +0 -33
@@ -1,40 +1,63 @@
|
|
1
|
-
module RSpec
|
2
|
-
module
|
3
|
-
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
module Matchers
|
4
|
+
# Matcher for template rendering.
|
5
|
+
module RenderTemplate
|
6
|
+
# @private
|
7
|
+
class RenderTemplateMatcher < RSpec::Rails::Matchers::BaseMatcher
|
8
|
+
def initialize(scope, expected, message = nil)
|
9
|
+
@expected = Symbol === expected ? expected.to_s : expected
|
10
|
+
@message = message
|
11
|
+
@scope = scope
|
12
|
+
@redirect_is = nil
|
13
|
+
end
|
4
14
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
15
|
+
# @api private
|
16
|
+
def matches?(*)
|
17
|
+
match_check = match_unless_raises ActiveSupport::TestCase::Assertion do
|
18
|
+
@scope.assert_template expected, @message
|
19
|
+
end
|
20
|
+
check_redirect unless match_check
|
21
|
+
match_check
|
22
|
+
end
|
23
|
+
|
24
|
+
# Uses normalize_argument_to_redirection to find and format
|
25
|
+
# the redirect location. normalize_argument_to_redirection is private
|
26
|
+
# in ActionDispatch::Assertions::ResponseAssertions so we call it
|
27
|
+
# here using #send. This will keep the error message format consistent
|
28
|
+
# @api private
|
29
|
+
def check_redirect
|
30
|
+
response = @scope.response
|
31
|
+
return unless response.respond_to?(:redirect?) && response.redirect?
|
32
|
+
@redirect_is = @scope.send(:normalize_argument_to_redirection, response.location)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
def failure_message
|
37
|
+
if @redirect_is
|
38
|
+
rescued_exception.message[/(.*?)( but|$)/, 1] +
|
39
|
+
" but was a redirect to <#{@redirect_is}>"
|
40
|
+
else
|
41
|
+
rescued_exception.message
|
42
|
+
end
|
43
|
+
end
|
10
44
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
45
|
+
# @api private
|
46
|
+
def failure_message_when_negated
|
47
|
+
"expected not to render #{expected.inspect}, but did"
|
48
|
+
end
|
15
49
|
end
|
16
|
-
end
|
17
50
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
51
|
+
# Delegates to `assert_template`.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# expect(response).to have_rendered("new")
|
55
|
+
def have_rendered(options, message = nil)
|
56
|
+
RenderTemplateMatcher.new(self, options, message)
|
57
|
+
end
|
22
58
|
|
23
|
-
|
24
|
-
def failure_message_for_should_not
|
25
|
-
"expected not to render #{expected.inspect}, but did"
|
59
|
+
alias_method :render_template, :have_rendered
|
26
60
|
end
|
27
61
|
end
|
28
|
-
|
29
|
-
# Delegates to `assert_template`
|
30
|
-
#
|
31
|
-
# @example
|
32
|
-
#
|
33
|
-
# response.should have_rendered("new")
|
34
|
-
def have_rendered(options, message=nil)
|
35
|
-
RenderTemplateMatcher.new(self, options, message)
|
36
|
-
end
|
37
|
-
|
38
|
-
alias_method :render_template, :have_rendered
|
39
62
|
end
|
40
63
|
end
|
@@ -1,37 +1,38 @@
|
|
1
|
-
module RSpec
|
2
|
-
module
|
3
|
-
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
module Matchers
|
4
|
+
# Matcher for redirects.
|
5
|
+
module RedirectTo
|
6
|
+
# @private
|
7
|
+
class RedirectTo < RSpec::Rails::Matchers::BaseMatcher
|
8
|
+
def initialize(scope, expected)
|
9
|
+
@expected = expected
|
10
|
+
@scope = scope
|
11
|
+
end
|
4
12
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
13
|
+
def matches?(_)
|
14
|
+
match_unless_raises ActiveSupport::TestCase::Assertion do
|
15
|
+
@scope.assert_redirected_to(@expected)
|
16
|
+
end
|
17
|
+
end
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@scope.assert_redirected_to(@expected)
|
14
|
-
end
|
15
|
-
end
|
19
|
+
def failure_message
|
20
|
+
rescued_exception.message
|
21
|
+
end
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
def failure_message_when_negated
|
24
|
+
"expected not to redirect to #{@expected.inspect}, but did"
|
25
|
+
end
|
26
|
+
end
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
# Delegates to `assert_redirected_to`.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# expect(response).to redirect_to(:action => "new")
|
32
|
+
def redirect_to(target)
|
33
|
+
RedirectTo.new(self, target)
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
27
|
-
|
28
|
-
# Delegates to `assert_redirected_to`
|
29
|
-
#
|
30
|
-
# @example
|
31
|
-
#
|
32
|
-
# response.should redirect_to(:action => "new")
|
33
|
-
def redirect_to(target)
|
34
|
-
RedirectTo.new(self, target)
|
35
|
-
end
|
36
37
|
end
|
37
38
|
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
if defined?(ActiveRecord::Relation)
|
2
|
-
RSpec::Matchers::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::
|
2
|
+
RSpec::Matchers::BuiltIn::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::ContainExactly)
|
3
3
|
end
|
@@ -1,109 +1,123 @@
|
|
1
|
-
module RSpec
|
2
|
-
module
|
3
|
-
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
module Matchers
|
4
|
+
# Matchers to help with specs for routing code.
|
5
|
+
module RoutingMatchers
|
6
|
+
extend RSpec::Matchers::DSL
|
4
7
|
|
5
|
-
|
8
|
+
# @private
|
9
|
+
class RouteToMatcher < RSpec::Rails::Matchers::BaseMatcher
|
10
|
+
def initialize(scope, *expected)
|
11
|
+
@scope = scope
|
12
|
+
@expected = expected[1] || {}
|
13
|
+
if Hash === expected[0]
|
14
|
+
@expected.merge!(expected[0])
|
15
|
+
else
|
16
|
+
controller, action = expected[0].split('#')
|
17
|
+
@expected.merge!(:controller => controller, :action => action)
|
18
|
+
end
|
19
|
+
end
|
6
20
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@actual = @verb_to_path_map = verb_to_path_map
|
21
|
-
# assert_recognizes does not consider ActionController::RoutingError an
|
22
|
-
# assertion failure, so we have to capture that and Assertion here.
|
23
|
-
match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
|
24
|
-
path, query = *verb_to_path_map.values.first.split('?')
|
25
|
-
@scope.assert_recognizes(
|
26
|
-
@expected,
|
27
|
-
{:method => verb_to_path_map.keys.first, :path => path},
|
28
|
-
Rack::Utils::parse_query(query)
|
29
|
-
)
|
30
|
-
end
|
31
|
-
end
|
21
|
+
def matches?(verb_to_path_map)
|
22
|
+
@actual = verb_to_path_map
|
23
|
+
# assert_recognizes does not consider ActionController::RoutingError an
|
24
|
+
# assertion failure, so we have to capture that and Assertion here.
|
25
|
+
match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
|
26
|
+
path, query = *verb_to_path_map.values.first.split('?')
|
27
|
+
@scope.assert_recognizes(
|
28
|
+
@expected,
|
29
|
+
{ :method => verb_to_path_map.keys.first, :path => path },
|
30
|
+
Rack::Utils.parse_nested_query(query)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
35
|
+
def failure_message
|
36
|
+
rescued_exception.message
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def failure_message_when_negated
|
40
|
+
"expected #{@actual.inspect} not to route to #{@expected.inspect}"
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
def description
|
44
|
+
"route #{@actual.inspect} to #{@expected.inspect}"
|
45
|
+
end
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
48
|
+
# Delegates to `assert_recognizes`. Supports short-hand controller/action
|
49
|
+
# declarations (e.g. `"controller#action"`).
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
#
|
53
|
+
# expect(:get => "/things/special").to route_to(
|
54
|
+
# :controller => "things",
|
55
|
+
# :action => "special"
|
56
|
+
# )
|
57
|
+
#
|
58
|
+
# expect(:get => "/things/special").to route_to("things#special")
|
59
|
+
#
|
60
|
+
# @see http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_recognizes
|
61
|
+
def route_to(*expected)
|
62
|
+
RouteToMatcher.new(self, *expected)
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
+
# @private
|
66
|
+
class BeRoutableMatcher < RSpec::Rails::Matchers::BaseMatcher
|
67
|
+
def initialize(scope)
|
68
|
+
@scope = scope
|
69
|
+
end
|
65
70
|
|
66
|
-
|
67
|
-
|
68
|
-
|
71
|
+
def matches?(path)
|
72
|
+
@actual = path
|
73
|
+
match_unless_raises ActionController::RoutingError do
|
74
|
+
@routing_options = @scope.routes.recognize_path(
|
75
|
+
path.values.first, :method => path.keys.first
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
69
79
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
match_unless_raises ActionController::RoutingError do
|
74
|
-
@routing_options = @scope.routes.recognize_path(
|
75
|
-
path.values.first, :method => path.keys.first
|
76
|
-
)
|
77
|
-
end
|
78
|
-
end
|
80
|
+
def failure_message
|
81
|
+
"expected #{@actual.inspect} to be routable"
|
82
|
+
end
|
79
83
|
|
80
|
-
|
81
|
-
|
82
|
-
|
84
|
+
def failure_message_when_negated
|
85
|
+
"expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
|
86
|
+
end
|
83
87
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
+
def description
|
89
|
+
"be routable"
|
90
|
+
end
|
91
|
+
end
|
88
92
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
BeRoutableMatcher.new(self)
|
101
|
-
end
|
93
|
+
# Passes if the route expression is recognized by the Rails router based on
|
94
|
+
# the declarations in `config/routes.rb`. Delegates to
|
95
|
+
# `RouteSet#recognize_path`.
|
96
|
+
#
|
97
|
+
# @example You can use route helpers provided by rspec-rails.
|
98
|
+
# expect(:get => "/a/path").to be_routable
|
99
|
+
# expect(:post => "/another/path").to be_routable
|
100
|
+
# expect(:put => "/yet/another/path").to be_routable
|
101
|
+
def be_routable
|
102
|
+
BeRoutableMatcher.new(self)
|
103
|
+
end
|
102
104
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
# Helpers for matching different route types.
|
106
|
+
module RouteHelpers
|
107
|
+
# @!method get
|
108
|
+
# @!method post
|
109
|
+
# @!method put
|
110
|
+
# @!method patch
|
111
|
+
# @!method delete
|
112
|
+
# @!method options
|
113
|
+
# @!method head
|
114
|
+
#
|
115
|
+
# Shorthand method for matching this type of route.
|
116
|
+
%w[get post put patch delete options head].each do |method|
|
117
|
+
define_method method do |path|
|
118
|
+
{ method.to_sym => path }
|
119
|
+
end
|
120
|
+
end
|
107
121
|
end
|
108
122
|
end
|
109
123
|
end
|
data/lib/rspec/rails/matchers.rb
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
-
require 'rspec/core/
|
1
|
+
require 'rspec/core/warnings'
|
2
2
|
require 'rspec/expectations'
|
3
|
+
require 'rspec/rails/feature_check'
|
3
4
|
|
4
|
-
module RSpec
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
begin
|
10
|
-
require 'test/unit/assertionfailederror'
|
11
|
-
rescue LoadError
|
12
|
-
module Test
|
13
|
-
module Unit
|
14
|
-
class AssertionFailedError < StandardError
|
15
|
-
end
|
5
|
+
module RSpec
|
6
|
+
module Rails
|
7
|
+
# @api public
|
8
|
+
# Container module for Rails specific matchers.
|
9
|
+
module Matchers
|
16
10
|
end
|
17
11
|
end
|
18
12
|
end
|
19
13
|
|
14
|
+
require 'rspec/rails/matchers/base_matcher'
|
20
15
|
require 'rspec/rails/matchers/have_rendered'
|
21
16
|
require 'rspec/rails/matchers/redirect_to'
|
22
17
|
require 'rspec/rails/matchers/routing_matchers'
|
23
18
|
require 'rspec/rails/matchers/be_new_record'
|
24
19
|
require 'rspec/rails/matchers/be_a_new'
|
25
|
-
require 'rspec/rails/matchers/have_extension'
|
26
20
|
require 'rspec/rails/matchers/relation_match_array'
|
27
21
|
require 'rspec/rails/matchers/be_valid'
|
22
|
+
require 'rspec/rails/matchers/have_http_status'
|
23
|
+
if RSpec::Rails::FeatureCheck.has_active_job?
|
24
|
+
require 'rspec/rails/matchers/active_job'
|
25
|
+
require 'rspec/rails/matchers/have_enqueued_mail'
|
26
|
+
end
|
@@ -22,7 +22,7 @@ namespace :spec do
|
|
22
22
|
task :prepare do
|
23
23
|
ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
|
24
24
|
if Rails.configuration.generators.options[:rails][:orm] == :active_record
|
25
|
-
if ::
|
25
|
+
if Rake::Task.task_defined?("test:prepare")
|
26
26
|
Rake::Task["test:prepare"].invoke
|
27
27
|
end
|
28
28
|
end
|
@@ -9,10 +9,17 @@ rescue LoadError
|
|
9
9
|
end
|
10
10
|
|
11
11
|
if defined?(Capybara)
|
12
|
+
require 'rspec/support/comparable_version'
|
13
|
+
unless RSpec::Support::ComparableVersion.new(Capybara::VERSION) >= '2.2.0'
|
14
|
+
raise "You are using capybara #{Capybara::VERSION}. RSpec requires >= 2.2.0."
|
15
|
+
end
|
16
|
+
|
12
17
|
RSpec.configure do |c|
|
13
18
|
if defined?(Capybara::DSL)
|
14
|
-
c.include Capybara::DSL, :type => :controller
|
15
19
|
c.include Capybara::DSL, :type => :feature
|
20
|
+
if defined?(ActionPack) && ActionPack::VERSION::STRING >= "5.1"
|
21
|
+
c.include Capybara::DSL, :type => :system
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
if defined?(Capybara::RSpecMatchers)
|
@@ -20,9 +27,8 @@ if defined?(Capybara)
|
|
20
27
|
c.include Capybara::RSpecMatchers, :type => :helper
|
21
28
|
c.include Capybara::RSpecMatchers, :type => :mailer
|
22
29
|
c.include Capybara::RSpecMatchers, :type => :controller
|
23
|
-
c.include Capybara::RSpecMatchers, :
|
24
|
-
|
25
|
-
}
|
30
|
+
c.include Capybara::RSpecMatchers, :type => :feature
|
31
|
+
c.include Capybara::RSpecMatchers, :type => :system
|
26
32
|
end
|
27
33
|
|
28
34
|
unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
|
data/lib/rspec/rails/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Rails
|
3
|
+
# Helpers for making instance variables available to views.
|
3
4
|
module ViewAssigns
|
4
5
|
# Assigns a value to an instance variable in the scope of the
|
5
6
|
# view being rendered.
|
@@ -11,35 +12,34 @@ module RSpec
|
|
11
12
|
_encapsulated_assigns[key] = value
|
12
13
|
end
|
13
14
|
|
15
|
+
# Compat-shim for AbstractController::Rendering#view_assigns
|
16
|
+
#
|
17
|
+
# _assigns was deprecated in favor of view_assigns after
|
18
|
+
# Rails-3.0.0 was released. Since we are not able to predict when
|
19
|
+
# the _assigns/view_assigns patch will be released (I thought it
|
20
|
+
# would have been in 3.0.1, but 3.0.1 bypassed this change for a
|
21
|
+
# security fix), this bit ensures that we do the right thing without
|
22
|
+
# knowing anything about the Rails version we are dealing with.
|
23
|
+
#
|
24
|
+
# Once that change _is_ released, this can be changed to something
|
25
|
+
# that checks for the Rails version when the module is being
|
26
|
+
# interpreted, as it was before commit dd0095.
|
14
27
|
def view_assigns
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# the _assigns/view_assigns patch will be released (I thought it
|
19
|
-
# would have been in 3.0.1, but 3.0.1 bypassed this change for a
|
20
|
-
# security fix), this bit ensures that we do the right thing without
|
21
|
-
# knowing anything about the Rails version we are dealing with.
|
22
|
-
#
|
23
|
-
# Once that change _is_ released, this can be changed to something
|
24
|
-
# that checks for the Rails version when the module is being
|
25
|
-
# interpreted, as it was before commit dd0095.
|
26
|
-
super.merge(_encapsulated_assigns)
|
27
|
-
rescue
|
28
|
-
_assigns
|
29
|
-
end
|
28
|
+
super.merge(_encapsulated_assigns)
|
29
|
+
rescue
|
30
|
+
_assigns
|
30
31
|
end
|
31
32
|
|
32
|
-
# @
|
33
|
+
# @private
|
33
34
|
def _assigns
|
34
35
|
super.merge(_encapsulated_assigns)
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
+
private
|
38
39
|
|
39
40
|
def _encapsulated_assigns
|
40
41
|
@_encapsulated_assigns ||= {}
|
41
42
|
end
|
42
|
-
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# Builds paths for view specs using a particular route set.
|
4
|
+
class ViewPathBuilder
|
5
|
+
def initialize(route_set)
|
6
|
+
self.class.send(:include, route_set.url_helpers)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Given a hash of parameters, build a view path, if possible.
|
10
|
+
# Returns nil if no path can be built from the given params.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # path can be built because all required params are present in the hash
|
14
|
+
# view_path_builder = ViewPathBuilder.new(::Rails.application.routes)
|
15
|
+
# view_path_builder.path_for({ :controller => 'posts', :action => 'show', :id => '54' })
|
16
|
+
# # => "/post/54"
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# # path cannot be built because the params are missing a required element (:id)
|
20
|
+
# view_path_builder.path_for({ :controller => 'posts', :action => 'delete' })
|
21
|
+
# # => ActionController::UrlGenerationError: No route matches {:action=>"delete", :controller=>"posts"}
|
22
|
+
def path_for(path_params)
|
23
|
+
url_for(path_params.merge(:only_path => true))
|
24
|
+
rescue => e
|
25
|
+
e.message
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|