无法再运行 rspec

Cannot run rspec anymore

我有 ruby 2.0 和 rspec 3.0。我卸载了所有 rspec 3.0 gem 并将它们替换为 2.0。我这样做是为了摆脱弃用警告。现在,我的规格不起作用。我收到以下错误。错误告诉我什么,我该如何解决?关于此的堆栈溢出帖子都没有帮助。

/zombie/spec/spec_helper.rb:29:in `block (2 levels) in <top (required)>': undefined method `include_chain_clauses_in_custom_matcher_descriptions=' for #<RSpec::Matchers::Configuration:0x00000001a73928> (NoMethodError)
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:398:in `expect_with'
    from /home/lsusr/Code/Rspec/zombie/spec/spec_helper.rb:21:in `block in <top (required)>'
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core.rb:92:in `configure'
    from /home/lsusr/Code/Rspec/zombie/spec/spec_helper.rb:17:in `<top (required)>'
    from /home/lsusr/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/lsusr/.rvm/rubies/ruby-2.0.0-p598/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `block in requires='
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `map'
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `requires='
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:20:in `block in configure'
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `each'
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `configure'
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:21:in `run'
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
    from /home/lsusr/.rvm/gems/ruby-2.0.0-p598/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'

好的,我找到了解决方法。

我刚刚使用

删除了所有不必要的 gem
for i in `gem list --no-versions`; do gem uninstall -aIx $i; done

然后,我使用 gem install rspec 重新安装了 rspec,这给了我 rspec 3.0 并修复了所有问题。但是,我再次收到弃用警告。

请告诉我错误发生的原因。教程作者说它应该适用于 rspec 2.10.0 或更高版本。

The tutorial author said that it should work with rspec 2.10.0 or higher.

可能作者的意思是 2.10 或更高,在 2.x 范围内。 RSpec 3.x 有重大变化。

像以前一样尝试卸载 gem,然后:

gem install rspec '>=2.10', '<3'

然后运行你的代码。

使用 RSpec 3 时出现的弃用警告还不错;他们正在指导您,您正在调用的 RSpec 方法将被淘汰。在移动整个版本号时,这些类型的警告是典型且正常的,例如2.x 到 3.x.

您在使用 RSpec 2.0 时遇到的错误是因为那是一个非常旧的版本,并且您调用的方法在 2.0 中不存在。这大概就是教程作者说要用2.10以上的原因吧

教程很可能已经过时了,所以最好的解决办法是写信给教程作者,让 him/her 知道更新它。

如果您对 RSpec 的版本号是如何计算的感到好奇,这里是 link 到 Semantic Versioning