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

标签 ruby-on-rails ruby rspec gem shoulda

我正在开发我的第一个 Ruby gem,并捆绑了 cucumber、rspec 和 shoulda-matches 进行测试。当我运行 rspec 时,出现以下错误:

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

这是我的 gem 规范:

# 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

我的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

出于某种原因,它找到了 Shoulda::Matchers 而不是 .configure 方法。我是否要求 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.

谢谢指点!

最佳答案

看起来您正在尝试使用支持 3.0.0.alpha 的 3.0.0.alpha 版 shoulda-matchers 的文档,但使用的是旧版本。查看您正在使用的版本的正确文档(我猜是 2.8.x )或更新您的 Gemfile 以使用 3.0.0.alpha:

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

然后运行 ​​bundle install 并且 Shoulda::Matchers.configure 应该开始工作。

关于ruby-on-rails - 测试我的 Ruby gem:Shoulda::Matchers:Module (NoMethodError) 的未定义方法 `configure',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29631831/

相关文章:

ruby - RSpec:如何监视与现有对象的交互?

ruby-on-rails - Rubocop RSpec/MultipleMemoizedHelpers 问题关于专家规范测试

ruby-on-rails - 如何使用 curl 查询 restful rails 应用程序?

ruby-on-rails - 为什么乘客找不到我的 rails 根

ruby - 比较 rspec 中的 float 时的奇怪行为

ruby-on-rails - ActionController::ParameterMissing - 参数缺失或值为空:用户:

ruby - 如何在 ruby​​ 中代理 shell 进程

ruby-on-rails-3 - 使用 Rails 3.2.12 使用 capybara 进行 ajax 调用的集成测试错误

ruby-on-rails - 在 ruby​​ 中使用索引遍历属性

ruby-on-rails - Ruby On Rails 中的类列表