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
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
module RSpec
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
module RSpec
|
|
2
|
+
module Rails
|
|
3
|
+
# Container class for request spec functionality.
|
|
4
|
+
module RequestExampleGroup
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
include RSpec::Rails::RailsExampleGroup
|
|
7
|
+
include ActionDispatch::Integration::Runner
|
|
8
|
+
include ActionDispatch::Assertions
|
|
9
|
+
include RSpec::Rails::Matchers::RedirectTo
|
|
10
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
|
11
|
+
include ActionController::TemplateAssertions
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
included do
|
|
16
|
-
metadata[:type] = :request
|
|
13
|
+
# Delegates to `Rails.application`.
|
|
14
|
+
def app
|
|
15
|
+
::Rails.application
|
|
16
|
+
end
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
included do
|
|
19
|
+
before do
|
|
20
|
+
@routes = ::Rails.application.routes
|
|
21
|
+
end
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
end
|
|
@@ -1,54 +1,55 @@
|
|
|
1
1
|
require "action_dispatch/testing/assertions/routing"
|
|
2
2
|
|
|
3
|
-
module RSpec
|
|
4
|
-
module
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
module RSpec
|
|
4
|
+
module Rails
|
|
5
|
+
# Container module for routing spec functionality.
|
|
6
|
+
module RoutingExampleGroup
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
include RSpec::Rails::RailsExampleGroup
|
|
9
|
+
include RSpec::Rails::Matchers::RoutingMatchers
|
|
10
|
+
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
|
|
11
|
+
include RSpec::Rails::AssertionDelegator.new(ActionDispatch::Assertions::RoutingAssertions)
|
|
12
|
+
|
|
13
|
+
# Class-level DSL for route specs.
|
|
14
|
+
module ClassMethods
|
|
15
|
+
# Specifies the routeset that will be used for the example group. This
|
|
16
|
+
# is most useful when testing Rails engines.
|
|
17
|
+
#
|
|
18
|
+
# @example
|
|
19
|
+
# describe MyEngine::PostsController do
|
|
20
|
+
# routes { MyEngine::Engine.routes }
|
|
21
|
+
#
|
|
22
|
+
# it "routes posts#index" do
|
|
23
|
+
# expect(:get => "/posts").to
|
|
24
|
+
# route_to(:controller => "my_engine/posts", :action => "index")
|
|
25
|
+
# end
|
|
26
|
+
# end
|
|
27
|
+
def routes(&blk)
|
|
28
|
+
before do
|
|
29
|
+
self.routes = blk.call
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
10
33
|
|
|
11
|
-
|
|
12
|
-
# Specifies the routeset that will be used for the example group. This
|
|
13
|
-
# is most useful when testing Rails engines.
|
|
14
|
-
#
|
|
15
|
-
# @example
|
|
16
|
-
#
|
|
17
|
-
# describe MyEngine::PostsController do
|
|
18
|
-
# routes { MyEngine::Engine.routes }
|
|
19
|
-
#
|
|
20
|
-
# it "routes posts#index" do
|
|
21
|
-
# expect(:get => "/posts").to
|
|
22
|
-
# route_to(:controller => "my_engine/posts", :action => "index")
|
|
23
|
-
# end
|
|
24
|
-
# end
|
|
25
|
-
def routes(&blk)
|
|
34
|
+
included do
|
|
26
35
|
before do
|
|
27
|
-
self.routes =
|
|
36
|
+
self.routes = ::Rails.application.routes
|
|
28
37
|
end
|
|
29
38
|
end
|
|
30
|
-
end
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
metadata[:type] = :routing
|
|
40
|
+
attr_reader :routes
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
# @private
|
|
43
|
+
def routes=(routes)
|
|
44
|
+
@routes = routes
|
|
45
|
+
assertion_instance.instance_variable_set(:@routes, routes)
|
|
37
46
|
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
attr_reader :routes
|
|
41
|
-
|
|
42
|
-
# @api private
|
|
43
|
-
def routes=(routes)
|
|
44
|
-
@routes = routes
|
|
45
|
-
assertion_instance.instance_variable_set(:@routes, routes)
|
|
46
|
-
end
|
|
47
47
|
|
|
48
48
|
private
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
def method_missing(m, *args, &block)
|
|
51
|
+
routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
|
|
52
|
+
end
|
|
52
53
|
end
|
|
53
54
|
end
|
|
54
55
|
end
|
|
@@ -1,169 +1,172 @@
|
|
|
1
1
|
require 'rspec/rails/view_assigns'
|
|
2
2
|
|
|
3
|
-
module RSpec
|
|
4
|
-
module
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
helpers << ApplicationHelper if Object.const_defined?('ApplicationHelper')
|
|
22
|
-
helpers
|
|
23
|
-
end
|
|
24
|
-
end
|
|
3
|
+
module RSpec
|
|
4
|
+
module Rails
|
|
5
|
+
# Container class for view spec functionality.
|
|
6
|
+
module ViewExampleGroup
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
include RSpec::Rails::RailsExampleGroup
|
|
9
|
+
include ActionView::TestCase::Behavior
|
|
10
|
+
include RSpec::Rails::ViewAssigns
|
|
11
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
|
12
|
+
|
|
13
|
+
# @private
|
|
14
|
+
module ClassMethods
|
|
15
|
+
def _default_helper
|
|
16
|
+
base = metadata[:description].split('/')[0..-2].join('/')
|
|
17
|
+
(base.camelize + 'Helper').constantize if base
|
|
18
|
+
rescue NameError
|
|
19
|
+
nil
|
|
20
|
+
end
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
# Delegates to ActionView::Base#render, so see documentation on that
|
|
33
|
-
# for more info.
|
|
34
|
-
#
|
|
35
|
-
# The only addition is that you can call render with no arguments, and RSpec
|
|
36
|
-
# will pass the top level description to render:
|
|
37
|
-
#
|
|
38
|
-
# describe "widgets/new.html.erb" do
|
|
39
|
-
# it "shows all the widgets" do
|
|
40
|
-
# render # => view.render(:file => "widgets/new.html.erb")
|
|
41
|
-
# # ...
|
|
42
|
-
# end
|
|
43
|
-
# end
|
|
44
|
-
def render(options={}, local_assigns={}, &block)
|
|
45
|
-
options = _default_render_options if Hash === options and options.empty?
|
|
46
|
-
super(options, local_assigns, &block)
|
|
22
|
+
def _default_helpers
|
|
23
|
+
helpers = [_default_helper].compact
|
|
24
|
+
helpers << ApplicationHelper if Object.const_defined?('ApplicationHelper')
|
|
25
|
+
helpers
|
|
26
|
+
end
|
|
47
27
|
end
|
|
48
28
|
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
29
|
+
# DSL exposed to view specs.
|
|
30
|
+
module ExampleMethods
|
|
31
|
+
# @overload render
|
|
32
|
+
# @overload render({:partial => path_to_file})
|
|
33
|
+
# @overload render({:partial => path_to_file}, {... locals ...})
|
|
34
|
+
# @overload render({:partial => path_to_file}, {... locals ...}) do ... end
|
|
35
|
+
#
|
|
36
|
+
# Delegates to ActionView::Base#render, so see documentation on that
|
|
37
|
+
# for more info.
|
|
38
|
+
#
|
|
39
|
+
# The only addition is that you can call render with no arguments, and
|
|
40
|
+
# RSpec will pass the top level description to render:
|
|
41
|
+
#
|
|
42
|
+
# describe "widgets/new.html.erb" do
|
|
43
|
+
# it "shows all the widgets" do
|
|
44
|
+
# render # => view.render(:file => "widgets/new.html.erb")
|
|
45
|
+
# # ...
|
|
46
|
+
# end
|
|
47
|
+
# end
|
|
48
|
+
def render(options = {}, local_assigns = {}, &block)
|
|
49
|
+
options = _default_render_options if Hash === options && options.empty?
|
|
50
|
+
super(options, local_assigns, &block)
|
|
51
|
+
end
|
|
62
52
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
# The instance of `ActionView::Base` that is used to render the template.
|
|
54
|
+
# Use this to stub methods _before_ calling `render`.
|
|
55
|
+
#
|
|
56
|
+
# describe "widgets/new.html.erb" do
|
|
57
|
+
# it "shows all the widgets" do
|
|
58
|
+
# view.stub(:foo) { "foo" }
|
|
59
|
+
# render
|
|
60
|
+
# # ...
|
|
61
|
+
# end
|
|
62
|
+
# end
|
|
63
|
+
def view
|
|
64
|
+
_view
|
|
65
|
+
end
|
|
74
66
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
# Simulates the presence of a template on the file system by adding a
|
|
68
|
+
# Rails' FixtureResolver to the front of the view_paths list. Designed to
|
|
69
|
+
# help isolate view examples from partials rendered by the view template
|
|
70
|
+
# that is the subject of the example.
|
|
71
|
+
#
|
|
72
|
+
# stub_template("widgets/_widget.html.erb" => "This content.")
|
|
73
|
+
def stub_template(hash)
|
|
74
|
+
view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
|
|
75
|
+
end
|
|
82
76
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
# Provides access to the params hash that will be available within the
|
|
78
|
+
# view.
|
|
79
|
+
#
|
|
80
|
+
# params[:foo] = 'bar'
|
|
81
|
+
def params
|
|
82
|
+
controller.params
|
|
83
|
+
end
|
|
88
84
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
# For backwards compatibility, we use #response as an alias for
|
|
94
|
-
# #rendered, but it needs to implement #body to avoid `assert_template`
|
|
95
|
-
# raising a `NoMethodError`.
|
|
96
|
-
unless rendered.respond_to?(:body)
|
|
97
|
-
def rendered.body; self; end;
|
|
85
|
+
# @deprecated Use `view` instead.
|
|
86
|
+
def template
|
|
87
|
+
RSpec.deprecate("template", :replacement => "view")
|
|
88
|
+
view
|
|
98
89
|
end
|
|
99
90
|
|
|
100
|
-
rendered
|
|
101
|
-
|
|
91
|
+
# @deprecated Use `rendered` instead.
|
|
92
|
+
def response
|
|
93
|
+
# `assert_template` expects `response` to implement a #body method
|
|
94
|
+
# like an `ActionDispatch::Response` does to force the view to
|
|
95
|
+
# render. For backwards compatibility, we use #response as an alias
|
|
96
|
+
# for #rendered, but it needs to implement #body to avoid
|
|
97
|
+
# `assert_template` raising a `NoMethodError`.
|
|
98
|
+
unless rendered.respond_to?(:body)
|
|
99
|
+
def rendered.body
|
|
100
|
+
self
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
rendered
|
|
105
|
+
end
|
|
102
106
|
|
|
103
|
-
|
|
107
|
+
private
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
def _default_render_options
|
|
110
|
+
if ::Rails::VERSION::STRING >= '3.2'
|
|
111
|
+
# pluck the handler, format, and locale out of, eg, posts/index.de.html.haml
|
|
112
|
+
template, *components = _default_file_to_render.split('.')
|
|
113
|
+
handler, format, locale = *components.reverse
|
|
110
114
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
render_options = { :template => template }
|
|
116
|
+
render_options[:handlers] = [handler] if handler
|
|
117
|
+
render_options[:formats] = [format] if format
|
|
118
|
+
render_options[:locales] = [locale] if locale
|
|
115
119
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
render_options
|
|
121
|
+
else
|
|
122
|
+
{ :template => _default_file_to_render }
|
|
123
|
+
end
|
|
119
124
|
end
|
|
120
|
-
end
|
|
121
125
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
def _path_parts
|
|
127
|
+
_default_file_to_render.split("/")
|
|
128
|
+
end
|
|
125
129
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
def _controller_path
|
|
131
|
+
_path_parts[0..-2].join("/")
|
|
132
|
+
end
|
|
129
133
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
def _inferred_action
|
|
135
|
+
_path_parts.last.split(".").first
|
|
136
|
+
end
|
|
133
137
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
def _include_controller_helpers
|
|
139
|
+
helpers = controller._helpers
|
|
140
|
+
view.singleton_class.class_exec do
|
|
141
|
+
include helpers unless included_modules.include?(helpers)
|
|
142
|
+
end
|
|
138
143
|
end
|
|
139
144
|
end
|
|
140
|
-
end
|
|
141
145
|
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
included do
|
|
147
|
+
include ExampleMethods
|
|
144
148
|
|
|
145
|
-
|
|
146
|
-
helper(*_default_helpers)
|
|
149
|
+
helper(*_default_helpers)
|
|
147
150
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
before do
|
|
152
|
+
_include_controller_helpers
|
|
153
|
+
if view.lookup_context.respond_to?(:prefixes)
|
|
154
|
+
# rails 3.1
|
|
155
|
+
view.lookup_context.prefixes << _controller_path
|
|
156
|
+
end
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
# fixes bug with differing formats
|
|
159
|
+
view.lookup_context.view_paths.each(&:clear_cache)
|
|
157
160
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
controller.controller_path = _controller_path
|
|
162
|
+
controller.request.path_parameters[:controller] = _controller_path
|
|
163
|
+
controller.request.path_parameters[:action] = _inferred_action unless _inferred_action =~ /^_/
|
|
164
|
+
end
|
|
162
165
|
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
let(:_default_file_to_render) do |example|
|
|
167
|
+
example.example_group.top_level_description
|
|
168
|
+
end
|
|
165
169
|
end
|
|
166
170
|
end
|
|
167
171
|
end
|
|
168
172
|
end
|
|
169
|
-
|
data/lib/rspec/rails/example.rb
CHANGED
|
@@ -7,36 +7,3 @@ require 'rspec/rails/example/mailer_example_group'
|
|
|
7
7
|
require 'rspec/rails/example/routing_example_group'
|
|
8
8
|
require 'rspec/rails/example/model_example_group'
|
|
9
9
|
require 'rspec/rails/example/feature_example_group'
|
|
10
|
-
|
|
11
|
-
RSpec::configure do |c|
|
|
12
|
-
def c.escaped_path(*parts)
|
|
13
|
-
Regexp.compile(parts.join('[\\\/]') + '[\\\/]')
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
c.include RSpec::Rails::ControllerExampleGroup, :type => :controller, :example_group => {
|
|
17
|
-
:file_path => c.escaped_path(%w[spec controllers])
|
|
18
|
-
}
|
|
19
|
-
c.include RSpec::Rails::HelperExampleGroup, :type => :helper, :example_group => {
|
|
20
|
-
:file_path => c.escaped_path(%w[spec helpers])
|
|
21
|
-
}
|
|
22
|
-
if defined?(RSpec::Rails::MailerExampleGroup)
|
|
23
|
-
c.include RSpec::Rails::MailerExampleGroup, :type => :mailer, :example_group => {
|
|
24
|
-
:file_path => c.escaped_path(%w[spec mailers])
|
|
25
|
-
}
|
|
26
|
-
end
|
|
27
|
-
c.include RSpec::Rails::ModelExampleGroup, :type => :model, :example_group => {
|
|
28
|
-
:file_path => c.escaped_path(%w[spec models])
|
|
29
|
-
}
|
|
30
|
-
c.include RSpec::Rails::RequestExampleGroup, :type => :request, :example_group => {
|
|
31
|
-
:file_path => c.escaped_path(%w[spec (requests|integration|api)])
|
|
32
|
-
}
|
|
33
|
-
c.include RSpec::Rails::RoutingExampleGroup, :type => :routing, :example_group => {
|
|
34
|
-
:file_path => c.escaped_path(%w[spec routing])
|
|
35
|
-
}
|
|
36
|
-
c.include RSpec::Rails::ViewExampleGroup, :type => :view, :example_group => {
|
|
37
|
-
:file_path => c.escaped_path(%w[spec views])
|
|
38
|
-
}
|
|
39
|
-
c.include RSpec::Rails::FeatureExampleGroup, :type => :feature, :example_group => {
|
|
40
|
-
:file_path => c.escaped_path(%w[spec features])
|
|
41
|
-
}
|
|
42
|
-
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @api private
|
|
2
|
+
module RSpec
|
|
3
|
+
module Rails
|
|
4
|
+
# Disable some cops until https://github.com/bbatsov/rubocop/issues/1310
|
|
5
|
+
# rubocop:disable Style/IndentationConsistency
|
|
6
|
+
module FeatureCheck
|
|
7
|
+
# rubocop:disable Style/IndentationWidth
|
|
8
|
+
module_function
|
|
9
|
+
# rubocop:enable Style/IndentationWidth
|
|
10
|
+
|
|
11
|
+
def can_check_pending_migrations?
|
|
12
|
+
has_active_record_migration? &&
|
|
13
|
+
::ActiveRecord::Migration.respond_to?(:check_pending!)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def can_maintain_test_schema?
|
|
17
|
+
has_active_record_migration? &&
|
|
18
|
+
::ActiveRecord::Migration.respond_to?(:maintain_test_schema!)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def has_active_job?
|
|
22
|
+
defined?(::ActiveJob)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def has_active_record?
|
|
26
|
+
defined?(::ActiveRecord)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def has_active_record_migration?
|
|
30
|
+
has_active_record? && defined?(::ActiveRecord::Migration)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
# rubocop:enable Style/IndentationConsistency
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
module RSpec
|
|
2
2
|
module Rails
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# @private
|
|
4
|
+
module FixtureSupport
|
|
5
|
+
if defined?(ActiveRecord::TestFixtures)
|
|
5
6
|
extend ActiveSupport::Concern
|
|
6
7
|
include RSpec::Rails::SetupAndTeardownAdapter
|
|
7
8
|
include RSpec::Rails::MinitestLifecycleAdapter if ::ActiveRecord::VERSION::STRING > '4'
|
|
@@ -9,12 +10,12 @@ module RSpec
|
|
|
9
10
|
include ActiveRecord::TestFixtures
|
|
10
11
|
|
|
11
12
|
included do
|
|
12
|
-
# TODO (DC 2011-06-25) this is necessary because fixture_file_upload
|
|
13
|
+
# TODO: (DC 2011-06-25) this is necessary because fixture_file_upload
|
|
13
14
|
# accesses fixture_path directly on ActiveSupport::TestCase. This is
|
|
14
15
|
# fixed in rails by https://github.com/rails/rails/pull/1861, which
|
|
15
16
|
# should be part of the 3.1 release, at which point we can include
|
|
16
17
|
# these lines for rails < 3.1.
|
|
17
|
-
ActiveSupport::TestCase.
|
|
18
|
+
ActiveSupport::TestCase.class_exec do
|
|
18
19
|
include ActiveRecord::TestFixtures
|
|
19
20
|
self.fixture_path = RSpec.configuration.fixture_path
|
|
20
21
|
end
|
|
@@ -26,14 +27,6 @@ module RSpec
|
|
|
26
27
|
fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
|
-
|
|
30
|
-
RSpec.configure do |c|
|
|
31
|
-
c.include RSpec::Rails::FixtureSupport
|
|
32
|
-
c.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples
|
|
33
|
-
c.add_setting :use_instantiated_fixtures
|
|
34
|
-
c.add_setting :global_fixtures
|
|
35
|
-
c.add_setting :fixture_path
|
|
36
|
-
end
|
|
37
30
|
end
|
|
38
31
|
end
|
|
39
32
|
end
|