@@ -2,52 +2,50 @@ module RSpec
22 module Rails
33 # @private
44 module FixtureSupport
5- if defined? ( ActiveRecord ::TestFixtures )
6- extend ActiveSupport ::Concern
7- include RSpec ::Rails ::SetupAndTeardownAdapter
8- include RSpec ::Rails ::MinitestLifecycleAdapter
9- include RSpec ::Rails ::MinitestAssertionAdapter
10- include ActiveRecord ::TestFixtures
11-
12- # @private prevent ActiveSupport::TestFixtures to start a DB transaction.
13- # Monkey patched to avoid collisions with 'let(:name)' since Rails 6.1
14- def run_in_transaction?
15- current_example_name = ( RSpec . current_example && RSpec . current_example . metadata [ :description ] )
16- use_transactional_tests && !self . class . uses_transaction? ( current_example_name )
17- end
18-
19- included do
20- if RSpec . configuration . use_active_record?
21- include Fixtures
5+ extend ActiveSupport ::Concern
6+
7+ included do
8+ if RSpec . configuration . use_active_record? && defined? ( ActiveRecord ::TestFixtures )
9+ include RSpec ::Rails ::SetupAndTeardownAdapter
10+ include RSpec ::Rails ::MinitestLifecycleAdapter
11+ include RSpec ::Rails ::MinitestAssertionAdapter
12+ include ActiveRecord ::TestFixtures
13+ include Fixtures
14+
15+ # @private prevent ActiveSupport::TestFixtures to start a DB transaction.
16+ # Monkey patched to avoid collisions with 'let(:name)' since Rails 6.1
17+ def run_in_transaction?
18+ current_example_name = ( RSpec . current_example && RSpec . current_example . metadata [ :description ] )
19+ use_transactional_tests && !self . class . uses_transaction? ( current_example_name )
20+ end
2221
23- self . fixture_paths = RSpec . configuration . fixture_paths
22+ self . fixture_paths = RSpec . configuration . fixture_paths
2423
25- self . use_transactional_tests = RSpec . configuration . use_transactional_fixtures
26- self . use_instantiated_fixtures = RSpec . configuration . use_instantiated_fixtures
24+ self . use_transactional_tests = RSpec . configuration . use_transactional_fixtures
25+ self . use_instantiated_fixtures = RSpec . configuration . use_instantiated_fixtures
2726
28- fixtures RSpec . configuration . global_fixtures if RSpec . configuration . global_fixtures
29- end
27+ fixtures RSpec . configuration . global_fixtures if RSpec . configuration . global_fixtures
3028 end
29+ end
3130
32- module Fixtures
33- extend ActiveSupport ::Concern
31+ module Fixtures
32+ extend ActiveSupport ::Concern
3433
35- class_methods do
36- def fixtures ( *args )
37- super . tap do
38- fixture_sets . each_pair do |method_name , fixture_name |
39- proxy_method_warning_if_called_in_before_context_scope ( method_name , fixture_name )
40- end
34+ class_methods do
35+ def fixtures ( *args )
36+ super . tap do
37+ fixture_sets . each_pair do |method_name , fixture_name |
38+ proxy_method_warning_if_called_in_before_context_scope ( method_name , fixture_name )
4139 end
4240 end
41+ end
4342
44- def proxy_method_warning_if_called_in_before_context_scope ( method_name , fixture_name )
45- define_method ( method_name ) do |*args , **kwargs , &blk |
46- if RSpec . current_scope == :before_context_hook
47- RSpec . warn_with ( "Calling fixture method in before :context " )
48- else
49- access_fixture ( fixture_name , *args , **kwargs , &blk )
50- end
43+ def proxy_method_warning_if_called_in_before_context_scope ( method_name , fixture_name )
44+ define_method ( method_name ) do |*args , **kwargs , &blk |
45+ if RSpec . current_scope == :before_context_hook
46+ RSpec . warn_with ( "Calling fixture method in before :context " )
47+ else
48+ access_fixture ( fixture_name , *args , **kwargs , &blk )
5149 end
5250 end
5351 end
0 commit comments