测试我的Ruby gem:未定义的方法`configure'for Shoulda :: Matchers:Module(NoMethodError)

six*_*bit 5 ruby gem rspec ruby-on-rails shoulda

我正在研究我的第一个Ruby gem,并将黄瓜,rspec和shoulda-matches捆绑在一起进行测试.当我运行rspec时,我收到以下错误:

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

这是我的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
Run Code Online (Sandbox Code Playgroud)

我的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
Run Code Online (Sandbox Code Playgroud)

.configure由于某些原因,它发现了Shoulda :: Matchers而不是方法.我shoulda以某种方式要求错误吗?不确定这是否相关,但是rspec也给了我这个警告:

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.
Run Code Online (Sandbox Code Playgroud)

感谢您的任何指示!

inf*_*sed 10

看起来您正在尝试使用支持的3.0.0.alpha,但使用较旧版本的应该匹配的3.0.0.alpha版本的文档.请查看您正在使用的版本的正确文档(我猜是2.8.x)或更新您要使用的Gemfile 3.0.0.alpha:

gem 'shoulda-matchers', github: 'thoughtbot/shoulda-matchers'
Run Code Online (Sandbox Code Playgroud)

然后运行bundle install,Shoulda::Matchers.configure应该开始工作.