Skip to content

Commit d9b14a7

Browse files
lazyatomsebjacobs
authored andcommitted
Only configure RSpec::Mocks if it is fully loaded
It's possible for the `::RSpec::Mocks` constant to exist, but for it not to have the `configuration` method present. This can happen if another library has required some files from _within_ the `rspec/mocks` library, but nothing else has fully loaded it. For a concrete example, see krisleech/wisper-rspec#21 While allowing external libraries to use parts of this one might not be something that's explicitly supported, we can avoid some unexpected exceptions by adding a little extra check to our detection of whether or not the mocking library is loaded.
1 parent 5f6e092 commit d9b14a7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/rspec/rails/active_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ActiveRecordConfiguration
77
def self.initialize_activerecord_configuration(config)
88
config.before :suite do
99
# This allows dynamic columns etc to be used on ActiveRecord models when creating instance_doubles
10-
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && defined?(::RSpec::Mocks)
10+
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && defined?(::RSpec::Mocks) && (::RSpec::Mocks.respond_to?(:configuration))
1111
::RSpec::Mocks.configuration.when_declaring_verifying_double do |possible_model|
1212
target = possible_model.target
1313

0 commit comments

Comments
 (0)