rspec-rails 3.8.2 → 7.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/Capybara.md +5 -54
- data/Changelog.md +440 -76
- data/README.md +281 -500
- 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 +24 -7
- 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 +3 -3
- data/lib/generators/rspec/generator/generator_generator.rb +24 -0
- data/lib/generators/rspec/generator/templates/generator_spec.rb +5 -0
- data/lib/generators/rspec/helper/helper_generator.rb +2 -2
- data/lib/generators/rspec/install/install_generator.rb +23 -6
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +32 -17
- data/lib/generators/rspec/job/job_generator.rb +2 -1
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +1 -1
- 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 +7 -4
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +4 -4
- data/lib/generators/rspec/model/model_generator.rb +8 -7
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/request/request_generator.rb +10 -3
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +36 -22
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +13 -49
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +14 -62
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +9 -9
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +2 -6
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/generators/rspec/system/system_generator.rb +24 -0
- data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
- data/lib/generators/rspec/view/view_generator.rb +4 -4
- data/lib/generators/rspec.rb +16 -5
- data/lib/rspec/rails/adapters.rb +22 -76
- data/lib/rspec/rails/configuration.rb +112 -38
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +5 -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 +7 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/system_example_group.rb +88 -16
- data/lib/rspec/rails/example/view_example_group.rb +40 -28
- data/lib/rspec/rails/example.rb +2 -0
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
- data/lib/rspec/rails/feature_check.rb +16 -29
- data/lib/rspec/rails/file_fixture_support.rb +11 -10
- data/lib/rspec/rails/fixture_file_upload_support.rb +20 -15
- data/lib/rspec/rails/fixture_support.rb +64 -34
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +173 -0
- data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
- data/lib/rspec/rails/matchers/action_cable.rb +65 -0
- data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
- data/lib/rspec/rails/matchers/active_job.rb +224 -24
- data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
- data/lib/rspec/rails/matchers/be_valid.rb +1 -1
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +258 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +23 -32
- data/lib/rspec/rails/matchers/have_rendered.rb +2 -1
- data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +13 -13
- data/lib/rspec/rails/matchers/send_email.rb +122 -0
- data/lib/rspec/rails/matchers.rb +12 -0
- data/lib/rspec/rails/tasks/rspec.rake +9 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -17
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +0 -18
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +20 -7
- data/lib/rspec-rails.rb +36 -18
- data.tar.gz.sig +0 -0
- metadata +55 -37
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/integration/integration_generator.rb +0 -22
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
- /data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +0 -0
@@ -37,37 +37,17 @@ end
|
|
37
37
|
|
38
38
|
unless RSpec.respond_to?(:feature)
|
39
39
|
opts = {
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
Feature specs require the Capybara (
|
44
|
-
gem, version 2.
|
45
|
-
some deprecation warnings and have support for
|
46
|
-
`config.expose_dsl_globally = false`.
|
40
|
+
capybara_feature: true,
|
41
|
+
type: :feature,
|
42
|
+
skip: <<-EOT.squish
|
43
|
+
Feature specs require the Capybara (https://github.com/teamcapybara/capybara)
|
44
|
+
gem, version 2.13.0 or later.
|
47
45
|
EOT
|
48
46
|
}
|
49
47
|
|
50
|
-
# Capybara's monkey patching causes us to have to jump through some hoops
|
51
|
-
top_level = self
|
52
|
-
main_feature = nil
|
53
|
-
if defined?(Capybara) && ::Capybara::VERSION.to_f < 2.4
|
54
|
-
# Capybara 2.2 and 2.3 do not use `alias_example_xyz`
|
55
|
-
opts[:skip] = <<-EOT.squish
|
56
|
-
Capybara < 2.4.0 does not support RSpec's namespace or
|
57
|
-
`config.expose_dsl_globally = false`. Upgrade to Capybara >= 2.4.0.
|
58
|
-
EOT
|
59
|
-
main_feature = top_level.method(:feature) if top_level.respond_to?(:feature)
|
60
|
-
end
|
61
|
-
|
62
48
|
RSpec.configure do |c|
|
63
|
-
main_feature = nil unless c.expose_dsl_globally?
|
64
49
|
c.alias_example_group_to :feature, opts
|
65
50
|
c.alias_example_to :scenario
|
66
|
-
c.alias_example_to :xscenario, :
|
51
|
+
c.alias_example_to :xscenario, skip: 'Temporarily skipped with xscenario'
|
67
52
|
end
|
68
|
-
|
69
|
-
# Due to load order issues and `config.expose_dsl_globally?` defaulting to
|
70
|
-
# `true` we need to put Capybara's monkey patch method back. Otherwise,
|
71
|
-
# app upgrades have a high likelyhood of having all feature specs skipped.
|
72
|
-
top_level.define_singleton_method(:feature, &main_feature) if main_feature
|
73
53
|
end
|
@@ -12,15 +12,8 @@ module RSpec
|
|
12
12
|
|
13
13
|
# @private
|
14
14
|
module ClassMethods
|
15
|
-
|
16
|
-
|
17
|
-
described_class if yield(described_class)
|
18
|
-
end
|
19
|
-
else
|
20
|
-
def determine_default_helper_class(_ignore)
|
21
|
-
return unless Module === described_class && !(Class === described_class)
|
22
|
-
described_class
|
23
|
-
end
|
15
|
+
def determine_constant_from_test_name(_ignore)
|
16
|
+
described_class if yield(described_class)
|
24
17
|
end
|
25
18
|
end
|
26
19
|
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @api public
|
4
|
+
# Container module for mailbox spec functionality.
|
5
|
+
module MailboxExampleGroup
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
if RSpec::Rails::FeatureCheck.has_action_mailbox?
|
9
|
+
require 'action_mailbox/test_helper'
|
10
|
+
extend ::ActionMailbox::TestHelper
|
11
|
+
|
12
|
+
# @private
|
13
|
+
def self.create_inbound_email(arg)
|
14
|
+
case arg
|
15
|
+
when Hash
|
16
|
+
create_inbound_email_from_mail(**arg)
|
17
|
+
else
|
18
|
+
create_inbound_email_from_source(arg.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
else
|
22
|
+
def self.create_inbound_email(_arg)
|
23
|
+
raise "Could not load ActionMailer::TestHelper"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class_methods do
|
28
|
+
# @private
|
29
|
+
def mailbox_class
|
30
|
+
described_class
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
included do
|
35
|
+
subject { described_class }
|
36
|
+
end
|
37
|
+
|
38
|
+
# @api public
|
39
|
+
# Passes if the inbound email was delivered
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# inbound_email = process(args)
|
43
|
+
# expect(inbound_email).to have_been_delivered
|
44
|
+
def have_been_delivered
|
45
|
+
satisfy('have been delivered', &:delivered?)
|
46
|
+
end
|
47
|
+
|
48
|
+
# @api public
|
49
|
+
# Passes if the inbound email bounced during processing
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
# inbound_email = process(args)
|
53
|
+
# expect(inbound_email).to have_bounced
|
54
|
+
def have_bounced
|
55
|
+
satisfy('have bounced', &:bounced?)
|
56
|
+
end
|
57
|
+
|
58
|
+
# @api public
|
59
|
+
# Passes if the inbound email failed to process
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# inbound_email = process(args)
|
63
|
+
# expect(inbound_email).to have_failed
|
64
|
+
def have_failed
|
65
|
+
satisfy('have failed', &:failed?)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Process an inbound email message directly, bypassing routing.
|
69
|
+
#
|
70
|
+
# @param message [Hash, Mail::Message] a mail message or hash of
|
71
|
+
# attributes used to build one
|
72
|
+
# @return [ActionMailbox::InboundMessage]
|
73
|
+
def process(message)
|
74
|
+
MailboxExampleGroup.create_inbound_email(message).tap do |mail|
|
75
|
+
self.class.mailbox_class.receive(mail)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -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.
|
@@ -2,6 +2,9 @@
|
|
2
2
|
# suite and ammeter.
|
3
3
|
require 'rspec/rails/matchers'
|
4
4
|
|
5
|
+
require 'active_support/current_attributes/test_helper'
|
6
|
+
require 'active_support/execution_context/test_helper'
|
7
|
+
|
5
8
|
module RSpec
|
6
9
|
module Rails
|
7
10
|
# @api public
|
@@ -9,9 +12,12 @@ module RSpec
|
|
9
12
|
module RailsExampleGroup
|
10
13
|
extend ActiveSupport::Concern
|
11
14
|
include RSpec::Rails::SetupAndTeardownAdapter
|
12
|
-
include RSpec::Rails::MinitestLifecycleAdapter
|
15
|
+
include RSpec::Rails::MinitestLifecycleAdapter
|
13
16
|
include RSpec::Rails::MinitestAssertionAdapter
|
14
17
|
include RSpec::Rails::FixtureSupport
|
18
|
+
include RSpec::Rails::TaggedLoggingAdapter
|
19
|
+
include ActiveSupport::CurrentAttributes::TestHelper
|
20
|
+
include ActiveSupport::ExecutionContext::TestHelper
|
15
21
|
end
|
16
22
|
end
|
17
23
|
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,53 @@ 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)}"
|
45
|
+
end
|
46
|
+
|
47
|
+
if ::Rails::VERSION::STRING.to_f >= 7.1
|
48
|
+
# @private
|
49
|
+
# Allows failure screenshot to work whilst not exposing metadata
|
50
|
+
class SuppressRailsScreenshotMetadata
|
51
|
+
def initialize
|
52
|
+
@example_data = {}
|
53
|
+
end
|
54
|
+
|
55
|
+
def [](key)
|
56
|
+
if @example_data.key?(key)
|
57
|
+
@example_data[key]
|
58
|
+
else
|
59
|
+
raise_wrong_scope_error
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def []=(key, value)
|
64
|
+
if key == :failure_screenshot_path
|
65
|
+
@example_data[key] = value
|
66
|
+
else
|
67
|
+
raise_wrong_scope_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def method_missing(_name, *_args, &_block)
|
72
|
+
raise_wrong_scope_error
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def raise_wrong_scope_error
|
78
|
+
raise RSpec::Core::ExampleGroup::WrongScopeError,
|
79
|
+
"`metadata` is not available from within an example " \
|
80
|
+
"(e.g. an `it` block) or from constructs that run in the " \
|
81
|
+
"scope of an example (e.g. `before`, `let`, etc). It is " \
|
82
|
+
"only available on an example group (e.g. a `describe` or "\
|
83
|
+
"`context` block)"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# @private
|
88
|
+
def metadata
|
89
|
+
@metadata ||= SuppressRailsScreenshotMetadata.new
|
90
|
+
end
|
41
91
|
end
|
42
92
|
|
43
93
|
# Delegates to `Rails.application`.
|
@@ -45,29 +95,42 @@ module RSpec
|
|
45
95
|
::Rails.application
|
46
96
|
end
|
47
97
|
|
98
|
+
# Default driver to assign if none specified.
|
99
|
+
DEFAULT_DRIVER =
|
100
|
+
if ::Rails::VERSION::STRING.to_f >= 7.2
|
101
|
+
:selenium_chrome_headless
|
102
|
+
else
|
103
|
+
:selenium
|
104
|
+
end
|
105
|
+
|
48
106
|
included do |other|
|
107
|
+
ActiveSupport.on_load(:action_dispatch_system_test_case) do
|
108
|
+
ActionDispatch::SystemTesting::Server.silence_puma = true
|
109
|
+
end
|
110
|
+
|
111
|
+
require 'action_dispatch/system_test_case'
|
112
|
+
|
49
113
|
begin
|
50
114
|
require 'capybara'
|
51
|
-
require 'action_dispatch/system_test_case'
|
52
|
-
# rubocop:disable Lint/HandleExceptions
|
53
115
|
rescue LoadError => e
|
54
|
-
# rubocop:enable Lint/HandleExceptions
|
55
116
|
abort """
|
56
117
|
LoadError: #{e.message}
|
57
|
-
System test integration
|
118
|
+
System test integration has a hard
|
58
119
|
dependency on a webserver and `capybara`, please add capybara to
|
59
120
|
your Gemfile and configure a webserver (e.g. `Capybara.server =
|
60
|
-
:
|
121
|
+
:puma`) before attempting to use system specs.
|
61
122
|
""".gsub(/\s+/, ' ').strip
|
62
123
|
end
|
63
124
|
|
125
|
+
original_before_teardown =
|
126
|
+
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:before_teardown)
|
127
|
+
|
64
128
|
original_after_teardown =
|
65
129
|
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
|
66
130
|
|
67
|
-
other.include ActionDispatch::IntegrationTest::Behavior
|
68
131
|
other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
|
69
132
|
other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
|
70
|
-
other.include
|
133
|
+
other.include BlowAwayTeardownHooks
|
71
134
|
|
72
135
|
attr_reader :driver
|
73
136
|
|
@@ -78,16 +141,19 @@ module RSpec
|
|
78
141
|
def initialize(*args, &blk)
|
79
142
|
super(*args, &blk)
|
80
143
|
@driver = nil
|
144
|
+
|
145
|
+
self.class.before do
|
146
|
+
# A user may have already set the driver, so only default if driver
|
147
|
+
# is not set
|
148
|
+
driven_by(DEFAULT_DRIVER) unless @driver
|
149
|
+
end
|
81
150
|
end
|
82
151
|
|
83
|
-
def driven_by(
|
84
|
-
@driver = ::ActionDispatch::SystemTestCase.driven_by(
|
152
|
+
def driven_by(driver, **driver_options, &blk)
|
153
|
+
@driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
|
85
154
|
end
|
86
155
|
|
87
156
|
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
157
|
@routes = ::Rails.application.routes
|
92
158
|
end
|
93
159
|
|
@@ -95,13 +161,19 @@ module RSpec
|
|
95
161
|
orig_stdout = $stdout
|
96
162
|
$stdout = StringIO.new
|
97
163
|
begin
|
98
|
-
|
164
|
+
original_before_teardown.bind(self).call
|
99
165
|
ensure
|
100
166
|
myio = $stdout
|
101
|
-
|
167
|
+
myio.rewind
|
168
|
+
RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
|
102
169
|
$stdout = orig_stdout
|
103
170
|
end
|
104
171
|
end
|
172
|
+
|
173
|
+
around do |example|
|
174
|
+
example.run
|
175
|
+
original_after_teardown.bind(self).call
|
176
|
+
end
|
105
177
|
end
|
106
178
|
end
|
107
179
|
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,12 +59,13 @@ 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
|
69
66
|
def render(options = {}, local_assigns = {}, &block)
|
70
67
|
options = _default_render_options if Hash === options && options.empty?
|
68
|
+
options = options.merge(_default_render_options) if Hash === options && options.keys == [:locals]
|
71
69
|
super(options, local_assigns, &block)
|
72
70
|
end
|
73
71
|
|
@@ -92,7 +90,7 @@ module RSpec
|
|
92
90
|
#
|
93
91
|
# stub_template("widgets/_widget.html.erb" => "This content.")
|
94
92
|
def stub_template(hash)
|
95
|
-
|
93
|
+
controller.prepend_view_path(StubResolverCache.resolver_for(hash))
|
96
94
|
end
|
97
95
|
|
98
96
|
# Provides access to the params hash that will be available within the
|
@@ -105,7 +103,7 @@ module RSpec
|
|
105
103
|
|
106
104
|
# @deprecated Use `view` instead.
|
107
105
|
def template
|
108
|
-
RSpec.deprecate("template", :
|
106
|
+
RSpec.deprecate("template", replacement: "view")
|
109
107
|
view
|
110
108
|
end
|
111
109
|
|
@@ -128,20 +126,37 @@ module RSpec
|
|
128
126
|
private
|
129
127
|
|
130
128
|
def _default_render_options
|
131
|
-
if ::
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
129
|
+
formats = if ActionView::Template::Types.respond_to?(:symbols)
|
130
|
+
ActionView::Template::Types.symbols
|
131
|
+
else
|
132
|
+
[:html, :text, :js, :css, :xml, :json].map(&:to_s)
|
133
|
+
end.map { |x| Regexp.escape(x) }.join("|")
|
134
|
+
|
135
|
+
handlers = ActionView::Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|")
|
136
|
+
locales = "[a-z]{2}(?:-[A-Z]{2})?"
|
137
|
+
variants = "[^.]*"
|
138
|
+
path_regex = %r{
|
139
|
+
\A
|
140
|
+
(?<template>.*?)
|
141
|
+
(?:\.(?<locale>#{locales}))??
|
142
|
+
(?:\.(?<format>#{formats}))??
|
143
|
+
(?:\+(?<variant>#{variants}))??
|
144
|
+
(?:\.(?<handler>#{handlers}))?
|
145
|
+
\z
|
146
|
+
}x
|
147
|
+
|
148
|
+
# This regex should always find a match.
|
149
|
+
# Worst case, everything will be nil, and :template will just be
|
150
|
+
# the original string.
|
151
|
+
match = path_regex.match(_default_file_to_render)
|
152
|
+
|
153
|
+
render_options = { template: match[:template] }
|
154
|
+
render_options[:handlers] = [match[:handler].to_sym] if match[:handler]
|
155
|
+
render_options[:formats] = [match[:format].to_sym] if match[:format]
|
156
|
+
render_options[:locales] = [match[:locale].to_sym] if match[:locale]
|
157
|
+
render_options[:variants] = [match[:variant].to_sym] if match[:variant]
|
158
|
+
|
159
|
+
render_options
|
145
160
|
end
|
146
161
|
|
147
162
|
def _path_parts
|
@@ -171,10 +186,7 @@ module RSpec
|
|
171
186
|
|
172
187
|
before do
|
173
188
|
_include_controller_helpers
|
174
|
-
|
175
|
-
# rails 3.1
|
176
|
-
view.lookup_context.prefixes << _controller_path
|
177
|
-
end
|
189
|
+
view.lookup_context.prefixes << _controller_path
|
178
190
|
|
179
191
|
controller.controller_path = _controller_path
|
180
192
|
|
data/lib/rspec/rails/example.rb
CHANGED
@@ -9,3 +9,5 @@ require 'rspec/rails/example/model_example_group'
|
|
9
9
|
require 'rspec/rails/example/job_example_group'
|
10
10
|
require 'rspec/rails/example/feature_example_group'
|
11
11
|
require 'rspec/rails/example/system_example_group'
|
12
|
+
require 'rspec/rails/example/channel_example_group'
|
13
|
+
require 'rspec/rails/example/mailbox_example_group'
|
@@ -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,29 @@ 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)
|
28
|
+
end
|
29
|
+
|
30
|
+
def has_action_mailer_parameterized?
|
31
|
+
has_action_mailer? && defined?(::ActionMailer::Parameterized::DeliveryJob)
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_action_mailer_unified_delivery?
|
35
|
+
has_action_mailer? && defined?(::ActionMailer::MailDeliveryJob)
|
44
36
|
end
|
45
37
|
|
46
|
-
def
|
47
|
-
::
|
38
|
+
def has_action_mailer_legacy_delivery_job?
|
39
|
+
defined?(ActionMailer::DeliveryJob)
|
48
40
|
end
|
49
41
|
|
50
|
-
def
|
51
|
-
::
|
42
|
+
def has_action_mailbox?
|
43
|
+
defined?(::ActionMailbox)
|
52
44
|
end
|
53
45
|
|
54
46
|
def type_metatag(type)
|
55
|
-
|
56
|
-
"type: :#{type}"
|
57
|
-
else
|
58
|
-
":type => :#{type}"
|
59
|
-
end
|
47
|
+
"type: :#{type}"
|
60
48
|
end
|
61
49
|
end
|
62
|
-
# rubocop:enable Style/IndentationConsistency
|
63
50
|
end
|
64
51
|
end
|
@@ -1,15 +1,16 @@
|
|
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
|
-
|
10
|
+
included do
|
11
|
+
self.file_fixture_path = RSpec.configuration.file_fixture_path
|
12
|
+
if defined?(ActiveStorage::FixtureSet)
|
13
|
+
ActiveStorage::FixtureSet.file_fixture_path = RSpec.configuration.file_fixture_path
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
@@ -2,37 +2,42 @@ 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
|
+
# In Rails 7.0 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 7.0 expect to rework this to remove
|
11
|
+
# the old accessor.
|
9
12
|
def rails_fixture_file_wrapper
|
10
|
-
RailsFixtureFileWrapper.
|
11
|
-
resolved_fixture_path =
|
12
|
-
|
13
|
+
RailsFixtureFileWrapper.file_fixture_path = nil
|
14
|
+
resolved_fixture_path =
|
15
|
+
if respond_to?(:file_fixture_path) && !file_fixture_path.nil?
|
16
|
+
file_fixture_path.to_s
|
17
|
+
elsif respond_to?(:fixture_paths)
|
18
|
+
(RSpec.configuration.fixture_paths&.first || '').to_s
|
19
|
+
else
|
20
|
+
(RSpec.configuration.fixture_path || '').to_s
|
21
|
+
end
|
22
|
+
RailsFixtureFileWrapper.file_fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
|
13
23
|
RailsFixtureFileWrapper.instance
|
14
24
|
end
|
15
25
|
|
16
26
|
class RailsFixtureFileWrapper
|
17
27
|
include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)
|
28
|
+
include ActiveSupport::Testing::FileFixtures
|
18
29
|
|
19
30
|
class << self
|
20
|
-
|
31
|
+
if ::Rails::VERSION::STRING < "7.1.0"
|
32
|
+
attr_accessor :fixture_path
|
33
|
+
else
|
34
|
+
attr_accessor :fixture_paths
|
35
|
+
end
|
21
36
|
|
22
37
|
# Get instance of wrapper
|
23
38
|
def instance
|
24
39
|
@instance ||= new
|
25
40
|
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
41
|
end
|
37
42
|
end
|
38
43
|
end
|