rspec-rails 2.99.0 → 3.1.0
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 +6 -14
- checksums.yaml.gz.sig +1 -0
- data/.yardopts +1 -1
- data/Capybara.md +1 -3
- data/Changelog.md +148 -11
- data/License.txt +1 -0
- data/README.md +202 -105
- 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 +16 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -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/{spec_helper.rb.tt → rails_helper.rb} +19 -28
- data/lib/generators/rspec/integration/integration_generator.rb +1 -12
- data/lib/generators/rspec/integration/templates/request_spec.rb +3 -8
- 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 +1 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +6 -6
- 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/scaffold/scaffold_generator.rb +108 -135
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +34 -39
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +5 -13
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -10
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +6 -14
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +9 -9
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +4 -11
- 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 +16 -6
- data/lib/rspec/rails/adapters.rb +33 -35
- data/lib/rspec/rails/configuration.rb +97 -0
- data/lib/rspec/rails/example/controller_example_group.rb +173 -159
- data/lib/rspec/rails/example/feature_example_group.rb +25 -20
- data/lib/rspec/rails/example/helper_example_group.rb +27 -26
- data/lib/rspec/rails/example/mailer_example_group.rb +29 -14
- data/lib/rspec/rails/example/model_example_group.rb +7 -7
- data/lib/rspec/rails/example/rails_example_group.rb +1 -0
- data/lib/rspec/rails/example/request_example_group.rb +19 -17
- data/lib/rspec/rails/example/routing_example_group.rb +40 -39
- data/lib/rspec/rails/example/view_example_group.rb +140 -137
- data/lib/rspec/rails/example.rb +0 -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 +35 -0
- data/lib/rspec/rails/fixture_support.rb +5 -12
- data/lib/rspec/rails/matchers/be_a_new.rb +67 -62
- data/lib/rspec/rails/matchers/be_new_record.rb +23 -21
- data/lib/rspec/rails/matchers/be_valid.rb +41 -33
- data/lib/rspec/rails/matchers/have_http_status.rb +361 -0
- data/lib/rspec/rails/matchers/have_rendered.rb +35 -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 +104 -94
- data/lib/rspec/rails/matchers.rb +7 -4
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/vendor/capybara.rb +2 -33
- data/lib/rspec/rails/version.rb +3 -1
- data/lib/rspec/rails/view_assigns.rb +18 -18
- data/lib/rspec/rails/view_rendering.rb +20 -45
- data/lib/rspec/rails.rb +2 -13
- data/lib/rspec-rails.rb +4 -1
- data.tar.gz.sig +0 -0
- metadata +80 -99
- metadata.gz.sig +3 -0
- data/lib/autotest/rails_rspec2.rb +0 -91
- data/lib/generators/rspec/install/templates/.rspec +0 -1
- data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
- data/lib/rspec/rails/infer_type_configuration.rb +0 -26
- data/lib/rspec/rails/matchers/have_extension.rb +0 -36
- data/lib/rspec/rails/mocks.rb +0 -284
- data/lib/rspec/rails/module_inclusion.rb +0 -19
- data/lib/rspec/rails/vendor/webrat.rb +0 -33
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
module RSpec
|
|
2
|
+
module Rails
|
|
3
|
+
# Fake class to document RSpec Rails configuration options. In practice,
|
|
4
|
+
# these are dynamically added to the normal RSpec configuration object.
|
|
5
|
+
class Configuration
|
|
6
|
+
# @!method infer_spec_type_from_file_location!
|
|
7
|
+
# Automatically tag specs in conventional directories with matching `type`
|
|
8
|
+
# metadata so that they have relevant helpers available to them. See
|
|
9
|
+
# `RSpec::Rails::DIRECTORY_MAPPINGS` for details on which metadata is
|
|
10
|
+
# applied to each directory.
|
|
11
|
+
|
|
12
|
+
# @!method render_views=(val)
|
|
13
|
+
#
|
|
14
|
+
# When set to `true`, controller specs will render the relevant view as
|
|
15
|
+
# well. Defaults to `false`.
|
|
16
|
+
|
|
17
|
+
# @!method render_views(val)
|
|
18
|
+
# Enables view rendering for controllers specs.
|
|
19
|
+
|
|
20
|
+
# @!method render_views?
|
|
21
|
+
# Reader for currently value of `render_views` setting.
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Mappings used by `infer_spec_type_from_file_location!`.
|
|
25
|
+
#
|
|
26
|
+
# @api private
|
|
27
|
+
DIRECTORY_MAPPINGS = {
|
|
28
|
+
:controller => %w[spec controllers],
|
|
29
|
+
:helper => %w[spec helpers],
|
|
30
|
+
:mailer => %w[spec mailers],
|
|
31
|
+
:model => %w[spec models],
|
|
32
|
+
:request => %w[spec (requests|integration|api)],
|
|
33
|
+
:routing => %w[spec routing],
|
|
34
|
+
:view => %w[spec views],
|
|
35
|
+
:feature => %w[spec features]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# @private
|
|
39
|
+
def self.initialize_configuration(config)
|
|
40
|
+
config.backtrace_exclusion_patterns << /vendor\//
|
|
41
|
+
config.backtrace_exclusion_patterns << %r{ lib/rspec/rails }
|
|
42
|
+
|
|
43
|
+
config.include RSpec::Rails::ControllerExampleGroup, :type => :controller
|
|
44
|
+
config.include RSpec::Rails::HelperExampleGroup, :type => :helper
|
|
45
|
+
config.include RSpec::Rails::ModelExampleGroup, :type => :model
|
|
46
|
+
config.include RSpec::Rails::RequestExampleGroup, :type => :request
|
|
47
|
+
config.include RSpec::Rails::RoutingExampleGroup, :type => :routing
|
|
48
|
+
config.include RSpec::Rails::ViewExampleGroup, :type => :view
|
|
49
|
+
config.include RSpec::Rails::FeatureExampleGroup, :type => :feature
|
|
50
|
+
|
|
51
|
+
if defined?(ActionMailer)
|
|
52
|
+
config.include RSpec::Rails::MailerExampleGroup, :type => :mailer
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# controller settings
|
|
56
|
+
config.add_setting :infer_base_class_for_anonymous_controllers, :default => true
|
|
57
|
+
|
|
58
|
+
# fixture support
|
|
59
|
+
config.include RSpec::Rails::FixtureSupport
|
|
60
|
+
config.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples
|
|
61
|
+
config.add_setting :use_instantiated_fixtures
|
|
62
|
+
config.add_setting :global_fixtures
|
|
63
|
+
config.add_setting :fixture_path
|
|
64
|
+
|
|
65
|
+
# This allows us to expose `render_views` as a config option even though it
|
|
66
|
+
# breaks the convention of other options by using `render_views` as a
|
|
67
|
+
# command (i.e. `render_views = true`), where it would normally be used
|
|
68
|
+
# as a getter. This makes it easier for rspec-rails users because we use
|
|
69
|
+
# `render_views` directly in example groups, so this aligns the two APIs,
|
|
70
|
+
# but requires this workaround:
|
|
71
|
+
config.add_setting :rendering_views, :default => false
|
|
72
|
+
|
|
73
|
+
def config.render_views=(val)
|
|
74
|
+
self.rendering_views = val
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def config.render_views
|
|
78
|
+
self.rendering_views = true
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def config.render_views?
|
|
82
|
+
rendering_views
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def config.infer_spec_type_from_file_location!
|
|
86
|
+
DIRECTORY_MAPPINGS.each do |type, dir_parts|
|
|
87
|
+
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
|
|
88
|
+
define_derived_metadata(:file_path => escaped_path) do |metadata|
|
|
89
|
+
metadata[:type] ||= type
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
initialize_configuration RSpec.configuration
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -1,188 +1,202 @@
|
|
|
1
|
-
RSpec
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
described_class
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Supports a simple DSL for specifying behavior of ApplicationController.
|
|
23
|
-
# Creates an anonymous subclass of ApplicationController and evals the
|
|
24
|
-
# `body` in that context. Also sets up implicit routes for this
|
|
25
|
-
# controller, that are separate from those defined in "config/routes.rb".
|
|
26
|
-
#
|
|
27
|
-
# @note Due to Ruby 1.8 scoping rules in anoymous subclasses, constants
|
|
28
|
-
# defined in `ApplicationController` must be fully qualified (e.g.
|
|
29
|
-
# `ApplicationController::AccessDenied`) in the block passed to the
|
|
30
|
-
# `controller` method. Any instance methods, filters, etc, that are
|
|
31
|
-
# defined in `ApplicationController`, however, are accessible from
|
|
32
|
-
# within the block.
|
|
33
|
-
#
|
|
34
|
-
# @example
|
|
35
|
-
#
|
|
36
|
-
# describe ApplicationController do
|
|
37
|
-
# controller do
|
|
38
|
-
# def index
|
|
39
|
-
# raise ApplicationController::AccessDenied
|
|
40
|
-
# end
|
|
41
|
-
# end
|
|
42
|
-
#
|
|
43
|
-
# describe "handling AccessDenied exceptions" do
|
|
44
|
-
# it "redirects to the /401.html page" do
|
|
45
|
-
# get :index
|
|
46
|
-
# response.should redirect_to("/401.html")
|
|
47
|
-
# end
|
|
48
|
-
# end
|
|
49
|
-
# end
|
|
50
|
-
#
|
|
51
|
-
# If you would like to spec a subclass of ApplicationController, call
|
|
52
|
-
# controller like so:
|
|
53
|
-
#
|
|
54
|
-
# controller(ApplicationControllerSubclass) do
|
|
55
|
-
# # ....
|
|
56
|
-
# end
|
|
57
|
-
def controller(base_class = nil, &body)
|
|
58
|
-
root_controller = defined?(ApplicationController) ? ApplicationController : ActionController::Base
|
|
59
|
-
base_class ||= RSpec.configuration.infer_base_class_for_anonymous_controllers? ?
|
|
60
|
-
controller_class :
|
|
61
|
-
root_controller
|
|
62
|
-
base_class ||= root_controller
|
|
63
|
-
|
|
64
|
-
new_controller_class = Class.new(base_class) do
|
|
65
|
-
def self.name; "AnonymousController"; end
|
|
1
|
+
module RSpec
|
|
2
|
+
module Rails
|
|
3
|
+
# Container module for controller spec functionality.
|
|
4
|
+
module ControllerExampleGroup
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
include RSpec::Rails::RailsExampleGroup
|
|
7
|
+
include ActionController::TestCase::Behavior
|
|
8
|
+
include RSpec::Rails::ViewRendering
|
|
9
|
+
include RSpec::Rails::Matchers::RedirectTo
|
|
10
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
|
11
|
+
include RSpec::Rails::Matchers::RoutingMatchers
|
|
12
|
+
include RSpec::Rails::AssertionDelegator.new(ActionDispatch::Assertions::RoutingAssertions)
|
|
13
|
+
|
|
14
|
+
# Class-level DSL for controller specs.
|
|
15
|
+
module ClassMethods
|
|
16
|
+
# @private
|
|
17
|
+
def controller_class
|
|
18
|
+
described_class
|
|
66
19
|
end
|
|
67
|
-
new_controller_class.class_eval(&body)
|
|
68
20
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
21
|
+
# Supports a simple DSL for specifying behavior of ApplicationController.
|
|
22
|
+
# Creates an anonymous subclass of ApplicationController and evals the
|
|
23
|
+
# `body` in that context. Also sets up implicit routes for this
|
|
24
|
+
# controller, that are separate from those defined in "config/routes.rb".
|
|
25
|
+
#
|
|
26
|
+
# @note Due to Ruby 1.8 scoping rules in anonymous subclasses, constants
|
|
27
|
+
# defined in `ApplicationController` must be fully qualified (e.g.
|
|
28
|
+
# `ApplicationController::AccessDenied`) in the block passed to the
|
|
29
|
+
# `controller` method. Any instance methods, filters, etc, that are
|
|
30
|
+
# defined in `ApplicationController`, however, are accessible from
|
|
31
|
+
# within the block.
|
|
32
|
+
#
|
|
33
|
+
# @example
|
|
34
|
+
# describe ApplicationController do
|
|
35
|
+
# controller do
|
|
36
|
+
# def index
|
|
37
|
+
# raise ApplicationController::AccessDenied
|
|
38
|
+
# end
|
|
39
|
+
# end
|
|
40
|
+
#
|
|
41
|
+
# describe "handling AccessDenied exceptions" do
|
|
42
|
+
# it "redirects to the /401.html page" do
|
|
43
|
+
# get :index
|
|
44
|
+
# response.should redirect_to("/401.html")
|
|
45
|
+
# end
|
|
46
|
+
# end
|
|
47
|
+
# end
|
|
48
|
+
#
|
|
49
|
+
# If you would like to spec a subclass of ApplicationController, call
|
|
50
|
+
# controller like so:
|
|
51
|
+
#
|
|
52
|
+
# controller(ApplicationControllerSubclass) do
|
|
53
|
+
# # ....
|
|
54
|
+
# end
|
|
55
|
+
def controller(base_class = nil, &body)
|
|
56
|
+
if RSpec.configuration.infer_base_class_for_anonymous_controllers?
|
|
57
|
+
base_class ||= controller_class
|
|
58
|
+
end
|
|
59
|
+
base_class ||= defined?(ApplicationController) ? ApplicationController : ActionController::Base
|
|
60
|
+
|
|
61
|
+
new_controller_class = Class.new(base_class) do
|
|
62
|
+
def self.name
|
|
63
|
+
root_controller = defined?(ApplicationController) ? ApplicationController : ActionController::Base
|
|
64
|
+
if superclass == root_controller || superclass.abstract?
|
|
65
|
+
"AnonymousController"
|
|
66
|
+
else
|
|
67
|
+
superclass.to_s
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
new_controller_class.class_exec(&body)
|
|
72
|
+
(class << self; self; end).__send__(:define_method, :controller_class) { new_controller_class }
|
|
73
|
+
|
|
74
|
+
before do
|
|
75
|
+
@orig_routes = routes
|
|
76
|
+
resource_name = if @controller.respond_to?(:controller_name)
|
|
77
|
+
@controller.controller_name.to_sym
|
|
78
|
+
else
|
|
79
|
+
:anonymous
|
|
80
|
+
end
|
|
81
|
+
resource_path = if @controller.respond_to?(:controller_path)
|
|
82
|
+
@controller.controller_path
|
|
83
|
+
else
|
|
84
|
+
resource_name.to_s
|
|
85
|
+
end
|
|
86
|
+
resource_module = resource_path.rpartition('/').first.presence
|
|
87
|
+
resource_as = 'anonymous_' + resource_path.tr('/', '_')
|
|
88
|
+
self.routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
|
89
|
+
r.draw do
|
|
90
|
+
resources resource_name,
|
|
91
|
+
:as => resource_as,
|
|
92
|
+
:module => resource_module,
|
|
93
|
+
:path => resource_path
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
72
97
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
98
|
+
after do
|
|
99
|
+
self.routes = @orig_routes
|
|
100
|
+
@orig_routes = nil
|
|
101
|
+
end
|
|
78
102
|
end
|
|
79
103
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
# Specifies the routeset that will be used for the example group. This
|
|
105
|
+
# is most useful when testing Rails engines.
|
|
106
|
+
#
|
|
107
|
+
# @example
|
|
108
|
+
# describe MyEngine::PostsController do
|
|
109
|
+
# routes { MyEngine::Engine.routes }
|
|
110
|
+
#
|
|
111
|
+
# # ...
|
|
112
|
+
# end
|
|
113
|
+
def routes(&blk)
|
|
114
|
+
before do
|
|
115
|
+
self.routes = blk.call
|
|
116
|
+
end
|
|
83
117
|
end
|
|
84
118
|
end
|
|
85
119
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
end
|
|
101
|
-
end
|
|
120
|
+
attr_reader :controller, :routes
|
|
121
|
+
|
|
122
|
+
# @private
|
|
123
|
+
#
|
|
124
|
+
# RSpec Rails uses this to make Rails routes easily available to specs.
|
|
125
|
+
def routes=(routes)
|
|
126
|
+
@routes = routes
|
|
127
|
+
assertion_instance.instance_variable_set(:@routes, routes)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# @private
|
|
131
|
+
module BypassRescue
|
|
132
|
+
def rescue_with_handler(exception)
|
|
133
|
+
raise exception
|
|
102
134
|
end
|
|
103
135
|
end
|
|
104
136
|
|
|
105
|
-
#
|
|
106
|
-
#
|
|
137
|
+
# Extends the controller with a module that overrides
|
|
138
|
+
# `rescue_with_handler` to raise the exception passed to it. Use this to
|
|
139
|
+
# specify that an action _should_ raise an exception given appropriate
|
|
140
|
+
# conditions.
|
|
107
141
|
#
|
|
108
142
|
# @example
|
|
143
|
+
# describe ProfilesController do
|
|
144
|
+
# it "raises a 403 when a non-admin user tries to view another user's profile" do
|
|
145
|
+
# profile = create_profile
|
|
146
|
+
# login_as profile.user
|
|
109
147
|
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
#
|
|
148
|
+
# expect do
|
|
149
|
+
# bypass_rescue
|
|
150
|
+
# get :show, :id => profile.id + 1
|
|
151
|
+
# end.to raise_error(/403 Forbidden/)
|
|
152
|
+
# end
|
|
114
153
|
# end
|
|
115
|
-
def
|
|
116
|
-
|
|
117
|
-
|
|
154
|
+
def bypass_rescue
|
|
155
|
+
controller.extend(BypassRescue)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# If method is a named_route, delegates to the RouteSet associated with
|
|
159
|
+
# this controller.
|
|
160
|
+
def method_missing(method, *args, &block)
|
|
161
|
+
if route_available?(method)
|
|
162
|
+
controller.send(method, *args, &block)
|
|
163
|
+
else
|
|
164
|
+
super
|
|
118
165
|
end
|
|
119
166
|
end
|
|
120
|
-
end
|
|
121
167
|
|
|
122
|
-
|
|
168
|
+
included do
|
|
169
|
+
subject { controller }
|
|
123
170
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
assertion_instance.instance_variable_set(:@routes, routes)
|
|
128
|
-
end
|
|
171
|
+
before do
|
|
172
|
+
self.routes = ::Rails.application.routes
|
|
173
|
+
end
|
|
129
174
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
175
|
+
around do |ex|
|
|
176
|
+
previous_allow_forgery_protection_value = ActionController::Base.allow_forgery_protection
|
|
177
|
+
begin
|
|
178
|
+
ActionController::Base.allow_forgery_protection = false
|
|
179
|
+
ex.call
|
|
180
|
+
ensure
|
|
181
|
+
ActionController::Base.allow_forgery_protection = previous_allow_forgery_protection_value
|
|
182
|
+
end
|
|
183
|
+
end
|
|
133
184
|
end
|
|
134
|
-
end
|
|
135
185
|
|
|
136
|
-
|
|
137
|
-
# `rescue_with_handler` to raise the exception passed to it. Use this to
|
|
138
|
-
# specify that an action _should_ raise an exception given appropriate
|
|
139
|
-
# conditions.
|
|
140
|
-
#
|
|
141
|
-
# @example
|
|
142
|
-
#
|
|
143
|
-
# describe ProfilesController do
|
|
144
|
-
# it "raises a 403 when a non-admin user tries to view another user's profile" do
|
|
145
|
-
# profile = create_profile
|
|
146
|
-
# login_as profile.user
|
|
147
|
-
#
|
|
148
|
-
# expect do
|
|
149
|
-
# bypass_rescue
|
|
150
|
-
# get :show, :id => profile.id + 1
|
|
151
|
-
# end.to raise_error(/403 Forbidden/)
|
|
152
|
-
# end
|
|
153
|
-
# end
|
|
154
|
-
def bypass_rescue
|
|
155
|
-
controller.extend(BypassRescue)
|
|
156
|
-
end
|
|
186
|
+
private
|
|
157
187
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if @routes && @routes.named_routes.helpers.include?(method)
|
|
162
|
-
controller.send(method, *args, &block)
|
|
163
|
-
elsif defined?(@orig_routes) && @orig_routes && @orig_routes.named_routes.helpers.include?(method)
|
|
164
|
-
controller.send(method, *args, &block)
|
|
165
|
-
else
|
|
166
|
-
super
|
|
188
|
+
def route_available?(method)
|
|
189
|
+
(defined?(@routes) && route_defined?(routes, method)) ||
|
|
190
|
+
(defined?(@orig_routes) && route_defined?(@orig_routes, method))
|
|
167
191
|
end
|
|
168
|
-
end
|
|
169
192
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
metadata[:type] = :controller
|
|
174
|
-
|
|
175
|
-
before do
|
|
176
|
-
self.routes = ::Rails.application.routes
|
|
177
|
-
end
|
|
193
|
+
def route_defined?(routes, method)
|
|
194
|
+
return false if routes.nil?
|
|
178
195
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
ex.call
|
|
184
|
-
ensure
|
|
185
|
-
ActionController::Base.allow_forgery_protection = previous_allow_forgery_protection_value
|
|
196
|
+
if routes.named_routes.respond_to?(:route_defined?)
|
|
197
|
+
routes.named_routes.route_defined?(method)
|
|
198
|
+
else
|
|
199
|
+
routes.named_routes.helpers.include?(method)
|
|
186
200
|
end
|
|
187
201
|
end
|
|
188
202
|
end
|
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
module RSpec
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module RSpec
|
|
2
|
+
module Rails
|
|
3
|
+
# Container module for routing spec functionality.
|
|
4
|
+
module FeatureExampleGroup
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
include RSpec::Rails::RailsExampleGroup
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
# Default host to be used in Rails route helpers if none is specified.
|
|
9
|
+
DEFAULT_HOST = "www.example.com"
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
included do
|
|
12
|
+
app = ::Rails.application
|
|
13
|
+
if app.respond_to?(:routes)
|
|
14
|
+
include app.routes.url_helpers if app.routes.respond_to?(:url_helpers)
|
|
15
|
+
include app.routes.mounted_helpers if app.routes.respond_to?(:mounted_helpers)
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
include app.routes.mounted_helpers if app.routes.respond_to?(:mounted_helpers)
|
|
15
|
-
|
|
16
|
-
if respond_to?(:default_url_options)
|
|
17
|
-
default_url_options[:host] ||= ::RSpec::Rails::FeatureExampleGroup::DEFAULT_HOST
|
|
17
|
+
if respond_to?(:default_url_options)
|
|
18
|
+
default_url_options[:host] ||= ::RSpec::Rails::FeatureExampleGroup::DEFAULT_HOST
|
|
19
|
+
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
|
-
end
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
if
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
# Shim to check for presence of Capybara. Will delegate if present, raise
|
|
24
|
+
# if not. We assume here that in most cases `visit` will be the first
|
|
25
|
+
# Capybara method called in a spec.
|
|
26
|
+
def visit(*)
|
|
27
|
+
if defined?(super)
|
|
28
|
+
super
|
|
29
|
+
else
|
|
30
|
+
raise "Capybara not loaded, please add it to your Gemfile:\n\ngem \"capybara\""
|
|
31
|
+
end
|
|
27
32
|
end
|
|
28
33
|
end
|
|
29
34
|
end
|
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
require 'rspec/rails/view_assigns'
|
|
2
2
|
|
|
3
|
-
module RSpec
|
|
4
|
-
module
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
module RSpec
|
|
4
|
+
module Rails
|
|
5
|
+
# Container module for helper specs.
|
|
6
|
+
module HelperExampleGroup
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
include RSpec::Rails::RailsExampleGroup
|
|
9
|
+
include ActionView::TestCase::Behavior
|
|
10
|
+
include RSpec::Rails::ViewAssigns
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
# @private
|
|
13
|
+
module ClassMethods
|
|
14
|
+
def determine_default_helper_class(_ignore)
|
|
15
|
+
described_class
|
|
16
|
+
end
|
|
14
17
|
end
|
|
15
|
-
end
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
# Returns an instance of ActionView::Base with the helper being specified
|
|
20
|
+
# mixed in, along with any of the built-in rails helpers.
|
|
21
|
+
def helper
|
|
22
|
+
_view.tap do |v|
|
|
23
|
+
v.extend(ApplicationHelper) if defined?(ApplicationHelper)
|
|
24
|
+
v.assign(view_assigns)
|
|
25
|
+
end
|
|
23
26
|
end
|
|
24
|
-
end
|
|
25
27
|
|
|
26
28
|
private
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
included do
|
|
33
|
-
metadata[:type] = :helper
|
|
30
|
+
def _controller_path(example)
|
|
31
|
+
example.example_group.described_class.to_s.sub(/Helper/, '').underscore
|
|
32
|
+
end
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
included do
|
|
35
|
+
before do |example|
|
|
36
|
+
controller.controller_path = _controller_path(example)
|
|
37
|
+
end
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
end
|
|
@@ -1,20 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
module
|
|
1
|
+
module RSpec
|
|
2
|
+
module Rails
|
|
3
|
+
# Container module for mailer spec functionality. It is only available if
|
|
4
|
+
# ActionMailer has been loaded before it.
|
|
3
5
|
module MailerExampleGroup
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
# This blank module is only necessary for YARD processing. It doesn't
|
|
7
|
+
# handle the conditional `defined?` check below very well.
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
if defined?(ActionMailer)
|
|
13
|
+
module RSpec
|
|
14
|
+
module Rails
|
|
15
|
+
# Container module for mailer spec functionality.
|
|
16
|
+
module MailerExampleGroup
|
|
17
|
+
extend ActiveSupport::Concern
|
|
18
|
+
include RSpec::Rails::RailsExampleGroup
|
|
19
|
+
include ActionMailer::TestCase::Behavior
|
|
20
|
+
|
|
21
|
+
included do
|
|
22
|
+
include ::Rails.application.routes.url_helpers
|
|
23
|
+
options = ::Rails.configuration.action_mailer.default_url_options
|
|
24
|
+
options.each { |key, value| default_url_options[key] = value } if options
|
|
25
|
+
end
|
|
14
26
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
described_class
|
|
27
|
+
# Class-level DSL for mailer specs.
|
|
28
|
+
module ClassMethods
|
|
29
|
+
# Alias for `described_class`.
|
|
30
|
+
def mailer_class
|
|
31
|
+
described_class
|
|
32
|
+
end
|
|
18
33
|
end
|
|
19
34
|
end
|
|
20
35
|
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
module RSpec
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
module RSpec
|
|
2
|
+
module Rails
|
|
3
|
+
# Container class for model spec functionality. Does not provide anything
|
|
4
|
+
# special over the common RailsExampleGroup currently.
|
|
5
|
+
module ModelExampleGroup
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
include RSpec::Rails::RailsExampleGroup
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
end
|