G5 / jsonapi-resources-matchers

Test matchers for jsonapi-resources
MIT License
31 stars 14 forks source link

undefined method `configure' for RSpec:Module (with Spring and Bundler.require) #12

Open Justin-Maxwell opened 7 years ago

Justin-Maxwell commented 7 years ago

[nb: workaround is simply gem 'jsonapi-resources-matchers', :require => false]

Using RubyMine, with Spring, and Bundler.require in application.rb

There was an error while trying to load the gem 'jsonapi-resources-matchers'. 
Gem Load Error is: undefined method `configure' for RSpec:Module

As near as I can tell: When jsonapi-resources-matchers is loaded by Bundler.require, lib/jsonapi/resources/matchers/integrations/rspec.rb checks to see if RSpec is defined before calling Rspec.configure, but I'm guessing RSpec.configure is dynamically created, and not necessarily at load time.

Adding the second line here:

if defined?(RSpec)
  puts 'RSpec: ', defined?(RSpec) || 'nope', '.configure: ', defined?(RSpec.configure) || 'nope'
  RSpec.configure do |c|
    c.include JSONAPI::Resources::Matchers, type: :resource
  end
end

with Spring enabled, outputs:

RSpec: 
constant
.configure: 
nope

and without Spring:

RSpec: 
constant
.configure: 
method
ramontayag commented 7 years ago

Perhaps the lib/jsonapi-resources-matchers.rb shouldn't require lib/jsonapi/resources/matchers.rb and just let the user paste that into their spec helper. What do you think?

Justin-Maxwell commented 7 years ago

To be honest, I'm still struggling with Ruby/Rails includes, but I think requiring/allowing the user to be explicit in the spec_helper or individual specs is in-line with other testing libraries. So yes.