rspec-rails 3.9.1 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Capybara.md +5 -54
- data/Changelog.md +207 -77
- data/README.md +27 -21
- data/lib/generators/rspec.rb +0 -6
- data/lib/generators/rspec/channel/channel_generator.rb +12 -0
- data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +22 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
- data/lib/generators/rspec/feature/feature_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/generator_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +4 -4
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +17 -16
- data/lib/generators/rspec/integration/integration_generator.rb +3 -3
- data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
- data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +2 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +5 -4
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/request/request_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +29 -19
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +0 -36
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +0 -48
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -5
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +137 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +14 -16
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/rspec-rails.rb +13 -16
- data/lib/rspec/rails/adapters.rb +11 -76
- data/lib/rspec/rails/configuration.rb +81 -37
- data/lib/rspec/rails/example.rb +2 -0
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +4 -4
- data/lib/rspec/rails/example/feature_example_group.rb +6 -26
- data/lib/rspec/rails/example/helper_example_group.rb +2 -9
- data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/system_example_group.rb +29 -12
- data/lib/rspec/rails/example/view_example_group.rb +38 -27
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
- data/lib/rspec/rails/feature_check.rb +12 -29
- data/lib/rspec/rails/file_fixture_support.rb +9 -11
- data/lib/rspec/rails/fixture_file_upload_support.rb +33 -17
- data/lib/rspec/rails/fixture_support.rb +34 -32
- data/lib/rspec/rails/matchers.rb +9 -0
- data/lib/rspec/rails/matchers/action_cable.rb +65 -0
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
- data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
- data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
- data/lib/rspec/rails/matchers/active_job.rb +169 -21
- data/lib/rspec/rails/matchers/base_matcher.rb +5 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +52 -28
- data/lib/rspec/rails/matchers/have_http_status.rb +11 -7
- data/lib/rspec/rails/matchers/have_rendered.rb +1 -0
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +12 -12
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -15
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +15 -4
- metadata +47 -35
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -21,8 +21,8 @@ if defined?(ActionMailer)
|
|
21
21
|
|
22
22
|
included do
|
23
23
|
include ::Rails.application.routes.url_helpers
|
24
|
-
options = ::Rails.configuration.action_mailer.default_url_options
|
25
|
-
options.each { |key, value| default_url_options[key] = value }
|
24
|
+
options = ::Rails.configuration.action_mailer.default_url_options || {}
|
25
|
+
options.each { |key, value| default_url_options[key] = value }
|
26
26
|
end
|
27
27
|
|
28
28
|
# Class-level DSL for mailer specs.
|
@@ -9,7 +9,7 @@ module RSpec
|
|
9
9
|
module RailsExampleGroup
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
include RSpec::Rails::SetupAndTeardownAdapter
|
12
|
-
include RSpec::Rails::MinitestLifecycleAdapter
|
12
|
+
include RSpec::Rails::MinitestLifecycleAdapter
|
13
13
|
include RSpec::Rails::MinitestAssertionAdapter
|
14
14
|
include RSpec::Rails::FixtureSupport
|
15
15
|
end
|
@@ -10,10 +10,7 @@ module RSpec
|
|
10
10
|
include RSpec::Rails::Matchers::RedirectTo
|
11
11
|
include RSpec::Rails::Matchers::RenderTemplate
|
12
12
|
include ActionController::TemplateAssertions
|
13
|
-
|
14
|
-
if ActionPack::VERSION::MAJOR >= 5
|
15
|
-
include ActionDispatch::IntegrationTest::Behavior
|
16
|
-
end
|
13
|
+
include ActionDispatch::IntegrationTest::Behavior
|
17
14
|
|
18
15
|
# Delegates to `Rails.application`.
|
19
16
|
def app
|
@@ -15,7 +15,11 @@ module RSpec
|
|
15
15
|
CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze
|
16
16
|
|
17
17
|
# @private
|
18
|
-
module
|
18
|
+
module BlowAwayTeardownHooks
|
19
|
+
# @private
|
20
|
+
def before_teardown
|
21
|
+
end
|
22
|
+
|
19
23
|
# @private
|
20
24
|
def after_teardown
|
21
25
|
end
|
@@ -37,7 +41,7 @@ module RSpec
|
|
37
41
|
@method_name ||= [
|
38
42
|
self.class.name.underscore,
|
39
43
|
RSpec.current_example.description.underscore
|
40
|
-
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")
|
44
|
+
].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
|
41
45
|
end
|
42
46
|
|
43
47
|
# Delegates to `Rails.application`.
|
@@ -46,12 +50,14 @@ module RSpec
|
|
46
50
|
end
|
47
51
|
|
48
52
|
included do |other|
|
53
|
+
ActiveSupport.on_load(:action_dispatch_system_test_case) do
|
54
|
+
ActionDispatch::SystemTesting::Server.silence_puma = true
|
55
|
+
end
|
56
|
+
|
49
57
|
begin
|
50
58
|
require 'capybara'
|
51
59
|
require 'action_dispatch/system_test_case'
|
52
|
-
# rubocop:disable Lint/HandleExceptions
|
53
60
|
rescue LoadError => e
|
54
|
-
# rubocop:enable Lint/HandleExceptions
|
55
61
|
abort """
|
56
62
|
LoadError: #{e.message}
|
57
63
|
System test integration requires Rails >= 5.1 and has a hard
|
@@ -61,13 +67,17 @@ module RSpec
|
|
61
67
|
""".gsub(/\s+/, ' ').strip
|
62
68
|
end
|
63
69
|
|
70
|
+
if ::Rails::VERSION::STRING >= '6.0'
|
71
|
+
original_before_teardown =
|
72
|
+
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:before_teardown)
|
73
|
+
end
|
74
|
+
|
64
75
|
original_after_teardown =
|
65
76
|
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
|
66
77
|
|
67
|
-
other.include ActionDispatch::IntegrationTest::Behavior
|
68
78
|
other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
|
69
79
|
other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
|
70
|
-
other.include
|
80
|
+
other.include BlowAwayTeardownHooks
|
71
81
|
|
72
82
|
attr_reader :driver
|
73
83
|
|
@@ -78,16 +88,19 @@ module RSpec
|
|
78
88
|
def initialize(*args, &blk)
|
79
89
|
super(*args, &blk)
|
80
90
|
@driver = nil
|
91
|
+
|
92
|
+
self.class.before do
|
93
|
+
# A user may have already set the driver, so only default if driver
|
94
|
+
# is not set
|
95
|
+
driven_by(:selenium) unless @driver
|
96
|
+
end
|
81
97
|
end
|
82
98
|
|
83
|
-
def driven_by(
|
84
|
-
@driver = ::ActionDispatch::SystemTestCase.driven_by(
|
99
|
+
def driven_by(driver, **driver_options, &blk)
|
100
|
+
@driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
|
85
101
|
end
|
86
102
|
|
87
103
|
before do
|
88
|
-
# A user may have already set the driver, so only default if driver
|
89
|
-
# is not set
|
90
|
-
driven_by(:selenium) unless @driver
|
91
104
|
@routes = ::Rails.application.routes
|
92
105
|
end
|
93
106
|
|
@@ -95,10 +108,14 @@ module RSpec
|
|
95
108
|
orig_stdout = $stdout
|
96
109
|
$stdout = StringIO.new
|
97
110
|
begin
|
111
|
+
if ::Rails::VERSION::STRING >= '6.0'
|
112
|
+
original_before_teardown.bind(self).call
|
113
|
+
end
|
98
114
|
original_after_teardown.bind(self).call
|
99
115
|
ensure
|
100
116
|
myio = $stdout
|
101
|
-
|
117
|
+
myio.rewind
|
118
|
+
RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
|
102
119
|
$stdout = orig_stdout
|
103
120
|
end
|
104
121
|
end
|
@@ -43,16 +43,13 @@ module RSpec
|
|
43
43
|
|
44
44
|
included do
|
45
45
|
include ::Rails.application.routes.url_helpers
|
46
|
-
|
47
|
-
if ::Rails.application.routes.respond_to?(:mounted_helpers)
|
48
|
-
include ::Rails.application.routes.mounted_helpers
|
49
|
-
end
|
46
|
+
include ::Rails.application.routes.mounted_helpers
|
50
47
|
end
|
51
48
|
|
52
49
|
# @overload render
|
53
|
-
# @overload render({:
|
54
|
-
# @overload render({:
|
55
|
-
# @overload render({:
|
50
|
+
# @overload render({partial: path_to_file})
|
51
|
+
# @overload render({partial: path_to_file}, {... locals ...})
|
52
|
+
# @overload render({partial: path_to_file}, {... locals ...}) do ... end
|
56
53
|
#
|
57
54
|
# Delegates to ActionView::Base#render, so see documentation on that
|
58
55
|
# for more info.
|
@@ -62,7 +59,7 @@ module RSpec
|
|
62
59
|
#
|
63
60
|
# describe "widgets/new.html.erb" do
|
64
61
|
# it "shows all the widgets" do
|
65
|
-
# render # => view.render(:
|
62
|
+
# render # => view.render(file: "widgets/new.html.erb")
|
66
63
|
# # ...
|
67
64
|
# end
|
68
65
|
# end
|
@@ -105,7 +102,7 @@ module RSpec
|
|
105
102
|
|
106
103
|
# @deprecated Use `view` instead.
|
107
104
|
def template
|
108
|
-
RSpec.deprecate("template", :
|
105
|
+
RSpec.deprecate("template", replacement: "view")
|
109
106
|
view
|
110
107
|
end
|
111
108
|
|
@@ -128,20 +125,37 @@ module RSpec
|
|
128
125
|
private
|
129
126
|
|
130
127
|
def _default_render_options
|
131
|
-
if ::
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
128
|
+
formats = if ActionView::Template::Types.respond_to?(:symbols)
|
129
|
+
ActionView::Template::Types.symbols
|
130
|
+
else
|
131
|
+
[:html, :text, :js, :css, :xml, :json].map(&:to_s)
|
132
|
+
end.map { |x| Regexp.escape(x) }.join("|")
|
133
|
+
|
134
|
+
handlers = ActionView::Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|")
|
135
|
+
locales = "[a-z]{2}(?:-[A-Z]{2})?"
|
136
|
+
variants = "[^.]*"
|
137
|
+
path_regex = %r{
|
138
|
+
\A
|
139
|
+
(?<template>.*?)
|
140
|
+
(?:\.(?<locale>#{locales}))??
|
141
|
+
(?:\.(?<format>#{formats}))??
|
142
|
+
(?:\+(?<variant>#{variants}))??
|
143
|
+
(?:\.(?<handler>#{handlers}))?
|
144
|
+
\z
|
145
|
+
}x
|
146
|
+
|
147
|
+
# This regex should always find a match.
|
148
|
+
# Worst case, everything will be nil, and :template will just be
|
149
|
+
# the original string.
|
150
|
+
match = path_regex.match(_default_file_to_render)
|
151
|
+
|
152
|
+
render_options = {template: match[:template]}
|
153
|
+
render_options[:handlers] = [match[:handler]] if match[:handler]
|
154
|
+
render_options[:formats] = [match[:format].to_sym] if match[:format]
|
155
|
+
render_options[:locales] = [match[:locale]] if match[:locale]
|
156
|
+
render_options[:variants] = [match[:variant]] if match[:variant]
|
157
|
+
|
158
|
+
render_options
|
145
159
|
end
|
146
160
|
|
147
161
|
def _path_parts
|
@@ -171,10 +185,7 @@ module RSpec
|
|
171
185
|
|
172
186
|
before do
|
173
187
|
_include_controller_helpers
|
174
|
-
|
175
|
-
# rails 3.1
|
176
|
-
view.lookup_context.prefixes << _controller_path
|
177
|
-
end
|
188
|
+
view.lookup_context.prefixes << _controller_path
|
178
189
|
|
179
190
|
controller.controller_path = _controller_path
|
180
191
|
|
@@ -1,16 +1,11 @@
|
|
1
1
|
RSpec.configure do |rspec|
|
2
2
|
# Delay this in order to give users a chance to configure `expect_with`...
|
3
3
|
rspec.before(:suite) do
|
4
|
-
if defined?(RSpec::Matchers) &&
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
proxy_class = ActiveRecord::Associations.const_get(const_name)
|
12
|
-
|
13
|
-
RSpec::Matchers.configuration.add_should_and_should_not_to proxy_class
|
4
|
+
if defined?(RSpec::Matchers) &&
|
5
|
+
RSpec::Matchers.configuration.respond_to?(:syntax) && # RSpec 4 dropped support for monkey-patching `should` syntax
|
6
|
+
RSpec::Matchers.configuration.syntax.include?(:should) &&
|
7
|
+
defined?(ActiveRecord::Associations)
|
8
|
+
RSpec::Matchers.configuration.add_should_and_should_not_to ActiveRecord::Associations::CollectionProxy
|
14
9
|
end
|
15
10
|
end
|
16
11
|
end
|
@@ -1,23 +1,8 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Rails
|
3
3
|
# @private
|
4
|
-
# Disable some cops until https://github.com/bbatsov/rubocop/issues/1310
|
5
|
-
# rubocop:disable Style/IndentationConsistency
|
6
4
|
module FeatureCheck
|
7
|
-
|
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
|
-
|
5
|
+
module_function
|
21
6
|
def has_active_job?
|
22
7
|
defined?(::ActiveJob)
|
23
8
|
end
|
@@ -38,27 +23,25 @@ module RSpec
|
|
38
23
|
has_action_mailer? && defined?(::ActionMailer::Preview)
|
39
24
|
end
|
40
25
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
26
|
+
def has_action_cable_testing?
|
27
|
+
defined?(::ActionCable) && ActionCable::VERSION::MAJOR >= 6
|
28
|
+
end
|
29
|
+
|
30
|
+
def has_action_mailer_parameterized?
|
31
|
+
has_action_mailer? && defined?(::ActionMailer::Parameterized)
|
44
32
|
end
|
45
33
|
|
46
|
-
def
|
47
|
-
::
|
34
|
+
def has_action_mailer_unified_delivery?
|
35
|
+
has_action_mailer? && defined?(::ActionMailer::MailDeliveryJob)
|
48
36
|
end
|
49
37
|
|
50
|
-
def
|
51
|
-
::
|
38
|
+
def has_action_mailbox?
|
39
|
+
defined?(::ActionMailbox)
|
52
40
|
end
|
53
41
|
|
54
42
|
def type_metatag(type)
|
55
|
-
|
56
|
-
"type: :#{type}"
|
57
|
-
else
|
58
|
-
":type => :#{type}"
|
59
|
-
end
|
43
|
+
"type: :#{type}"
|
60
44
|
end
|
61
45
|
end
|
62
|
-
# rubocop:enable Style/IndentationConsistency
|
63
46
|
end
|
64
47
|
end
|
@@ -1,16 +1,14 @@
|
|
1
|
-
|
2
|
-
require 'active_support/testing/file_fixtures'
|
1
|
+
require 'active_support/testing/file_fixtures'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module RSpec
|
4
|
+
module Rails
|
5
|
+
# @private
|
6
|
+
module FileFixtureSupport
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include ActiveSupport::Testing::FileFixtures
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
10
|
+
included do
|
11
|
+
self.file_fixture_path = RSpec.configuration.file_fixture_path
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
@@ -2,37 +2,53 @@ module RSpec
|
|
2
2
|
module Rails
|
3
3
|
# @private
|
4
4
|
module FixtureFileUploadSupport
|
5
|
-
delegate :fixture_file_upload, :
|
5
|
+
delegate :fixture_file_upload, to: :rails_fixture_file_wrapper
|
6
6
|
|
7
7
|
private
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
# In Rails 6.2 fixture file path needs to be relative to `file_fixture_path` instead, this change
|
10
|
+
# was brought in with a deprecation warning on 6.1. In Rails 6.2 expect to rework this to remove
|
11
|
+
# the old accessor.
|
12
|
+
if ::Rails.version.to_f >= 6.1
|
13
|
+
def rails_fixture_file_wrapper
|
14
|
+
RailsFixtureFileWrapper.file_fixture_path = nil
|
15
|
+
resolved_fixture_path =
|
16
|
+
if respond_to?(:file_fixture_path) && !file_fixture_path.nil?
|
17
|
+
file_fixture_path.to_s
|
18
|
+
else
|
19
|
+
(RSpec.configuration.fixture_path || '').to_s
|
20
|
+
end
|
21
|
+
RailsFixtureFileWrapper.file_fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
|
22
|
+
RailsFixtureFileWrapper.instance
|
23
|
+
end
|
24
|
+
else
|
25
|
+
def rails_fixture_file_wrapper
|
26
|
+
RailsFixtureFileWrapper.fixture_path = nil
|
27
|
+
resolved_fixture_path =
|
28
|
+
if respond_to?(:fixture_path) && !fixture_path.nil?
|
29
|
+
fixture_path.to_s
|
30
|
+
else
|
31
|
+
(RSpec.configuration.fixture_path || '').to_s
|
32
|
+
end
|
33
|
+
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
|
34
|
+
RailsFixtureFileWrapper.instance
|
35
|
+
end
|
14
36
|
end
|
15
37
|
|
16
38
|
class RailsFixtureFileWrapper
|
17
39
|
include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)
|
18
40
|
|
41
|
+
if ::Rails.version.to_f >= 6.1
|
42
|
+
include ActiveSupport::Testing::FileFixtures
|
43
|
+
end
|
44
|
+
|
19
45
|
class << self
|
20
|
-
|
46
|
+
attr_accessor :fixture_path
|
21
47
|
|
22
48
|
# Get instance of wrapper
|
23
49
|
def instance
|
24
50
|
@instance ||= new
|
25
51
|
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
52
|
end
|
37
53
|
end
|
38
54
|
end
|
@@ -5,52 +5,54 @@ module RSpec
|
|
5
5
|
if defined?(ActiveRecord::TestFixtures)
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
include RSpec::Rails::SetupAndTeardownAdapter
|
8
|
-
include RSpec::Rails::MinitestLifecycleAdapter
|
8
|
+
include RSpec::Rails::MinitestLifecycleAdapter
|
9
9
|
include RSpec::Rails::MinitestAssertionAdapter
|
10
10
|
include ActiveRecord::TestFixtures
|
11
11
|
|
12
|
+
# @private prevent ActiveSupport::TestFixtures to start a DB transaction.
|
13
|
+
# Monkey patched to avoid collisions with 'let(:name)' in Rails 6.1 and after
|
14
|
+
# and let(:method_name) before Rails 6.1.
|
15
|
+
def run_in_transaction?
|
16
|
+
use_transactional_tests && !self.class.uses_transaction?(self)
|
17
|
+
end
|
18
|
+
|
12
19
|
included do
|
13
|
-
|
14
|
-
|
15
|
-
# fixed in rails by https://github.com/rails/rails/pull/1861, which
|
16
|
-
# should be part of the 3.1 release, at which point we can include
|
17
|
-
# these lines for rails < 3.1.
|
18
|
-
ActiveSupport::TestCase.class_exec do
|
19
|
-
include ActiveRecord::TestFixtures
|
20
|
-
self.fixture_path = RSpec.configuration.fixture_path
|
21
|
-
end
|
22
|
-
# /TODO
|
20
|
+
if RSpec.configuration.use_active_record?
|
21
|
+
include Fixtures
|
23
22
|
|
24
|
-
|
25
|
-
if ::Rails::VERSION::STRING > '5'
|
23
|
+
self.fixture_path = RSpec.configuration.fixture_path
|
26
24
|
self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
|
27
|
-
|
28
|
-
|
25
|
+
self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures
|
26
|
+
|
27
|
+
fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
|
29
28
|
end
|
30
|
-
|
29
|
+
end
|
30
|
+
|
31
|
+
module Fixtures
|
32
|
+
extend ActiveSupport::Concern
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
class_methods do
|
35
|
+
def fixtures(*args)
|
36
|
+
orig_methods = private_instance_methods
|
37
|
+
super.tap do
|
38
|
+
new_methods = private_instance_methods - orig_methods
|
39
|
+
new_methods.each do |method_name|
|
40
|
+
proxy_method_warning_if_called_in_before_context_scope(method_name)
|
41
|
+
end
|
38
42
|
end
|
39
43
|
end
|
40
|
-
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
def proxy_method_warning_if_called_in_before_context_scope(method_name)
|
46
|
+
orig_implementation = instance_method(method_name)
|
47
|
+
define_method(method_name) do |*args, &blk|
|
48
|
+
if inspect.include?("before(:context)")
|
49
|
+
RSpec.warn_with("Calling fixture method in before :context ")
|
50
|
+
else
|
51
|
+
orig_implementation.bind(self).call(*args, &blk)
|
52
|
+
end
|
49
53
|
end
|
50
54
|
end
|
51
55
|
end
|
52
|
-
|
53
|
-
fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|