rspec-rails 3.6.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/Capybara.md +5 -54
  4. data/Changelog.md +391 -68
  5. data/README.md +280 -527
  6. data/lib/generators/rspec/channel/channel_generator.rb +12 -0
  7. data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
  8. data/lib/generators/rspec/controller/controller_generator.rb +24 -7
  9. data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
  10. data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
  11. data/lib/generators/rspec/feature/feature_generator.rb +5 -5
  12. data/lib/generators/rspec/generator/generator_generator.rb +24 -0
  13. data/lib/generators/rspec/generator/templates/generator_spec.rb +6 -0
  14. data/lib/generators/rspec/helper/helper_generator.rb +2 -2
  15. data/lib/generators/rspec/install/install_generator.rb +23 -6
  16. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +25 -13
  17. data/lib/generators/rspec/integration/integration_generator.rb +13 -6
  18. data/lib/generators/rspec/job/job_generator.rb +2 -1
  19. data/lib/generators/rspec/job/templates/job_spec.rb.erb +1 -1
  20. data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
  21. data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  22. data/lib/generators/rspec/mailer/mailer_generator.rb +5 -4
  23. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
  24. data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
  25. data/lib/generators/rspec/model/model_generator.rb +8 -7
  26. data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
  27. data/lib/generators/rspec/request/request_generator.rb +10 -3
  28. data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +1 -1
  29. data/lib/generators/rspec/scaffold/scaffold_generator.rb +50 -26
  30. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +15 -51
  31. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  32. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +32 -65
  33. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +9 -9
  34. data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -2
  35. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
  36. data/lib/generators/rspec/scaffold/templates/request_spec.rb +153 -0
  37. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +10 -13
  38. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  39. data/lib/generators/rspec/system/system_generator.rb +24 -0
  40. data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  41. data/lib/generators/rspec/view/view_generator.rb +4 -4
  42. data/lib/generators/rspec.rb +16 -5
  43. data/lib/rspec/rails/active_record.rb +1 -1
  44. data/lib/rspec/rails/adapters.rb +21 -76
  45. data/lib/rspec/rails/configuration.rb +86 -35
  46. data/lib/rspec/rails/example/channel_example_group.rb +93 -0
  47. data/lib/rspec/rails/example/controller_example_group.rb +5 -4
  48. data/lib/rspec/rails/example/feature_example_group.rb +6 -26
  49. data/lib/rspec/rails/example/helper_example_group.rb +2 -9
  50. data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  51. data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
  52. data/lib/rspec/rails/example/rails_example_group.rb +2 -1
  53. data/lib/rspec/rails/example/request_example_group.rb +1 -4
  54. data/lib/rspec/rails/example/system_example_group.rb +126 -0
  55. data/lib/rspec/rails/example/view_example_group.rb +47 -28
  56. data/lib/rspec/rails/example.rb +3 -0
  57. data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
  58. data/lib/rspec/rails/feature_check.rb +16 -29
  59. data/lib/rspec/rails/file_fixture_support.rb +9 -11
  60. data/lib/rspec/rails/fixture_file_upload_support.rb +39 -0
  61. data/lib/rspec/rails/fixture_support.rb +35 -32
  62. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
  63. data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  64. data/lib/rspec/rails/matchers/action_cable.rb +65 -0
  65. data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  66. data/lib/rspec/rails/matchers/active_job.rb +209 -25
  67. data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  68. data/lib/rspec/rails/matchers/be_a_new.rb +6 -5
  69. data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
  70. data/lib/rspec/rails/matchers/be_valid.rb +1 -1
  71. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +227 -0
  72. data/lib/rspec/rails/matchers/have_http_status.rb +39 -18
  73. data/lib/rspec/rails/matchers/have_rendered.rb +2 -1
  74. data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
  75. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  76. data/lib/rspec/rails/matchers/routing_matchers.rb +13 -13
  77. data/lib/rspec/rails/matchers.rb +11 -0
  78. data/lib/rspec/rails/tasks/rspec.rake +7 -17
  79. data/lib/rspec/rails/vendor/capybara.rb +10 -13
  80. data/lib/rspec/rails/version.rb +1 -1
  81. data/lib/rspec/rails/view_assigns.rb +0 -18
  82. data/lib/rspec/rails/view_path_builder.rb +2 -2
  83. data/lib/rspec/rails/view_rendering.rb +10 -17
  84. data/lib/rspec/rails.rb +1 -0
  85. data/lib/rspec-rails.rb +10 -13
  86. data.tar.gz.sig +0 -0
  87. metadata +58 -35
  88. metadata.gz.sig +0 -0
  89. data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -0,0 +1,93 @@
