palkan / anyway_config

Configuration library for Ruby gems and applications
MIT License
778 stars 52 forks source link

RSpec.configure is not always available if RSpec::Core is defined #129

Closed stefanhorning closed 1 year ago

stefanhorning commented 1 year ago

What did you do?

Run a rake task which includes rspec rake tasks like this:

require 'rspec/core/rake_task'

Which is quite a common line added on top of many Rakefiles as it makes Rspec commands available as rake tasks.

What did you expect to happen?

The rake task to succeed.

What actually happened?

I got an error NoMethodError: undefined method 'configure' for RSpec:Module from within anyway_config-2.4.1/lib/anyway/testing.rb

Additional context

This is locigal, as at this point the RSpec::Core class will be defined. Which doesn't automatically mean that RSpec.configure is available (as only parts for Rspec::Core will be loaded). I guess a better check here would be to also test for Rspec.configure being present like so:

if defined?(RSpec::Core) && RSpec.respond_to?(:configure)

Environment

Ruby Version: 2.7.2p137

Rspec version: rspec-core-3.12.2

Anyway Config Version: 2.4.1

palkan commented 1 year ago

Thanks for the report!

if defined?(RSpec::Core) && RSpec.respond_to?(:configure)

Yeah, this check looks better; will update.