rspec-rails 4.0.0.beta3 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Capybara.md +5 -54
  5. data/Changelog.md +61 -7
  6. data/README.md +20 -19
  7. data/lib/generators/rspec.rb +0 -6
  8. data/lib/generators/rspec/controller/controller_generator.rb +13 -5
  9. data/lib/generators/rspec/controller/templates/request_spec.rb +14 -0
  10. data/lib/generators/rspec/controller/templates/routing_spec.rb +1 -1
  11. data/lib/generators/rspec/feature/feature_generator.rb +2 -2
  12. data/lib/generators/rspec/{generators → generator}/generator_generator.rb +2 -2
  13. data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
  14. data/lib/generators/rspec/helper/helper_generator.rb +1 -1
  15. data/lib/generators/rspec/install/install_generator.rb +4 -4
  16. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +17 -16
  17. data/lib/generators/rspec/integration/integration_generator.rb +3 -3
  18. data/lib/generators/rspec/mailer/mailer_generator.rb +1 -1
  19. data/lib/generators/rspec/model/model_generator.rb +4 -4
  20. data/lib/generators/rspec/scaffold/scaffold_generator.rb +26 -18
  21. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +0 -36
  22. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  23. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -10
  24. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
  25. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  26. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
  27. data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -0
  28. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
  29. data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
  30. data/lib/generators/rspec/system/system_generator.rb +1 -1
  31. data/lib/generators/rspec/view/view_generator.rb +2 -2
  32. data/lib/rspec-rails.rb +6 -9
  33. data/lib/rspec/rails/adapters.rb +10 -76
  34. data/lib/rspec/rails/configuration.rb +72 -36
  35. data/lib/rspec/rails/example/channel_example_group.rb +2 -2
  36. data/lib/rspec/rails/example/controller_example_group.rb +4 -4
  37. data/lib/rspec/rails/example/feature_example_group.rb +6 -26
  38. data/lib/rspec/rails/example/helper_example_group.rb +2 -10
  39. data/lib/rspec/rails/example/mailbox_example_group.rb +1 -1
  40. data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
  41. data/lib/rspec/rails/example/rails_example_group.rb +1 -1
  42. data/lib/rspec/rails/example/system_example_group.rb +14 -7
  43. data/lib/rspec/rails/example/view_example_group.rb +38 -48
  44. data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
  45. data/lib/rspec/rails/feature_check.rb +1 -28
  46. data/lib/rspec/rails/fixture_file_upload_support.rb +8 -13
  47. data/lib/rspec/rails/fixture_support.rb +37 -31
  48. data/lib/rspec/rails/matchers/action_cable.rb +1 -1
  49. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +3 -3
  50. data/lib/rspec/rails/matchers/active_job.rb +132 -18
  51. data/lib/rspec/rails/matchers/base_matcher.rb +4 -10
  52. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +9 -6
  53. data/lib/rspec/rails/matchers/have_http_status.rb +7 -7
  54. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  55. data/lib/rspec/rails/matchers/routing_matchers.rb +11 -11
  56. data/lib/rspec/rails/tasks/rspec.rake +7 -17
  57. data/lib/rspec/rails/vendor/capybara.rb +10 -15
  58. data/lib/rspec/rails/version.rb +1 -1
  59. data/lib/rspec/rails/view_path_builder.rb +1 -1
  60. data/lib/rspec/rails/view_rendering.rb +3 -3
  61. metadata +34 -33
  62. metadata.gz.sig +0 -0
  63. data/lib/generators/rspec/observer/observer_generator.rb +0 -13
  64. data/lib/generators/rspec/observer/templates/observer_spec.rb +0 -7
@@ -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
- :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
@@ -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 (https://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,16 +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
-
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
 
@@ -13,7 +13,7 @@ module RSpec
13
13
  def self.create_inbound_email(arg)
14
14
  case arg
15
15
  when Hash
16
- create_inbound_email_from_mail(arg)
16
+ create_inbound_email_from_mail(**arg)
17
17
  else
18
18
  create_inbound_email_from_source(arg.to_s)
19
19
  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.
@@ -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 if ::Rails::VERSION::STRING >= '4'
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,16 +88,19 @@ 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
- def driven_by(*args, &blk)
91
- @driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use)
99
+ def driven_by(driver, **driver_options, &blk)
100
+ @driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
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
 
@@ -108,7 +114,8 @@ module RSpec
108
114
  original_after_teardown.bind(self).call
109
115
  ensure
110
116
  myio = $stdout
111
- RSpec.current_example.metadata[:extra_failure_lines] = myio.string
117
+ myio.rewind
118
+ RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
112
119
  $stdout = orig_stdout
113
120
  end