1
+ require "rspec/rails/matchers/action_cable/have_streams"
2
+
3
+ module RSpec
4
+ module Rails
5
+ # @api public
6
+ # Container module for channel spec functionality. It is only available if
7
+ # ActionCable has been loaded before it.
8
+ module ChannelExampleGroup
9
+ # @private
10
+ module ClassMethods
11
+ # These blank modules are only necessary for YARD processing. It doesn't
12
+ # handle the conditional check below very well and reports undocumented objects.
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ if RSpec::Rails::FeatureCheck.has_action_cable_testing?
19
+ module RSpec
20
+ module Rails
21
+ # @api public
22
+ # Container module for channel spec functionality.
23
+ module ChannelExampleGroup
24
+ extend ActiveSupport::Concern
25
+ include RSpec::Rails::RailsExampleGroup
26
+ include ActionCable::Connection::TestCase::Behavior
27
+ include ActionCable::Channel::TestCase::Behavior
28
+
29
+ # Class-level DSL for channel specs.
30
+ module ClassMethods
31
+ # @private
32
+ def channel_class
33
+ (_channel_class || described_class).tap do |klass|
34
+ next if klass <= ::ActionCable::Channel::Base
35
+
36
+ raise "Described class is not a channel class.\n" \
37
+ "Specify the channel class in the `describe` statement " \
38
+ "or set it manually using `tests MyChannelClass`"
39
+ end
40
+ end
41
+
42
+ # @private
43
+ def connection_class
44
+ (_connection_class || described_class).tap do |klass|
45
+ next if klass <= ::ActionCable::Connection::Base
46
+
47
+ raise "Described class is not a connection class.\n" \
48
+ "Specify the connection class in the `describe` statement " \
49
+ "or set it manually using `tests MyConnectionClass`"
50
+ end
51
+ end
52
+ end
53
+
54
+ # Checks that the connection attempt has been rejected.
55
+ #
56
+ # @example
57
+ # expect { connect }.to have_rejected_connection
58
+ def have_rejected_connection
59
+ raise_error(::ActionCable::Connection::Authorization::UnauthorizedError)
60
+ end
61
+
62
+ # Checks that the subscription is subscribed to at least one stream.
63
+ #
64
+ # @example
65
+ # expect(subscription).to have_streams
66
+ def have_streams
67
+ check_subscribed!
68
+
69
+ RSpec::Rails::Matchers::ActionCable::HaveStream.new
70
+ end
71
+
72
+ # Checks that the channel has been subscribed to the given stream
73
+ #
74
+ # @example
75
+ # expect(subscription).to have_stream_from("chat_1")
76
+ def have_stream_from(stream)
77
+ check_subscribed!
78
+
79
+ RSpec::Rails::Matchers::ActionCable::HaveStream.new(stream)
80
+ end
81
+
82
+ # Checks that the channel has been subscribed to a stream for the given model
83
+ #
84
+ # @example
85
+ # expect(subscription).to have_stream_for(user)
86
+ def have_stream_for(object)
87
+ check_subscribed!
88
+ RSpec::Rails::Matchers::ActionCable::HaveStream.new(broadcasting_for(object))
89
+ end
90
+ end
91
+ end
92
+ end
93
+ 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
- :as => resource_as,
98
- :module => resource_module,
99
- :path => resource_path
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, :id => profile.id + 1
162
+ # get :show, id: profile.id + 1
163
163
  # end.to raise_error(/403 Forbidden/)
164
164
  # end
165
165
  # end
@@ -176,6 +176,7 @@ module RSpec
176
176
  super
177
177
  end
178
178
  end
179
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
179
180
 
180
181
  included do
181
182
  subject { controller }
@@ -37,37 +37,17 @@ end
37
37
 
38
38
  unless RSpec.respond_to?(:feature)
