在新应用程序上运行第一次测试时出现Rspec错误

时间:2013-11-15 00:48:29

标签: ruby-on-rails ruby rspec ruby-on-rails-4

我在新应用上运行我的第一个测试,我收到此错误:

/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/
runtime.rb:33:in `block in setup': You have already activated rspec-core
2.14.4, but your Gemfile requires rspec-core 2.13.1. Using bundle exec
may solve this. (Gem::LoadError)

我不知道“激活的rspec-core 2.14.4意味着什么。我不记得做过这样的事。”

我从命令行运行测试:

bundle exec rspec spec/requests/static_pages_spec.rb

Ruby -v:2.0.0

Rails -v:4.0.0

有问题的测试:

要求'spec_helper'

describe "Static pages" do

  describe "Home page" do

    it "should have the content 'Skeleton App'" do
      visit root_url
      expect(page).to have_content('Skeleton App')
    end
  end
end

我的Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.0'
gem 'bootstrap-sass', '~> 3.0.1.0.rc'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.1.2'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'

gem 'devise'

group :development, :test do
  gem 'sqlite3', '1.3.7'
  gem 'rspec-rails', '2.13.1'
  # The following optional lines are part of the advanced setup.
  gem 'guard-rspec', '2.5.0'
  gem 'spork-rails', github: 'sporkrb/spork-rails'
  gem 'guard-spork', '1.5.0'
  gem 'childprocess', '0.3.6'
end

group :test do
  gem 'selenium-webdriver', '2.0.0'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.2.0'
  gem 'cucumber-rails', '1.3.0', :require => false
  gem 'database_cleaner', github: 'bmabey/database_cleaner'

  # Uncomment this line on OS X.
  gem 'growl', '1.0.3'

  # Uncomment these lines on Linux.
  # gem 'libnotify', '0.8.0'

  # Uncomment these lines on Windows.
  # gem 'rb-notifu', '0.0.4'
  # gem 'win32console', '1.3.2'
end

gem 'sass-rails', '4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

谢谢!

修改

/Gemfile.lock

GIT
  remote: git://github.com/bmabey/database_cleaner.git
  revision: 6da38c4c1a565bbcc62ed9b84c2574537c6ebae2
  specs:
    database_cleaner (1.2.0)

GIT
  remote: git://github.com/sporkrb/spork-rails.git
  revision: 0dd45e59d3237b4c8f9efc215b46d9c07072a95e
  specs:
    spork-rails (4.0.0)
      rails (>= 3.0.0, < 5)
      spork (>= 1.0rc0)

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.0.0)
      actionpack (= 4.0.0)
      mail (~> 2.5.3)
    actionpack (4.0.0)
      activesupport (= 4.0.0)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    activemodel (4.0.0)
      activesupport (= 4.0.0)
      builder (~> 3.1.0)
    activerecord (4.0.0)
      activemodel (= 4.0.0)
      activerecord-deprecated_finders (~> 1.0.2)
      activesupport (= 4.0.0)
      arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.0)
      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)
    bcrypt-ruby (3.0.1)
    bootstrap-sass (3.0.1.0)
      sass (~> 3.2)
    bootstrap-will_paginate (0.0.9)
      will_paginate
    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)
    celluloid (0.15.2)
      timers (~> 1.1.0)
    childprocess (0.3.6)
      ffi (~> 1.0, >= 1.0.6)
    coderay (1.0.9)
    coffee-rails (4.0.0)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0.beta, < 5.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.6.3)
    cucumber (1.3.9)
      builder (>= 2.1.2)
      diff-lcs (>= 1.1.3)
      gherkin (~> 2.12)
      multi_json (>= 1.7.5, < 2.0)
      multi_test (>= 0.0.2)
    cucumber-rails (1.3.0)
      capybara (>= 1.1.2)
      cucumber (>= 1.1.8)
      nokogiri (>= 1.5.0)
    devise (3.2.0)
      bcrypt-ruby (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 3.2.6, < 5)
      thread_safe (~> 0.1)
      warden (~> 1.2.3)
    diff-lcs (1.2.5)
    erubis (2.7.0)
    execjs (2.0.2)
    factory_girl (4.2.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.2.0)
      factory_girl (~> 4.2.0)
      railties (>= 3.0.0)
    faker (1.1.2)
      i18n (~> 0.5)
    ffi (1.9.3)
    formatador (0.2.4)
    gherkin (2.12.2)
      multi_json (~> 1.3)
    growl (1.0.3)
    guard (2.2.3)
      formatador (>= 0.2.4)
      listen (~> 2.1)
      lumberjack (~> 1.0)
      pry (>= 0.9.12)
      thor (>= 0.18.1)
    guard-rspec (2.5.0)
      guard (>= 1.1)
      rspec (~> 2.11)
    guard-spork (1.5.0)
      childprocess (>= 0.2.3)
      guard (>= 1.1)
      spork (>= 0.8.4)
    hike (1.2.3)
    i18n (0.6.5)
    jbuilder (1.0.2)
      activesupport (>= 3.0.0)
    jquery-rails (2.2.1)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    json (1.8.1)
    json_pure (1.8.1)
    listen (2.2.0)
      celluloid (>= 0.15.2)
      rb-fsevent (>= 0.9.3)
      rb-inotify (>= 0.9)
    lumberjack (1.0.4)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    method_source (0.8.2)
    mime-types (1.25)
    mini_portile (0.5.2)
    minitest (4.7.5)
    multi_json (1.8.2)
    multi_test (0.0.2)
    nokogiri (1.6.0)
      mini_portile (~> 0.5.0)
    orm_adapter (0.4.0)
    pg (0.15.1)
    polyglot (0.3.3)
    pry (0.9.12.2)
      coderay (~> 1.0.5)
      method_source (~> 0.8)
      slop (~> 3.4)
    rack (1.5.2)
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (4.0.0)
      actionmailer (= 4.0.0)
      actionpack (= 4.0.0)
      activerecord (= 4.0.0)
      activesupport (= 4.0.0)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.0.0)
      sprockets-rails (~> 2.0.0)
    rails_12factor (0.0.2)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.1)
    rails_stdout_logging (0.0.3)
    railties (4.0.0)
      actionpack (= 4.0.0)
      activesupport (= 4.0.0)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.1.0)
    rb-fsevent (0.9.3)
    rb-inotify (0.9.2)
      ffi (>= 0.5.0)
    rdoc (3.12.2)
      json (~> 1.4)
    rspec (2.13.0)
      rspec-core (~> 2.13.0)
      rspec-expectations (~> 2.13.0)
      rspec-mocks (~> 2.13.0)
    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)
    rubyzip (1.1.0)
    sass (3.2.12)
    sass-rails (4.0.0)
      railties (>= 4.0.0.beta, < 5.0)
      sass (>= 3.1.10)
      sprockets-rails (~> 2.0.0)
    sdoc (0.3.20)
      json (>= 1.1.3)
      rdoc (~> 3.10)
    selenium-webdriver (2.0.0)
      childprocess (>= 0.1.9)
      ffi (>= 1.0.7)
      json_pure
      rubyzip
    slop (3.4.6)
    spork (1.0.0rc4)
    sprockets (2.10.0)
      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.7)
    thor (0.18.1)
    thread_safe (0.1.3)
      atomic
    tilt (1.4.1)
    timers (1.1.0)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    turbolinks (1.1.1)
      coffee-rails
    tzinfo (0.3.38)
    uglifier (2.1.1)
      execjs (>= 0.3.0)
      multi_json (~> 1.0, >= 1.0.2)
    warden (1.2.3)
      rack (>= 1.0)
    will_paginate (3.0.4)
    xpath (2.0.0)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  bcrypt-ruby (= 3.0.1)
  bootstrap-sass (~> 3.0.1.0.rc)
  bootstrap-will_paginate (= 0.0.9)
  capybara (= 2.1.0)
  childprocess (= 0.3.6)
  coffee-rails (= 4.0.0)
  cucumber-rails (= 1.3.0)
  database_cleaner!
  devise
  factory_girl_rails (= 4.2.0)
  faker (= 1.1.2)
  growl (= 1.0.3)
  guard-rspec (= 2.5.0)
  guard-spork (= 1.5.0)
  jbuilder (= 1.0.2)
  jquery-rails (= 2.2.1)
  pg (= 0.15.1)
  rails (= 4.0.0)
  rails_12factor (= 0.0.2)
  rspec-rails (= 2.13.1)
  sass-rails (= 4.0.0)
  sdoc (= 0.3.20)
  selenium-webdriver (= 2.0.0)
  spork-rails!
  sqlite3 (= 1.3.7)
  turbolinks (= 1.1.1)
  uglifier (= 2.1.1)
  will_paginate (= 3.0.4)

3 个答案:

答案 0 :(得分:1)

在Gemfile.lock文件中查找多个rspec-core依赖项。很可能你所包含的宝石之一锁定了一个与你锁定的版本不一致的依赖。

在此处粘贴Gemfile.lock文件以获取更多帮助。

合理的解决方案是在gemfile中使用一个运算符,允许限制较少的版本锁定。悲观的运算符(`gem'rspec-rails','〜&gt; 2.13')将允许版本的rspec-rails&gt; = 2.13和&lt; 3.更多信息:http://techiferous.com/2011/05/sanely-updating-your-gems/

答案 1 :(得分:1)

试试这个:在你的Gemfile中指定:

group :development, :test do 
  gem 'rspec-rails', "~> 2.14"
  #other gems for development and test only
end

然后在shell cd中运行你的应用程序目录并运行

bundle install

让我知道这是否有效或者我错过了什么。

答案 2 :(得分:1)

我不确定导致此错误的原因,但我从Gemfile中移除了所有与rspec相关的(实际上所有与测试相关的)宝石,运行bundle install,将其添加回来,然后再次运行bundle install,到目前为止它似乎正在发挥作用。

相关问题