rspec-rails 4.0.0.beta3 → 4.0.0
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 +70 -12
- data/README.md +4 -5
- data/lib/generators/rspec/controller/controller_generator.rb +13 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +14 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +1 -1
- 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/mailer/mailer_generator.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +4 -4
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +26 -18
- 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 +10 -10
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -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 +1 -1
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/generators/rspec.rb +0 -6
- data/lib/rspec/rails/adapters.rb +10 -76
- data/lib/rspec/rails/configuration.rb +35 -35
- data/lib/rspec/rails/example/channel_example_group.rb +2 -2
- 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 -10
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/system_example_group.rb +10 -4
- data/lib/rspec/rails/example/view_example_group.rb +38 -48
- data/lib/rspec/rails/extensions/active_record/proxy.rb +1 -9
- data/lib/rspec/rails/feature_check.rb +1 -28
- data/lib/rspec/rails/fixture_file_upload_support.rb +1 -1
- data/lib/rspec/rails/fixture_support.rb +37 -31
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +3 -3
- data/lib/rspec/rails/matchers/action_cable.rb +1 -1
- data/lib/rspec/rails/matchers/active_job.rb +126 -16
- data/lib/rspec/rails/matchers/base_matcher.rb +4 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +6 -3
- data/lib/rspec/rails/matchers/have_http_status.rb +7 -7
- data/lib/rspec/rails/matchers/routing_matchers.rb +11 -11
- 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 +3 -3
- data/lib/rspec-rails.rb +6 -9
- data.tar.gz.sig +0 -0
- metadata +30 -29
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
- data/lib/generators/rspec/observer/templates/observer_spec.rb +0 -7
data/lib/rspec/rails/adapters.rb
CHANGED
@@ -19,68 +19,15 @@ module RSpec
|
|
19
19
|
end
|
20
20
|
private_class_method :disable_testunit_autorun
|
21
21
|
|
22
|
-
if
|
23
|
-
|
24
|
-
gem 'minitest'
|
25
|
-
else
|
26
|
-
require 'minitest'
|
27
|
-
end
|
28
|
-
require 'minitest/assertions'
|
29
|
-
# Constant aliased to either Minitest or TestUnit, depending on what is
|
30
|
-
# loaded.
|
31
|
-
Assertions = Minitest::Assertions
|
32
|
-
elsif RUBY_VERSION >= '2.2.0'
|
33
|
-
# Minitest / TestUnit has been removed from ruby core. However, we are
|
34
|
-
# on an old Rails version and must load the appropriate gem
|
35
|
-
if ::Rails::VERSION::STRING >= '4.0.0'
|
36
|
-
# ActiveSupport 4.0.x has the minitest '~> 4.2' gem as a dependency
|
37
|
-
# This gem has no `lib/minitest.rb` file.
|
38
|
-
gem 'minitest' if defined?(Kernel.gem)
|
39
|
-
require 'minitest/unit'
|
40
|
-
Assertions = MiniTest::Assertions
|
41
|
-
elsif ::Rails::VERSION::STRING >= '3.2.21'
|
42
|
-
# TODO: Change the above check to >= '3.2.22' once it's released
|
43
|
-
begin
|
44
|
-
# Test::Unit "helpfully" sets up autoload for its `AutoRunner`.
|
45
|
-
# While we do not reference it directly, when we load the `TestCase`
|
46
|
-
# classes from AS (ActiveSupport), AS kindly references `AutoRunner`
|
47
|
-
# for everyone.
|
48
|
-
#
|
49
|
-
# To handle this we need to pre-emptively load 'test/unit' and make
|
50
|
-
# sure the version installed has `AutoRunner` (the 3.x line does to
|
51
|
-
# date). If so, we turn the auto runner off.
|
52
|
-
require 'test/unit'
|
53
|
-
require 'test/unit/assertions'
|
54
|
-
disable_testunit_autorun
|
55
|
-
rescue LoadError => e
|
56
|
-
raise LoadError, <<-ERR.squish, e.backtrace
|
57
|
-
Ruby 2.2+ has removed test/unit from the core library. Rails
|
58
|
-
requires this as a dependency. Please add test-unit gem to your
|
59
|
-
Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})"
|
60
|
-
ERR
|
61
|
-
end
|
62
|
-
Assertions = Test::Unit::Assertions
|
63
|
-
else
|
64
|
-
abort <<-MSG.squish
|
65
|
-
Ruby 2.2+ is not supported on Rails #{::Rails::VERSION::STRING}.
|
66
|
-
Check the Rails release notes for the appropriate update with
|
67
|
-
support.
|
68
|
-
MSG
|
69
|
-
end
|
22
|
+
if defined?(Kernel.gem)
|
23
|
+
gem 'minitest'
|
70
24
|
else
|
71
|
-
|
72
|
-
require 'test/unit/assertions'
|
73
|
-
rescue LoadError
|
74
|
-
# work around for Rubinius not having a std std-lib
|
75
|
-
require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
76
|
-
require 'test/unit/assertions'
|
77
|
-
end
|
78
|
-
# Turn off test unit's auto runner for those using the gem
|
79
|
-
disable_testunit_autorun
|
80
|
-
# Constant aliased to either Minitest or TestUnit, depending on what is
|
81
|
-
# loaded.
|
82
|
-
Assertions = Test::Unit::Assertions
|
25
|
+
require 'minitest'
|
83
26
|
end
|
27
|
+
require 'minitest/assertions'
|
28
|
+
# Constant aliased to either Minitest or TestUnit, depending on what is
|
29
|
+
# loaded.
|
30
|
+
Assertions = Minitest::Assertions
|
84
31
|
|
85
32
|
# @private
|
86
33
|
class AssertionDelegator < Module
|
@@ -199,12 +146,11 @@ module RSpec
|
|
199
146
|
# examples without exposing non-assertion methods in Test::Unit or
|
200
147
|
# Minitest.
|
201
148
|
def assertion_method_names
|
202
|
-
|
203
|
-
public_instance_methods
|
204
|
-
select do |m|
|
149
|
+
::RSpec::Rails::Assertions
|
150
|
+
.public_instance_methods
|
151
|
+
.select do |m|
|
205
152
|
m.to_s =~ /^(assert|flunk|refute)/
|
206
153
|
end
|
207
|
-
methods + test_unit_specific_methods
|
208
154
|
end
|
209
155
|
|
210
156
|
def define_assertion_delegators
|
@@ -214,18 +160,6 @@ module RSpec
|
|
214
160
|
end
|
215
161
|
end
|
216
162
|
end
|
217
|
-
|
218
|
-
# Starting on Rails 4, Minitest is the default testing framework so no
|
219
|
-
# need to add TestUnit specific methods.
|
220
|
-
if ::Rails::VERSION::STRING >= '4.0.0'
|
221
|
-
def test_unit_specific_methods
|
222
|
-
[]
|
223
|
-
end
|
224
|
-
else
|
225
|
-
def test_unit_specific_methods
|
226
|
-
[:build_message]
|
227
|
-
end
|
228
|
-
end
|
229
163
|
end
|
230
164
|
|
231
165
|
class AssertionDelegator
|
@@ -25,46 +25,46 @@ module RSpec
|
|
25
25
|
#
|
26
26
|
# @api private
|
27
27
|
DIRECTORY_MAPPINGS = {
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
28
|
+
channel: %w[spec channels],
|
29
|
+
controller: %w[spec controllers],
|
30
|
+
helper: %w[spec helpers],
|
31
|
+
job: %w[spec jobs],
|
32
|
+
mailer: %w[spec mailers],
|
33
|
+
model: %w[spec models],
|
34
|
+
request: %w[spec (requests|integration|api)],
|
35
|
+
routing: %w[spec routing],
|
36
|
+
view: %w[spec views],
|
37
|
+
feature: %w[spec features],
|
38
|
+
system: %w[spec system],
|
39
|
+
mailbox: %w[spec mailboxes]
|
40
40
|
}
|
41
41
|
|
42
42
|
# Sets up the different example group modules for the different spec types
|
43
43
|
#
|
44
44
|
# @api private
|
45
45
|
def self.add_test_type_configurations(config)
|
46
|
-
config.include RSpec::Rails::ControllerExampleGroup, :
|
47
|
-
config.include RSpec::Rails::HelperExampleGroup, :
|
48
|
-
config.include RSpec::Rails::ModelExampleGroup, :
|
49
|
-
config.include RSpec::Rails::RequestExampleGroup, :
|
50
|
-
config.include RSpec::Rails::RoutingExampleGroup, :
|
51
|
-
config.include RSpec::Rails::ViewExampleGroup, :
|
52
|
-
config.include RSpec::Rails::FeatureExampleGroup, :
|
46
|
+
config.include RSpec::Rails::ControllerExampleGroup, type: :controller
|
47
|
+
config.include RSpec::Rails::HelperExampleGroup, type: :helper
|
48
|
+
config.include RSpec::Rails::ModelExampleGroup, type: :model
|
49
|
+
config.include RSpec::Rails::RequestExampleGroup, type: :request
|
50
|
+
config.include RSpec::Rails::RoutingExampleGroup, type: :routing
|
51
|
+
config.include RSpec::Rails::ViewExampleGroup, type: :view
|
52
|
+
config.include RSpec::Rails::FeatureExampleGroup, type: :feature
|
53
53
|
config.include RSpec::Rails::Matchers
|
54
|
-
config.include RSpec::Rails::SystemExampleGroup, :
|
54
|
+
config.include RSpec::Rails::SystemExampleGroup, type: :system
|
55
55
|
end
|
56
56
|
|
57
57
|
# @private
|
58
|
-
# rubocop:disable Metrics/MethodLength
|
59
|
-
def self.initialize_configuration(config)
|
58
|
+
def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength
|
60
59
|
config.backtrace_exclusion_patterns << /vendor\//
|
61
60
|
config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
|
62
61
|
|
63
62
|
# controller settings
|
64
|
-
config.add_setting :infer_base_class_for_anonymous_controllers, :
|
63
|
+
config.add_setting :infer_base_class_for_anonymous_controllers, default: true
|
65
64
|
|
66
65
|
# fixture support
|
67
|
-
config.add_setting :
|
66
|
+
config.add_setting :use_active_record, default: true
|
67
|
+
config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples
|
68
68
|
config.add_setting :use_instantiated_fixtures
|
69
69
|
config.add_setting :global_fixtures
|
70
70
|
config.add_setting :fixture_path
|
@@ -80,7 +80,7 @@ module RSpec
|
|
80
80
|
config.include RSpec::Rails::FixtureSupport
|
81
81
|
|
82
82
|
if ::Rails::VERSION::STRING > '5'
|
83
|
-
config.add_setting :file_fixture_path, :
|
83
|
+
config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
|
84
84
|
config.include RSpec::Rails::FileFixtureSupport
|
85
85
|
end
|
86
86
|
|
@@ -93,7 +93,7 @@ module RSpec
|
|
93
93
|
# as a getter. This makes it easier for rspec-rails users because we use
|
94
94
|
# `render_views` directly in example groups, so this aligns the two APIs,
|
95
95
|
# but requires this workaround:
|
96
|
-
config.add_setting :rendering_views, :
|
96
|
+
config.add_setting :rendering_views, default: false
|
97
97
|
|
98
98
|
config.instance_exec do
|
99
99
|
def render_views=(val)
|
@@ -111,7 +111,7 @@ module RSpec
|
|
111
111
|
def infer_spec_type_from_file_location!
|
112
112
|
DIRECTORY_MAPPINGS.each do |type, dir_parts|
|
113
113
|
escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
|
114
|
-
define_derived_metadata(:
|
114
|
+
define_derived_metadata(file_path: escaped_path) do |metadata|
|
115
115
|
metadata[:type] ||= type
|
116
116
|
end
|
117
117
|
end
|
@@ -129,29 +129,29 @@ module RSpec
|
|
129
129
|
|
130
130
|
if defined?(::Rails::Controller::Testing)
|
131
131
|
[:controller, :view, :request].each do |type|
|
132
|
-
config.include ::Rails::Controller::Testing::TestProcess, :
|
133
|
-
config.include ::Rails::Controller::Testing::TemplateAssertions, :
|
134
|
-
config.include ::Rails::Controller::Testing::Integration, :
|
132
|
+
config.include ::Rails::Controller::Testing::TestProcess, type: type
|
133
|
+
config.include ::Rails::Controller::Testing::TemplateAssertions, type: type
|
134
|
+
config.include ::Rails::Controller::Testing::Integration, type: type
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
138
|
if RSpec::Rails::FeatureCheck.has_action_mailer?
|
139
|
-
config.include RSpec::Rails::MailerExampleGroup, :
|
139
|
+
config.include RSpec::Rails::MailerExampleGroup, type: :mailer
|
140
|
+
config.after { ActionMailer::Base.deliveries.clear }
|
140
141
|
end
|
141
142
|
|
142
143
|
if RSpec::Rails::FeatureCheck.has_active_job?
|
143
|
-
config.include RSpec::Rails::JobExampleGroup, :
|
144
|
+
config.include RSpec::Rails::JobExampleGroup, type: :job
|
144
145
|
end
|
145
146
|
|
146
147
|
if RSpec::Rails::FeatureCheck.has_action_cable_testing?
|
147
|
-
config.include RSpec::Rails::ChannelExampleGroup, :
|
148
|
+
config.include RSpec::Rails::ChannelExampleGroup, type: :channel
|
148
149
|
end
|
149
150
|
|
150
151
|
if RSpec::Rails::FeatureCheck.has_action_mailbox?
|
151
|
-
config.include RSpec::Rails::MailboxExampleGroup, :
|
152
|
+
config.include RSpec::Rails::MailboxExampleGroup, type: :mailbox
|
152
153
|
end
|
153
154
|
end
|
154
|
-
# rubocop:enable Metrics/MethodLength
|
155
155
|
|
156
156
|
initialize_configuration RSpec.configuration
|
157
157
|
end
|
@@ -34,7 +34,7 @@ if RSpec::Rails::FeatureCheck.has_action_cable_testing?
|
|
34
34
|
next if klass <= ::ActionCable::Channel::Base
|
35
35
|
|
36
36
|
raise "Described class is not a channel class.\n" \
|
37
|
-
"Specify the channel class in the `describe` statement "\
|
37
|
+
"Specify the channel class in the `describe` statement " \
|
38
38
|
"or set it manually using `tests MyChannelClass`"
|
39
39
|
end
|
40
40
|
end
|
@@ -45,7 +45,7 @@ if RSpec::Rails::FeatureCheck.has_action_cable_testing?
|
|
45
45
|
next if klass <= ::ActionCable::Connection::Base
|
46
46
|
|
47
47
|
raise "Described class is not a connection class.\n" \
|
48
|
-
"Specify the connection class in the `describe` statement "\
|
48
|
+
"Specify the connection class in the `describe` statement " \
|
49
49
|
"or set it manually using `tests MyConnectionClass`"
|
50
50
|
end
|
51
51
|
end
|
@@ -94,9 +94,9 @@ module RSpec
|
|
94
94
|
self.routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
|
95
95
|
r.draw do
|
96
96
|
resources resource_name,
|
97
|
-
:
|
98
|
-
:
|
99
|
-
:
|
97
|
+
as: resource_as,
|
98
|
+
module: resource_module,
|
99
|
+
path: resource_path
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -159,7 +159,7 @@ module RSpec
|
|
159
159
|
#
|
160
160
|
# expect do
|
161
161
|
# bypass_rescue
|
162
|
-
# get :show, :
|
162
|
+
# get :show, id: profile.id + 1
|
163
163
|
# end.to raise_error(/403 Forbidden/)
|
164
164
|
# end
|
165
165
|
# end
|
@@ -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 (https://github.com/
|
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,16 +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
|
-
|
23
|
-
described_class
|
24
|
-
end
|
15
|
+
def determine_constant_from_test_name(_ignore)
|
16
|
+
described_class if yield(described_class)
|
25
17
|
end
|
26
18
|
end
|
27
19
|
|
@@ -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
|
@@ -50,6 +50,10 @@ module RSpec
|
|
50
50
|
end
|
51
51
|
|
52
52
|
included do |other|
|
53
|
+
ActiveSupport.on_load(:action_dispatch_system_test_case) do
|
54
|
+
ActionDispatch::SystemTesting::Server.silence_puma = true
|
55
|
+
end
|
56
|
+
|
53
57
|
begin
|
54
58
|
require 'capybara'
|
55
59
|
require 'action_dispatch/system_test_case'
|
@@ -71,7 +75,6 @@ module RSpec
|
|
71
75
|
original_after_teardown =
|
72
76
|
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
|
73
77
|
|
74
|
-
other.include ActionDispatch::IntegrationTest::Behavior
|
75
78
|
other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
|
76
79
|
other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
|
77
80
|
other.include BlowAwayTeardownHooks
|
@@ -85,6 +88,12 @@ module RSpec
|
|
85
88
|
def initialize(*args, &blk)
|
86
89
|
super(*args, &blk)
|
87
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
|
88
97
|
end
|
89
98
|
|
90
99
|
def driven_by(*args, &blk)
|
@@ -92,9 +101,6 @@ module RSpec
|
|
92
101
|
end
|
93
102
|
|
94
103
|
before do
|
95
|
-
# A user may have already set the driver, so only default if driver
|
96
|
-
# is not set
|
97
|
-
driven_by(:selenium) unless @driver
|
98
104
|
@routes = ::Rails.application.routes
|
99
105
|
end
|
100
106
|
|
@@ -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,41 +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
|
-
(?:\.(?<
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
render_options
|
163
|
-
else
|
164
|
-
{ :template => _default_file_to_render }
|
165
|
-
end
|
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
|
166
159
|
end
|
167
160
|
|
168
161
|
def _path_parts
|
@@ -192,10 +185,7 @@ module RSpec
|
|
192
185
|
|
193
186
|
before do
|
194
187
|
_include_controller_helpers
|
195
|
-
|
196
|
-
# rails 3.1
|
197
|
-
view.lookup_context.prefixes << _controller_path
|
198
|
-
end
|
188
|
+
view.lookup_context.prefixes << _controller_path
|
199
189
|
|
200
190
|
controller.controller_path = _controller_path
|
201
191
|
|
@@ -2,15 +2,7 @@ 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
4
|
if defined?(RSpec::Matchers) && RSpec::Matchers.configuration.syntax.include?(:should) && defined?(ActiveRecord::Associations)
|
5
|
-
|
6
|
-
# In 3.1+, it's CollectionProxy.
|
7
|
-
const_name = [:CollectionProxy, :AssociationProxy].find do |const|
|
8
|
-
ActiveRecord::Associations.const_defined?(const)
|
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
|
5
|
+
RSpec::Matchers.configuration.add_should_and_should_not_to ActiveRecord::Associations::CollectionProxy
|
14
6
|
end
|
15
7
|
end
|
16
8
|
end
|
@@ -3,16 +3,6 @@ module RSpec
|
|
3
3
|
# @private
|
4
4
|
module FeatureCheck
|
5
5
|
module_function
|
6
|
-
def can_check_pending_migrations?
|
7
|
-
has_active_record_migration? &&
|
8
|
-
::ActiveRecord::Migration.respond_to?(:check_pending!)
|
9
|
-
end
|
10
|
-
|
11
|
-
def can_maintain_test_schema?
|
12
|
-
has_active_record_migration? &&
|
13
|
-
::ActiveRecord::Migration.respond_to?(:maintain_test_schema!)
|
14
|
-
end
|
15
|
-
|
16
6
|
def has_active_job?
|
17
7
|
defined?(::ActiveJob)
|
18
8
|
end
|
@@ -37,11 +27,6 @@ module RSpec
|
|
37
27
|
defined?(::ActionCable) && ActionCable::VERSION::MAJOR >= 6
|
38
28
|
end
|
39
29
|
|
40
|
-
def has_action_mailer_show_preview?
|
41
|
-
has_action_mailer_preview? &&
|
42
|
-
::ActionMailer::Base.respond_to?(:show_previews=)
|
43
|
-
end
|
44
|
-
|
45
30
|
def has_action_mailer_parameterized?
|
46
31
|
has_action_mailer? && defined?(::ActionMailer::Parameterized)
|
47
32
|
end
|
@@ -54,20 +39,8 @@ module RSpec
|
|
54
39
|
defined?(::ActionMailbox)
|
55
40
|
end
|
56
41
|
|
57
|
-
def has_1_9_hash_syntax?
|
58
|
-
::Rails::VERSION::STRING > '4.0'
|
59
|
-
end
|
60
|
-
|
61
|
-
def has_file_fixture?
|
62
|
-
::Rails::VERSION::STRING > '5.0'
|
63
|
-
end
|
64
|
-
|
65
42
|
def type_metatag(type)
|
66
|
-
|
67
|
-
"type: :#{type}"
|
68
|
-
else
|
69
|
-
":type => :#{type}"
|
70
|
-
end
|
43
|
+
"type: :#{type}"
|
71
44
|
end
|
72
45
|
end
|
73
46
|
end
|