39
39
  opts = {
40
- :capybara_feature => true,
41
- :type => :feature,
42
- :skip => <<-EOT.squish
43
- Feature specs require the Capybara (http://github.com/jnicklas/capybara)
44
- gem, version 2.2.0 or later. We recommend version 2.4.0 or later to avoid
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, :skip => 'Temporarily skipped with 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
- if ::Rails::VERSION::MAJOR > 3
16
- def determine_constant_from_test_name(_ignore)
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 [ActionMaibox::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 } if options
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,9 +9,10 @@ module RSpec
9
9
  module RailsExampleGroup
10
10
  extend ActiveSupport::Concern
11
11
  include RSpec::Rails::SetupAndTeardownAdapter
12
- include RSpec::Rails::MinitestLifecycleAdapter if ::Rails::VERSION::STRING >= '4'
12
+ include RSpec::Rails::MinitestLifecycleAdapter
13
13
  include RSpec::Rails::MinitestAssertionAdapter
14
14
  include RSpec::Rails::FixtureSupport
15
+ include RSpec::Rails::TaggedLoggingAdapter if ::Rails::VERSION::MAJOR >= 7
15
16
  end
16
17
  end
17
18
  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
@@ -0,0 +1,126 @@
1
+ module RSpec
2
+ module Rails
3
+ # @api public
4
+ # Container class for system tests
5
+ module SystemExampleGroup
6
+ extend ActiveSupport::Concern
7
+ include RSpec::Rails::RailsExampleGroup
8
+ include RSpec::Rails::Matchers::RedirectTo
9
+ include RSpec::Rails::Matchers::RenderTemplate
10
+ include ActionDispatch::Integration::Runner
11
+ include ActionDispatch::Assertions
12
+ include ActionController::TemplateAssertions
13
+
14
+ # Special characters to translate into underscores for #method_name
15
+ CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze
16
+
17
+ # @private
18
+ module BlowAwayTeardownHooks
19
+ # @private
20
+ def before_teardown
21
+ end
22
+
23
+ # @private
24
+ def after_teardown
25
+ end
26
+ end
27
+
28
+ # for the SystemTesting Screenshot situation
29
+ def passed?
30
+ return false if RSpec.current_example.exception
31
+ return true unless defined?(::RSpec::Expectations::FailureAggregator)
32
+
33
+ failure_notifier = ::RSpec::Support.failure_notifier
34
+ return true unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
35
+
36
+ failure_notifier.failures.empty? && failure_notifier.other_errors.empty?
37
+ end
38
+
39
+ # @private
40
+ def method_name
41
+ @method_name ||= [
42
+ self.class.name.underscore,
43
+ RSpec.current_example.description.underscore
44
+ ].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
45
+ end
46
+
47
+ # Delegates to `Rails.application`.
48
+ def app
49
+ ::Rails.application
50
+ end
51
+
52
+ included do |other|
53
+ ActiveSupport.on_load(:action_dispatch_system_test_case) do
54
+ ActionDispatch::SystemTesting::Server.silence_puma = true
55
+ end
56
+
57
+ require 'action_dispatch/system_test_case'
58
+
59
+ begin
60
+ require 'capybara'
61
+ rescue LoadError => e
62
+ abort """
63
+ LoadError: #{e.message}
64
+ System test integration has a hard
65
+ dependency on a webserver and `capybara`, please add capybara to
66
+ your Gemfile and configure a webserver (e.g. `Capybara.server =
67
+ :puma`) before attempting to use system specs.
68
+ """.gsub(/\s+/, ' ').strip
69
+ end
70
+
71
+ original_before_teardown =
72
+ ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:before_teardown)
73
+
74
+ original_after_teardown =
75
+ ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
76
+
77
+ other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
78
+ other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
79
+ other.include BlowAwayTeardownHooks
80
+
81
+ attr_reader :driver
82
+
83
+ if ActionDispatch::SystemTesting::Server.respond_to?(:silence_puma=)
84
+ ActionDispatch::SystemTesting::Server.silence_puma = true
85
+ end
86
+
87
+ def initialize(*args, &blk)
88
+ super(*args, &blk)
89
+ @driver = nil
90
+
91
+ self.class.before do
92
+ # A user may have already set the driver, so only default if driver
93
+ # is not set
94
+ driven_by(:selenium) unless @driver
95
+ end
96
+ end
97
+
98
+ def driven_by(driver, **driver_options, &blk)
99
+ @driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
100
+ end
101
+
102
+ before do
103
+ @routes = ::Rails.application.routes
104
+ end
105
+
106
+ after do
107
+ orig_stdout = $stdout
108
+ $stdout = StringIO.new
109
+ begin
110
+ original_before_teardown.bind(self).call
111
+ ensure
112
+ myio = $stdout
113
+ myio.rewind
114
+ RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
115
+ $stdout = orig_stdout
116
+ end
117
+ end
118
+
119
+ around do |example|
120
+ example.run
121
+ original_after_teardown.bind(self).call
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -13,6 +13,14 @@ module RSpec
13
13
  include RSpec::Rails::ViewAssigns
14
14
  include RSpec::Rails::Matchers::RenderTemplate
15
15
 
16
+ # @private
17
+ module StubResolverCache
18
+ def self.resolver_for(hash)
19
+ @resolvers ||= {}
20
+ @resolvers[hash] ||= ActionView::FixtureResolver.new(hash)
21
+ end
22
+ end
23
+
16
24
  # @private
17
25
  module ClassMethods
18
26
  def _default_helper
@@ -35,16 +43,13 @@ module RSpec
35
43
 
36
44
  included do
37
45
  include ::Rails.application.routes.url_helpers
38
-
39
- if ::Rails.application.routes.respond_to?(:mounted_helpers)
40
- include ::Rails.application.routes.mounted_helpers
41
- end
46
+ include ::Rails.application.routes.mounted_helpers
42
47
  end
43
48
 
44
49
  # @overload render
45
- # @overload render({:partial => path_to_file})
46
- # @overload render({:partial => path_to_file}, {... locals ...})
47
- # @overload render({:partial => path_to_file}, {... locals ...}) do ... end
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
48
53
  #
49
54
  # Delegates to ActionView::Base#render, so see documentation on that
50
55
  # for more info.
@@ -54,7 +59,7 @@ module RSpec
54
59
  #
55
60
  # describe "widgets/new.html.erb" do
56
61
  # it "shows all the widgets" do
57
- # render # => view.render(:file => "widgets/new.html.erb")
62
+ # render # => view.render(file: "widgets/new.html.erb")
58
63
  # # ...
59
64
  # end
60
65
  # end
@@ -84,7 +89,7 @@ module RSpec
84
89
  #
85
90
  # stub_template("widgets/_widget.html.erb" => "This content.")
86
91
  def stub_template(hash)
87
- view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
92
+ view.view_paths.unshift(StubResolverCache.resolver_for(hash))
88
93
  end
89
94
 
90
95
  # Provides access to the params hash that will be available within the
@@ -97,7 +102,7 @@ module RSpec
97
102
 
98
103
  # @deprecated Use `view` instead.
99
104
  def template
100
- RSpec.deprecate("template", :replacement => "view")
105
+ RSpec.deprecate("template", replacement: "view")
101
106
  view
102
107
  end
103
108
 
@@ -120,20 +125,37 @@ module RSpec
120
125
  private
121
126
 
122
127
  def _default_render_options
123
- if ::Rails::VERSION::STRING >= '3.2'
124
- # pluck the handler, format, and locale out of, eg, posts/index.de.html.haml
125
- template, *components = _default_file_to_render.split('.')
126
- handler, format, locale = *components.reverse
127
-
128
- render_options = { :template => template }
129
- render_options[:handlers] = [handler] if handler
130
- render_options[:formats] = [format.to_sym] if format
131
- render_options[:locales] = [locale] if locale
132
-
133
- render_options
134
- else
135
- { :template => _default_file_to_render }
136
- 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].to_sym] if match[:handler]
154
+ render_options[:formats] = [match[:format].to_sym] if match[:format]
155
+ render_options[:locales] = [match[:locale].to_sym] if match[:locale]
156
+ render_options[:variants] = [match[:variant].to_sym] if match[:variant]
157
+
158
+ render_options
137
159
  end
