lib/convenient_service/support/gems/rspec.rb in convenient_service-0.3.1 vs lib/convenient_service/support/gems/rspec.rb in convenient_service-0.4.0
- old
+ new
@@ -32,18 +32,25 @@
##
# @return [RSpec::Core::Example, nil]
#
# @internal
- # NOTE: Returns `nil` in a non-test environment
+ # NOTE: Returns `nil` in environments where RSpec is NOT fully loaded, e.g: irb, rails console, etc.
#
# `::RSpec.current_example` docs:
# - https://www.rubydoc.info/github/rspec/rspec-core/RSpec.current_example
# - https://github.com/rspec/rspec-core/blob/v3.12.0/lib/rspec/core.rb#L122
# - https://relishapp.com/rspec/rspec-core/docs/metadata/current-example
#
def current_example
- ::RSpec.current_example if loaded?
+ return unless loaded?
+
+ ##
+ # NOTE: This happens in Ruby-only projects where RSpec is loaded by `Bundler.require`, not by `bundle exec rspec`.
+ #
+ return unless ::RSpec.respond_to?(:current_example)
+
+ ::RSpec.current_example
end
end
end
end
end