进行第一次rspec测试,运行时出现错误:

 rspec spec/features/list_movies_spec.rb

错误消息:
/Users/waymond/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.5.1/lib/bundler/runtime.rb:34:inblock in setup': You have already activated rspec-core 2.14.7, but your Gemfile requires rspec-core 2.13.1. Prependingbundle exec`到您的命令可以解决这个问题(Gem::加载错误)
在Gemfile.lock中,我注意到其中有两个rspec核心,一个是2.13.0,这可能是问题所在任何关于如何解决这个问题的帮助是非常感谢的。谢谢您!这是我的Gemfile:
 source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more:           https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

 group :test, :development do
 gem "rspec-rails", "~> 2.13.1"
 end

 group :test do
 gem "capybara", "2.1.0"
 end

还有我的Gemfile.lock:
  GEM
  remote: https://rubygems.org/
  specs:
  actionmailer (4.0.2)
  actionpack (= 4.0.2)
  mail (~> 2.5.4)
  actionpack (4.0.2)
  activesupport (= 4.0.2)
  builder (~> 3.1.0)
  erubis (~> 2.7.0)
  rack (~> 1.5.2)
  rack-test (~> 0.6.2)
  activemodel (4.0.2)
  activesupport (= 4.0.2)
  builder (~> 3.1.0)
  activerecord (4.0.2)
  activemodel (= 4.0.2)
  activerecord-deprecated_finders (~> 1.0.2)
  activesupport (= 4.0.2)
  arel (~> 4.0.0)
  activerecord-deprecated_finders (1.0.3)
  activesupport (4.0.2)
  i18n (~> 0.6, >= 0.6.4)
  minitest (~> 4.2)
  multi_json (~> 1.3)
  thread_safe (~> 0.1)
  tzinfo (~> 0.3.37)
  arel (4.0.1)
  atomic (1.1.14)
  builder (3.1.4)
  capybara (2.1.0)
  mime-types (>= 1.16)
  nokogiri (>= 1.3.3)
  rack (>= 1.0.0)
  rack-test (>= 0.5.4)
  xpath (~> 2.0)
  coffee-rails (4.0.1)
  coffee-script (>= 2.2.0)
  railties (>= 4.0.0, < 5.0)
  coffee-script (2.2.0)
  coffee-script-source
  execjs
  coffee-script-source (1.6.3)
  diff-lcs (1.2.5)
  erubis (2.7.0)
  execjs (2.0.2)
  hike (1.2.3)
  i18n (0.6.9)
  jbuilder (1.5.3)
  activesupport (>= 3.0.0)
  multi_json (>= 1.2.0)
  jquery-rails (3.0.4)
  railties (>= 3.0, < 5.0)
  thor (>= 0.14, < 2.0)
  json (1.8.1)
  mail (2.5.4)
  mime-types (~> 1.16)
  treetop (~> 1.4.8)
  mime-types (1.25.1)
  mini_portile (0.5.2)
  minitest (4.7.5)
  multi_json (1.8.2)
  nokogiri (1.6.1)
  mini_portile (~> 0.5.0)
  polyglot (0.3.3)
  rack (1.5.2)
  rack-test (0.6.2)
  rack (>= 1.0)
  rails (4.0.2)
  actionmailer (= 4.0.2)
  actionpack (= 4.0.2)
  activerecord (= 4.0.2)
  activesupport (= 4.0.2)
  bundler (>= 1.3.0, < 2.0)
  railties (= 4.0.2)
  sprockets-rails (~> 2.0.0)
  railties (4.0.2)
  actionpack (= 4.0.2)
  activesupport (= 4.0.2)
  rake (>= 0.8.7)
  thor (>= 0.18.1, < 2.0)
  rake (10.1.1)
  rdoc (3.12.2)
  json (~> 1.4)
  rspec-core (2.13.1)
  rspec-expectations (2.13.0)
  diff-lcs (>= 1.1.3, < 2.0)
  rspec-mocks (2.13.1)
  rspec-rails (2.13.1)
  actionpack (>= 3.0)
  activesupport (>= 3.0)
  railties (>= 3.0)
  rspec-core (~> 2.13.0)
  rspec-expectations (~> 2.13.0)
  rspec-mocks (~> 2.13.0)
  sass (3.2.13)
  sass-rails (4.0.1)
  railties (>= 4.0.0, < 5.0)
  sass (>= 3.1.10)
  sprockets-rails (~> 2.0.0)
  sdoc (0.3.20)
  json (>= 1.1.3)
  rdoc (~> 3.10)
  sprockets (2.10.1)
  hike (~> 1.2)
  multi_json (~> 1.0)
  rack (~> 1.0)
  tilt (~> 1.1, != 1.3.0)
  sprockets-rails (2.0.1)
  actionpack (>= 3.0)
  activesupport (>= 3.0)
  sprockets (~> 2.8)
  sqlite3 (1.3.8)
  thor (0.18.1)
  thread_safe (0.1.3)
  atomic
  tilt (1.4.1)
  treetop (1.4.15)
  polyglot
  polyglot (>= 0.3.1)
  turbolinks (2.1.0)
  coffee-rails
  tzinfo (0.3.38)
  uglifier (2.4.0)
  execjs (>= 0.3.0)
  json (>= 1.8.0)
  xpath (2.0.0)
  nokogiri (~> 1.3)

 PLATFORMS
 ruby

 DEPENDENCIES
 capybara (= 2.1.0)
 coffee-rails (~> 4.0.0)
 jbuilder (~> 1.2)
 jquery-rails
 rails (= 4.0.2)
 rspec-rails (~> 2.13.1)
 sass-rails (~> 4.0.0)
 sdoc
 sqlite3
 turbolinks
 uglifier (>= 1.3.0)

最佳答案

使用运行规范

$ bundle exec rspec spec/features/list_movies_spec.rb

这将确保使用gemfile中列出的相同版本执行命令。
系统上可能安装了多个rspec版本直接使用rspec命令将加载最新版本,但这与Gemfile中列出的版本冲突。
其他可能的解决方案有:
卸载除Gemfile中列出的版本以外的所有版本
升级Gemfile中的rspec版本

10-07 19:07
查看更多