testing my Ruby gem: undefined method `configure' for Shoulda::Matchers:Module (NoMethodError)
Asked Answered
A

3

5

I'm working on my first Ruby gem and have bundled cucumber, rspec and shoulda-matches for testing. When I run rspec, I get the following error:

/app/my_gem/spec/spec_helper.rb:6:in `<top (required)>': undefined method `configure' for Shoulda::Matchers:Module (NoMethodError)

Here is my gemspec:

# my_gem.gemspec
...
Gem::Specification.new do |spec|
  ...
  ...
  spec.add_development_dependency "activemodel"
  spec.add_development_dependency "bundler", "~> 1.8"
  spec.add_development_dependency "cucumber"
  spec.add_development_dependency "rake", "~> 10.0"
  spec.add_development_dependency "rspec" 
  spec.add_development_dependency "shoulda-matchers"
end

My spec_helper.rb:

require 'my_gem'
require 'pry'
require 'shoulda/matchers'

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec

    # with.library :active_record
    with.library :active_model
    # with.library :action_controller
    # Or, choose all of the above:
    # with.library :rails
  end
end

It's finding Shoulda::Matchers but not the .configure method for some reason. Am I requiring shoulda wrong somehow? Not sure if this is related, but the rspec is also giving me this warning:

WARN: Unresolved specs during Gem::Specification.reset:
  json (>= 1.7.7, ~> 1.7)
  minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.

Thanks for any pointers!

Alternation answered 14/4, 2015 at 15:47 Comment(0)
S
10

It looks like you are trying to use the documentation for the 3.0.0.alpha version of shoulda-matchers which supports 3.0.0.alpha, but are using an older version. Either see the correct documentation for the version you are using (I'm guessing 2.8.x) or update your Gemfile to use 3.0.0.alpha:

gem 'shoulda-matchers', github: 'thoughtbot/shoulda-matchers'

Then run bundle install and Shoulda::Matchers.configure should start working.

Statolith answered 14/4, 2015 at 16:30 Comment(2)
Thanks, you were exactly right. I am using 2.8.0 and the configure block isn't necessaryAlternation
it is misspell, took me a while to figure out an error while running bundle installRegal
B
0

The solution provided by @infused is correct.

The documentation and configuration provided in GitHub is for version 3.x and not for 2.x.

In order to make it work, change the version of should-matchers to '~> 3.0.0.alpha' and then run 'bundle update should-matchers'

Bishopric answered 26/3, 2018 at 6:25 Comment(0)
R
-1

Git protocol is depreciated, now use:

   gem 'shoulda-matchers', git: 'https://github.com/thoughtbot/shoulda-matchers.git'

(per https://github.com/thoughtbot/shoulda-matchers/issues/719#issuecomment-103556439)

Regal answered 19/5, 2015 at 15:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.