138
160
 
139
161
  def _path_parts
@@ -163,10 +185,7 @@ module RSpec
163
185
 
164
186
  before do
165
187
  _include_controller_helpers
166
- if view.lookup_context.respond_to?(:prefixes)
167
- # rails 3.1
168
- view.lookup_context.prefixes << _controller_path
169
- end
188
+ view.lookup_context.prefixes << _controller_path
170
189
 
171
190
  controller.controller_path = _controller_path
172
191
 
@@ -8,3 +8,6 @@ require 'rspec/rails/example/routing_example_group'
8
8
  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
+ 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) && RSpec::Matchers.configuration.syntax.include?(:should) && defined?(ActiveRecord::Associations)
5
- # In Rails 3.0, it was AssociationProxy.
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
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
- # 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
-
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 has_action_mailer_show_preview?
42
- has_action_mailer_preview? &&
43
- ::ActionMailer::Base.respond_to?(:show_previews=)
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 has_1_9_hash_syntax?
47
- ::Rails::VERSION::STRING > '4.0'
38
+ def has_action_mailer_legacy_delivery_job?
39
+ defined?(ActionMailer::DeliveryJob)
48
40
  end
49
41
 
50
- def has_file_fixture?
51
- ::Rails::VERSION::STRING > '5.0'
42
+ def has_action_mailbox?
43
+ defined?(::ActionMailbox)
52
44
  end
53
45
 
54
46
  def type_metatag(type)
55
- if has_1_9_hash_syntax?
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,16 +1,14 @@
1
- if ::Rails::VERSION::STRING > '5'
2
- require 'active_support/testing/file_fixtures'
1
+ require 'active_support/testing/file_fixtures'
3
2
 
4
- module RSpec
5
- module Rails
6
- # @private
7
- module FileFixtureSupport
8
- extend ActiveSupport::Concern
9
- include ActiveSupport::Testing::FileFixtures
3
+ module RSpec
4
+ module Rails
5
+ # @private
6
+ module FileFixtureSupport
7
+ extend ActiveSupport::Concern
8
+ include ActiveSupport::Testing::FileFixtures
10
9
 
11
- included do
12
- self.file_fixture_path = RSpec.configuration.file_fixture_path
13
- end
10
+ included do
11
+ self.file_fixture_path = RSpec.configuration.file_fixture_path
14
12
  end
15
13
  end
16
14
  end