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,169 +1,202 @@
|
|
1
1
|
require 'rspec/rails/view_assigns'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
2
|
+
require 'rspec/rails/view_spec_methods'
|
3
|
+
require 'rspec/rails/view_path_builder'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Rails
|
7
|
+
# @api public
|
8
|
+
# Container class for view spec functionality.
|
9
|
+
module ViewExampleGroup
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include RSpec::Rails::RailsExampleGroup
|
12
|
+
include ActionView::TestCase::Behavior
|
13
|
+
include RSpec::Rails::ViewAssigns
|
14
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
15
|
+
|
16
|
+
# @private
|
17
|
+
module StubResolverCache
|
18
|
+
def self.resolver_for(hash)
|
19
|
+
@resolvers ||= {}
|
20
|
+
@resolvers[hash] ||= ActionView::FixtureResolver.new(hash)
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
# @private
|
25
|
+
module ClassMethods
|
26
|
+
def _default_helper
|
27
|
+
base = metadata[:description].split('/')[0..-2].join('/')
|
28
|
+
(base.camelize + 'Helper').constantize unless base.to_s.empty?
|
29
|
+
rescue NameError
|
30
|
+
nil
|
31
|
+
end
|
25
32
|
|
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)
|
33
|
+
def _default_helpers
|
34
|
+
helpers = [_default_helper].compact
|
35
|
+
helpers << ApplicationHelper if Object.const_defined?('ApplicationHelper')
|
36
|
+
helpers
|
37
|
+
end
|
47
38
|
end
|
48
39
|
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
# describe "widgets/new.html.erb" do
|
53
|
-
# it "shows all the widgets" do
|
54
|
-
# view.stub(:foo) { "foo" }
|
55
|
-
# render
|
56
|
-
# # ...
|
57
|
-
# end
|
58
|
-
# end
|
59
|
-
def view
|
60
|
-
_view
|
61
|
-
end
|
40
|
+
# DSL exposed to view specs.
|
41
|
+
module ExampleMethods
|
42
|
+
extend ActiveSupport::Concern
|
62
43
|
|
63
|
-
|
64
|
-
|
65
|
-
# help isolate view examples from partials rendered by the view template
|
66
|
-
# that is the subject of the example.
|
67
|
-
#
|
68
|
-
# @example
|
69
|
-
#
|
70
|
-
# stub_template("widgets/_widget.html.erb" => "This content.")
|
71
|
-
def stub_template(hash)
|
72
|
-
view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
|
73
|
-
end
|
44
|
+
included do
|
45
|
+
include ::Rails.application.routes.url_helpers
|
74
46
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def params
|
80
|
-
controller.params
|
81
|
-
end
|
47
|
+
if ::Rails.application.routes.respond_to?(:mounted_helpers)
|
48
|
+
include ::Rails.application.routes.mounted_helpers
|
49
|
+
end
|
50
|
+
end
|
82
51
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
52
|
+
# @overload render
|
53
|
+
# @overload render({:partial => path_to_file})
|
54
|
+
# @overload render({:partial => path_to_file}, {... locals ...})
|
55
|
+
# @overload render({:partial => path_to_file}, {... locals ...}) do ... end
|
56
|
+
#
|
57
|
+
# Delegates to ActionView::Base#render, so see documentation on that
|
58
|
+
# for more info.
|
59
|
+
#
|
60
|
+
# The only addition is that you can call render with no arguments, and
|
61
|
+
# RSpec will pass the top level description to render:
|
62
|
+
#
|
63
|
+
# describe "widgets/new.html.erb" do
|
64
|
+
# it "shows all the widgets" do
|
65
|
+
# render # => view.render(:file => "widgets/new.html.erb")
|
66
|
+
# # ...
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
def render(options = {}, local_assigns = {}, &block)
|
70
|
+
options = _default_render_options if Hash === options && options.empty?
|
71
|
+
super(options, local_assigns, &block)
|
72
|
+
end
|
88
73
|
|
89
|
-
|
90
|
-
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
|
97
|
-
|
74
|
+
# The instance of `ActionView::Base` that is used to render the template.
|
75
|
+
# Use this to stub methods _before_ calling `render`.
|
76
|
+
#
|
77
|
+
# describe "widgets/new.html.erb" do
|
78
|
+
# it "shows all the widgets" do
|
79
|
+
# view.stub(:foo) { "foo" }
|
80
|
+
# render
|
81
|
+
# # ...
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
def view
|
85
|
+
_view
|
98
86
|
end
|
99
87
|
|
100
|
-
|
101
|
-
|
88
|
+
# Simulates the presence of a template on the file system by adding a
|
89
|
+
# Rails' FixtureResolver to the front of the view_paths list. Designed to
|
90
|
+
# help isolate view examples from partials rendered by the view template
|
91
|
+
# that is the subject of the example.
|
92
|
+
#
|
93
|
+
# stub_template("widgets/_widget.html.erb" => "This content.")
|
94
|
+
def stub_template(hash)
|
95
|
+
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
|
96
|
+
end
|
102
97
|
|
103
|
-
|
98
|
+
# Provides access to the params hash that will be available within the
|
99
|
+
# view.
|
100
|
+
#
|
101
|
+
# params[:foo] = 'bar'
|
102
|
+
def params
|
103
|
+
controller.params
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
# @deprecated Use `view` instead.
|
107
|
+
def template
|
108
|
+
RSpec.deprecate("template", :replacement => "view")
|
109
|
+
view
|
110
|
+
end
|
108
111
|
|
109
|
-
|
110
|
-
|
111
|
-
#
|
112
|
-
|
113
|
-
|
112
|
+
# @deprecated Use `rendered` instead.
|
113
|
+
def response
|
114
|
+
# `assert_template` expects `response` to implement a #body method
|
115
|
+
# like an `ActionDispatch::Response` does to force the view to
|
116
|
+
# render. For backwards compatibility, we use #response as an alias
|
117
|
+
# for #rendered, but it needs to implement #body to avoid
|
118
|
+
# `assert_template` raising a `NoMethodError`.
|
119
|
+
unless rendered.respond_to?(:body)
|
120
|
+
def rendered.body
|
121
|
+
self
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
rendered
|
126
|
+
end
|
114
127
|
|
115
|
-
|
116
|
-
render_options[:handlers] = [handler] if handler
|
117
|
-
render_options[:formats] = [format] if format
|
118
|
-
render_options[:locales] = [locale] if locale
|
128
|
+
private
|
119
129
|
|
120
|
-
|
121
|
-
|
122
|
-
|
130
|
+
def _default_render_options
|
131
|
+
if ::Rails::VERSION::STRING >= '3.2'
|
132
|
+
# pluck the handler, format, and locale out of, eg, posts/index.de.html.haml
|
133
|
+
template, *components = _default_file_to_render.split('.')
|
134
|
+
handler, format, locale = *components.reverse
|
135
|
+
|
136
|
+
render_options = { :template => template }
|
137
|
+
render_options[:handlers] = [handler] if handler
|
138
|
+
render_options[:formats] = [format.to_sym] if format
|
139
|
+
render_options[:locales] = [locale] if locale
|
140
|
+
|
141
|
+
render_options
|
142
|
+
else
|
143
|
+
{ :template => _default_file_to_render }
|
144
|
+
end
|
123
145
|
end
|
124
|
-
end
|
125
146
|
|
126
|
-
|
127
|
-
|
128
|
-
|
147
|
+
def _path_parts
|
148
|
+
_default_file_to_render.split("/")
|
149
|
+
end
|
129
150
|
|
130
|
-
|
131
|
-
|
132
|
-
|
151
|
+
def _controller_path
|
152
|
+
_path_parts[0..-2].join("/")
|
153
|
+
end
|
133
154
|
|
134
|
-
|
135
|
-
|
136
|
-
|
155
|
+
def _inferred_action
|
156
|
+
_path_parts.last.split(".").first
|
157
|
+
end
|
137
158
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
159
|
+
def _include_controller_helpers
|
160
|
+
helpers = controller._helpers
|
161
|
+
view.singleton_class.class_exec do
|
162
|
+
include helpers unless included_modules.include?(helpers)
|
163
|
+
end
|
142
164
|
end
|
143
165
|
end
|
144
|
-
end
|
145
166
|
|
146
|
-
|
147
|
-
|
167
|
+
included do
|
168
|
+
include ExampleMethods
|
169
|
+
|
170
|
+
helper(*_default_helpers)
|
171
|
+
|
172
|
+
before do
|
173
|
+
_include_controller_helpers
|
174
|
+
if view.lookup_context.respond_to?(:prefixes)
|
175
|
+
# rails 3.1
|
176
|
+
view.lookup_context.prefixes << _controller_path
|
177
|
+
end
|
178
|
+
|
179
|
+
controller.controller_path = _controller_path
|
148
180
|
|
149
|
-
|
150
|
-
|
181
|
+
path_params_to_merge = {}
|
182
|
+
path_params_to_merge[:controller] = _controller_path
|
183
|
+
path_params_to_merge[:action] = _inferred_action unless _inferred_action =~ /^_/
|
151
184
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
185
|
+
path_params = controller.request.path_parameters
|
186
|
+
|
187
|
+
controller.request.path_parameters = path_params.reverse_merge(path_params_to_merge)
|
188
|
+
controller.request.path = ViewPathBuilder.new(::Rails.application.routes).path_for(controller.request.path_parameters)
|
189
|
+
ViewSpecMethods.add_to(::ActionView::TestCase::TestController)
|
157
190
|
end
|
158
191
|
|
159
|
-
|
160
|
-
|
192
|
+
after do
|
193
|
+
ViewSpecMethods.remove_from(::ActionView::TestCase::TestController)
|
194
|
+
end
|
161
195
|
|
162
|
-
|
163
|
-
|
164
|
-
|
196
|
+
let(:_default_file_to_render) do |example|
|
197
|
+
example.example_group.top_level_description
|
198
|
+
end
|
165
199
|
end
|
166
200
|
end
|
167
201
|
end
|
168
202
|
end
|
169
|
-
|
data/lib/rspec/rails/example.rb
CHANGED
@@ -6,37 +6,6 @@ require 'rspec/rails/example/view_example_group'
|
|
6
6
|
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
|
+
require 'rspec/rails/example/job_example_group'
|
9
10
|
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
|
11
|
+
require 'rspec/rails/example/system_example_group'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @private
|
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
|
+
|
33
|
+
def has_action_mailer?
|
34
|
+
defined?(::ActionMailer)
|
35
|
+
end
|
36
|
+
|
37
|
+
def has_action_mailer_preview?
|
38
|
+
has_action_mailer? && defined?(::ActionMailer::Preview)
|
39
|
+
end
|
40
|
+
|
41
|
+
def has_action_mailer_show_preview?
|
42
|
+
has_action_mailer_preview? &&
|
43
|
+
::ActionMailer::Base.respond_to?(:show_previews=)
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_1_9_hash_syntax?
|
47
|
+
::Rails::VERSION::STRING > '4.0'
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_file_fixture?
|
51
|
+
::Rails::VERSION::STRING > '5.0'
|
52
|
+
end
|
53
|
+
|
54
|
+
def type_metatag(type)
|
55
|
+
if has_1_9_hash_syntax?
|
56
|
+
"type: :#{type}"
|
57
|
+
else
|
58
|
+
":type => :#{type}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
# rubocop:enable Style/IndentationConsistency
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
if ::Rails::VERSION::STRING > '5'
|
2
|
+
require 'active_support/testing/file_fixtures'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Rails
|
6
|
+
# @private
|
7
|
+
module FileFixtureSupport
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
include ActiveSupport::Testing::FileFixtures
|
10
|
+
|
11
|
+
included do
|
12
|
+
self.file_fixture_path = RSpec.configuration.file_fixture_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @private
|
4
|
+
module FixtureFileUploadSupport
|
5
|
+
delegate :fixture_file_upload, :to => :rails_fixture_file_wrapper
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def rails_fixture_file_wrapper
|
10
|
+
RailsFixtureFileWrapper.fixture_path = nil
|
11
|
+
resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '').to_s
|
12
|
+
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
|
13
|
+
RailsFixtureFileWrapper.instance
|
14
|
+
end
|
15
|
+
|
16
|
+
class RailsFixtureFileWrapper
|
17
|
+
include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_reader :fixture_path
|
21
|
+
|
22
|
+
# Get instance of wrapper
|
23
|
+
def instance
|
24
|
+
@instance ||= new
|
25
|
+
end
|
26
|
+
|
27
|
+
# Override fixture_path set
|
28
|
+
# to support Rails 3.0->3.1 using ActionController::TestCase class to resolve fixture_path
|
29
|
+
# see https://apidock.com/rails/v3.0.0/ActionDispatch/TestProcess/fixture_file_upload
|
30
|
+
def fixture_path=(value)
|
31
|
+
if ActionController::TestCase.respond_to?(:fixture_path)
|
32
|
+
ActionController::TestCase.fixture_path = value
|
33
|
+
end
|
34
|
+
@fixture_path = value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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,31 +10,49 @@ 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
|
21
22
|
# /TODO
|
22
23
|
|
23
24
|
self.fixture_path = RSpec.configuration.fixture_path
|
24
|
-
|
25
|
+
if ::Rails::VERSION::STRING > '5'
|
26
|
+
self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
|
27
|
+
else
|
28
|
+
self.use_transactional_fixtures = RSpec.configuration.use_transactional_fixtures
|
29
|
+
end
|
25
30
|
self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures
|
31
|
+
|
32
|
+
def self.fixtures(*args)
|
33
|
+
orig_methods = private_instance_methods
|
34
|
+
super.tap do
|
35
|
+
new_methods = private_instance_methods - orig_methods
|
36
|
+
new_methods.each do |method_name|
|
37
|
+
proxy_method_warning_if_called_in_before_context_scope(method_name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.proxy_method_warning_if_called_in_before_context_scope(method_name)
|
43
|
+
orig_implementation = instance_method(method_name)
|
44
|
+
define_method(method_name) do |*args, &blk|
|
45
|
+
if inspect.include?("before(:context)")
|
46
|
+
RSpec.warn_with("Calling fixture method in before :context ")
|
47
|
+
else
|
48
|
+
orig_implementation.bind(self).call(*args, &blk)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
26
53
|
fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
|
27
54
|
end
|
28
55
|
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
56
|
end
|
38
57
|
end
|
39
58
|
end
|