0

所以我正在研究一个 gem...我输入 bundle,它会安装 rspec 2.0.1,我相信你会明白,这在 rspec 2.12.2 的这个时代是完全不可接受的。

我会同意的,除非我运行 rake spec ......

 % rake spec
/home/alg/.rvm/rubies/ruby-1.9.3-p374/bin/ruby -S bundle exec rspec "./spec/file_comparisons_spec.rb" "./spec/monitor_spec.rb" "./spec/pipboy_spec.rb"
/home/alg/Documents/Code/pipboy/spec/spec_helper.rb:8:in `block in <top (required)>': undefined method `treat_symbols_as_metadata_keys_with_true_values=' for #<RSpec::Core::Configuration:0x9c99a74> (NoMethodError)
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core.rb:67:in `configure'
    from /home/alg/Documents/Code/pipboy/spec/spec_helper.rb:7:in `<top (required)>'
    from /home/alg/Documents/Code/pipboy/spec/file_comparisons_spec.rb:1:in `require'
    from /home/alg/Documents/Code/pipboy/spec/file_comparisons_spec.rb:1:in `<top (required)>'
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load'
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files'
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map'
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files'
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run'
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process'
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run'
    from /home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
ruby -S bundle exec rspec "./spec/file_comparisons_spec.rb" "./spec/monitor_spec.rb" "./spec/pipboy_spec.rb" failed
/home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/rake_task.rb:117:in `rescue in block (2 levels) in initialize'
/home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/rake_task.rb:113:in `block (2 levels) in initialize'
/home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/gems/rspec-core-2.0.1/lib/rspec/core/rake_task.rb:109:in `block in initialize'
/home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/bin/ruby_noexec_wrapper:14:in `eval'
/home/alg/.rvm/gems/ruby-1.9.3-p374@pipboy/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => spec
(See full trace by running task with --trace)

所以这是我认为重要的部分,即使我找不到它们有什么问题:

=> 耙文件

require "bundler/gem_tasks"
require 'rspec/core/rake_task'
require 'cucumber/rake/task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec

Cucumber::Rake::Task.new(:features) do |t|
    t.cucumber_opts = "features --format progress"
end

=> 宝石文件

source :rubygems

# Specify your gem's dependencies in pipboy.gemspec
gemspec

=> 宝石规格

# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'pipboy/version'

Gem::Specification.new do |gem|

  gem.files         = `git ls-files`.split($/)
  gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
  gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
  gem.require_paths = ["lib"]

  gem.add_development_dependency 'rspec'
  gem.add_development_dependency 'cucumber'
  gem.add_development_dependency 'rake'
  gem.add_development_dependency 'rdoc'
end

而且,没有 Gemfile.lock,调用 bundle 的结果...

% bundle
Fetching gem metadata from http://rubygems.org/.........
Fetching gem metadata from http://rubygems.org/..
Using rake (10.0.3) 
Using builder (3.1.4) 
Using diff-lcs (1.2.0) 
Using json (1.7.6) 
Using gherkin (2.11.5) 
Using cucumber (1.2.1) 
Using pipboy (0.0.1) from source at /home/alg/Documents/Code/pipboy 
Using rdoc (3.12) 
Using rspec-core (2.0.1) 
Using rspec-expectations (2.0.1) 
Using rspec-mocks (2.0.1) 
Using rspec (2.0.1) 
Using bundler (1.2.3) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

=> Gemfile.lock 事后

PATH
  remote: .
  specs:
    pipboy (0.0.1)

GEM
  remote: http://rubygems.org/
  specs:
    builder (3.1.4)
    cucumber (1.2.1)
      builder (>= 2.1.2)
      diff-lcs (>= 1.1.3)
      gherkin (~> 2.11.0)
      json (>= 1.4.6)
    diff-lcs (1.2.0)
    gherkin (2.11.5)
      json (>= 1.4.6)
    json (1.7.6)
    rake (10.0.3)
    rdoc (3.12)
      json (~> 1.4)
    rspec (2.0.1)
      rspec-core (~> 2.0.1)
      rspec-expectations (~> 2.0.1)
      rspec-mocks (~> 2.0.1)
    rspec-core (2.0.1)
    rspec-expectations (2.0.1)
      diff-lcs (>= 1.1.2)
    rspec-mocks (2.0.1)
      rspec-core (~> 2.0.1)
      rspec-expectations (~> 2.0.1)

PLATFORMS
  ruby

DEPENDENCIES
  cucumber
  pipboy!
  rake
  rdoc
  rspec
4

1 回答 1

4

看来,诀窍就是这样做。

gem.add_development_dependency 'rspec', '>= 2.12.0'

rspec 使用的 rspec-core 版本为 2.12.2——我错误地认为这些子宝石会与元宝石同时升级。

再说一次,我不知道为什么要下载 rspec 2.0.1 而不是 2.12.0 ...

于 2013-01-24T03:29:37.170 回答