114
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({:partial => path_to_file})
54
- # @overload render({:partial => path_to_file}, {... locals ...})
55
- # @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
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(:file => "widgets/new.html.erb")
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", :replacement => "view")
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 ::Rails::VERSION::STRING >= '3.2'
132
- formats = if ActionView::Template::Types.respond_to?(:symbols)
133
- ActionView::Template::Types.symbols
134
- else
135
- [:html, :text, :js, :css, :xml, :json].map(&:to_s)
136
- end.map { |x| Regexp.escape(x) }.join("|")
137
-
138
- handlers = ActionView::Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|")
139
- locales = "[a-z]{2}(?:-[A-Z]{2})?"
140
- variants = "[^.]*"
141
- path_regex = %r{
142
- \A
143
- (?<template>.*?)
144
- (?:\.(?<locale>#{locales}))??
145
- (?:\.(?<format>#{formats}))??
146
- (?:\+(?<variant>#{variants}))??
147
- (?:\.(?<handler>#{handlers}))?
148
- \z
149
- }x
150
-
151
- # This regex should always find a match.
152
- # Worst case, everything will be nil, and :template will just be
153
- # the original string.
154
- match = path_regex.match(_default_file_to_render)
155
-
156
- render_options = { :template => match[:template] }
157
- render_options[:handlers] = [match[:handler]] if match[:handler]
158
- render_options[:formats] = [match[:format].to_sym] if match[:format]
159
- render_options[:locales] = [match[:locale]] if match[:locale]
160
- render_options[:variants] = [match[:variant]] if match[:variant]
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
- if view.lookup_context.respond_to?(:prefixes)
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
 
@@ -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
@@ -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
- if has_1_9_hash_syntax?
67
- "type: :#{type}"
68
- else
69
- ":type => :#{type}"
70
- end
43
+ "type: :#{type}"
71
44
  end
72
45
  end
73
46
  end
@@ -2,13 +2,18 @@ module RSpec
2
2
  module Rails
3
3
  # @private
4
4
  module FixtureFileUploadSupport
5
- delegate :fixture_file_upload, :to => :rails_fixture_file_wrapper
5
+ delegate :fixture_file_upload, to: :rails_fixture_file_wrapper
6
6
 
7
7
  private
8
8
 
9
9
  def rails_fixture_file_wrapper
10
10
  RailsFixtureFileWrapper.fixture_path = nil
11
- resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '').to_s
11
+ resolved_fixture_path =
12
+ if respond_to?(:fixture_path) && !fixture_path.nil?
13
+ fixture_path.to_s
14
+ else
15
+ (RSpec.configuration.fixture_path || '').to_s
16
+ end
12
17
  RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
13
18
  RailsFixtureFileWrapper.instance
14
19
  end
@@ -17,22 +22,12 @@ module RSpec
17
22
  include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)
18
23
 
19
24
  class << self
20
- attr_reader :fixture_path
25
+ attr_accessor :fixture_path
21
26
 
22
27
  # Get instance of wrapper
23
28
  def instance
24
29
  @instance ||= new
25
30
  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
31
  end
37
32
  end
38
33
  end
@@ -5,52 +5,58 @@ module RSpec
5
5
  if defined?(ActiveRecord::TestFixtures)
6
6
  extend ActiveSupport::Concern
7
7
  include RSpec::Rails::SetupAndTeardownAdapter
8
- include RSpec::Rails::MinitestLifecycleAdapter if ::ActiveRecord::VERSION::STRING > '4'
8
+ include RSpec::Rails::MinitestLifecycleAdapter
9
9
  include RSpec::Rails::MinitestAssertionAdapter
10
10
  include ActiveRecord::TestFixtures
11
11
 
12
12
  included do
13
- # TODO: (DC 2011-06-25) this is necessary because fixture_file_upload
14
- # accesses fixture_path directly on ActiveSupport::TestCase. This is
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
13
+ if RSpec.configuration.use_active_record?
14
+ include Fixtures
15
+
20
16
  self.fixture_path = RSpec.configuration.fixture_path
21
- end
22
- # /TODO
17
+ if ::Rails::VERSION::STRING > '5'
18
+ self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
19
+ else
20
+ self.use_transactional_fixtures = RSpec.configuration.use_transactional_fixtures
21
+ end
22
+ self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures
23
23
 
24
- self.fixture_path = RSpec.configuration.fixture_path
25
- if ::Rails::VERSION::STRING > '5'
26
- self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
27
- else
28
- self.use_transactional_fixtures = RSpec.configuration.use_transactional_fixtures
24
+ fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
29
25
  end
30
- self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures
26
+ end
31
27
 
32
- def self.fixtures(*args)
33
- orig_methods = private_instance_methods
34
- super.tap do
35
- new_methods = private_instance_methods - orig_methods
36
- new_methods.each do |method_name|
37
- proxy_method_warning_if_called_in_before_context_scope(method_name)
28
+ module Fixtures
29
+ extend ActiveSupport::Concern
30
+
31
+ class_methods do
32
+ def fixtures(*args)
33
+ orig_methods = private_instance_methods
34
+ super.tap do
35
+ new_methods = private_instance_methods - orig_methods
36
+ new_methods.each do |method_name|
37
+ proxy_method_warning_if_called_in_before_context_scope(method_name)
38
+ end
38
39
  end
39
40
  end
40
- end
41
41
 
42
- def self.proxy_method_warning_if_called_in_before_context_scope(method_name)
43
- orig_implementation = instance_method(method_name)
44
- define_method(method_name) do |*args, &blk|
45
- if inspect.include?("before(:context)")
46
- RSpec.warn_with("Calling fixture method in before :context ")
47
- else
48
- orig_implementation.bind(self).call(*args, &blk)
42
+ def proxy_method_warning_if_called_in_before_context_scope(method_name)
43
+ orig_implementation = instance_method(method_name)
44
+ define_method(method_name) do |*args, &blk|
45
+ if inspect.include?("before(:context)")
46
+ RSpec.warn_with("Calling fixture method in before :context ")
47
+ else
48
+ orig_implementation.bind(self).call(*args, &blk)
49
+ end
49
50
  end
50
51
  end
51
52
  end
52
53
 
53
- fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
54
+ if ::Rails.version.to_f >= 6.1
55
+ # @private return the example name for TestFixtures
56
+ def name
57
+ @example
58
+ end
59
+ end
54
60
  end
55
61
  end
56
62
  end