无法在RoR中运行rspec

时间:2017-01-19 06:36:33

标签: ruby-on-rails json rspec

我是RoR的初学者,我遇到错误当我在rails中运行 rspec 时,我收到此错误消息:

您已经激活了json 2.0.2,但您的Gemfile需要json 1.8.6。将bundle exec添加到您的命令可能会解决此问题。 (GEM :: LoadError)

我尝试通过“捆绑更新json ”更新json gem,但仍然收到相同的错误消息。

有人可以帮我解决这个问题。 我正在使用: - Ruby 2.3.0            - Rails 4.2.7.1            - 宝石版2.5.1 谢谢!

这是我的Gemfile内容:

source "https://rubygems.org"

ruby "2.3.0"

gem "dhis2",                   github: 'BLSQ/dhis2'
gem "rails",                   "4.2.7.1"
gem "awesome_print",           "1.6.1"
gem "pg",                      "0.18.4"
gem "sass-rails",              "5.0.6"
gem "uglifier",                "3.0.0"
gem "coffee-rails",            "4.1.0"
gem "therubyracer",            "0.12.2"
gem "jquery-rails",            "4.1.1"
gem "translation",             "1.6"
gem "slim",                    "3.0.6"
gem "bootstrap-sass",          "3.3.6"
gem "rails_admin",             "0.8.1"
gem "devise",                  "4.0.0"
gem "simple_form",             "3.2.1"
gem "rest-client",             "2.0.0"
gem "figaro",                  "1.1.1"
gem "sidekiq",                 "4.1.1"
gem "unicorn",                 "5.1.0"
gem "sentry-raven",            "0.15.6"
gem "sinatra",                 require: nil
gem "will_paginate",           "3.1.0"
gem "will_paginate-bootstrap", "1.0.1"
gem "rubyzip", "~> 1.1.0"
gem "axlsx", "2.1.0.pre"
gem "axlsx_rails"
gem "jquery-ui-rails"
gem "rails4-autocomplete"
gem "chosen-rails"

group :production do
  gem "rails_12factor", "0.0.3"
end

group :development, :test do
  gem "derailed"
  gem "byebug"
  gem "database_cleaner"
  gem "factory_girl_rails", " 4.0"
  gem "faker"
  gem "rspec-its"
  gem "rspec-rails",        "~> 3.0"
  gem "shoulda-matchers",   require: false
  gem "rails-erd"
  gem "mailcatcher"
  gem "rest-client-logger"
end

group :development do
  gem "annotate"
  gem "web-console", "2.0"
  gem "spring"
  gem 'rack-mini-profiler'
  gem 'memory_profiler'
  gem 'flamegraph'
  gem 'stackprof'
end

group :test do
  gem "simplecov", require: false
  gem "codeclimate-test-reporter", "~> 1.0.0"
  gem "webmock"
  gem "rspec-sidekiq",        "~> 2.2.0"

end

这是Gemfile.lock:

GIT
  revision: d91e3ebecefc3ded8c17d7d786a7de6d42efebfb
  specs:
    dhis2 (2.2.1)
      rest-client

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.2.7.1)
      actionpack (= 4.2.7.1)
      actionview (= 4.2.7.1)
      activejob (= 4.2.7.1)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.7.1)
      actionview (= 4.2.7.1)
      activesupport (= 4.2.7.1)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (4.2.7.1)
      activesupport (= 4.2.7.1)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    activejob (4.2.7.1)
      activesupport (= 4.2.7.1)
      globalid (>= 0.3.0)
    activemodel (4.2.7.1)
      activesupport (= 4.2.7.1)
      builder (~> 3.1)
    activerecord (4.2.7.1)
      activemodel (= 4.2.7.1)
      activesupport (= 4.2.7.1)
      arel (~> 6.0)
    activesupport (4.2.7.1)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    addressable (2.5.0)
      public_suffix (~> 2.0, >= 2.0.2)
    annotate (2.7.1)
      activerecord (>= 3.2, < 6.0)
      rake (>= 10.4, < 12.0)
    arel (6.0.4)
    autoprefixer-rails (6.6.1)
      execjs
    awesome_print (1.6.1)
    axlsx (2.1.0.pre)
      htmlentities (~> 4.3.1)
      nokogiri (>= 1.4.1)
      rubyzip (~> 1.1.7)
    axlsx_rails (0.5.0)
      actionpack (>= 3.1)
      axlsx (>= 2.0.1)
    bcrypt (3.1.11)
    benchmark-ips (2.7.2)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    bootstrap-sass (3.3.6)
      autoprefixer-rails (>= 5.2.1)
      sass (>= 3.3.4)
    builder (3.2.3)
    byebug (9.0.6)
    choice (0.2.0)
    chosen-rails (1.5.2)
      coffee-rails (>= 3.2)
      railties (>= 3.0)
      sass-rails (>= 3.2)
    codeclimate-test-reporter (1.0.4)
      simplecov
    coffee-rails (4.1.0)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.12.2)
    concurrent-ruby (1.0.4)
    connection_pool (2.2.1)
    crack (0.4.3)
      safe_yaml (~> 1.0.0)
    daemons (1.2.4)
    database_cleaner (1.5.3)
    debug_inspector (0.0.2)
    derailed (0.1.0)
      derailed_benchmarks
    derailed_benchmarks (1.3.2)
      benchmark-ips (~> 2)
      get_process_mem (~> 0)
      heapy (~> 0)
      memory_profiler (~> 0)
      rack (>= 1)
      rake (> 10, < 13)
      thor (~> 0.19)
    devise (4.0.0)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 4.1.0, < 5.1)
      responders
      warden (~> 1.2.3)
    diff-lcs (1.2.5)
    docile (1.1.5)
    domain_name (0.5.20161129)
      unf (>= 0.0.5, < 1.0.0)
    erubis (2.7.0)
    eventmachine (1.0.9.1)
    execjs (2.7.0)
    factory_girl (4.0.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.0.0)
      factory_girl (~> 4.0.0)
      railties (>= 3.0.0)
    faker (1.7.2)
      i18n (~> 0.5)
    faraday (0.11.0)
      multipart-post (>= 1.2, < 3)
    figaro (1.1.1)
      thor (~> 0.14)
    flamegraph (0.9.5)
    font-awesome-rails (4.7.0.1)
      railties (>= 3.2, < 5.1)
    get_process_mem (0.2.1)
    gettext (3.1.7)
      locale (>= 2.0.5)
      text (>= 1.3.0)
    globalid (0.3.7)
      activesupport (>= 4.1.0)
    haml (4.0.7)
      tilt
    hashdiff (0.3.2)
    heapy (0.1.2)
    htmlentities (4.3.4)
    http-cookie (1.0.3)
      domain_name (~> 0.5)
    i18n (0.7.0)
    jquery-rails (4.1.1)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (5.0.5)
      railties (>= 3.2.16)
    json (1.8.6)
    kaminari (0.17.0)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
    kgio (2.11.0)
    libv8 (3.16.14.17)
    locale (2.1.2)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.4)
      mime-types (>= 1.16, < 4)
    mailcatcher (0.6.5)
      eventmachine (= 1.0.9.1)
      mail (~> 2.3)
      rack (~> 1.5)
      sinatra (~> 1.2)
      skinny (~> 0.2.3)
      sqlite3 (~> 1.3)
      thin (~> 1.5.0)
    memory_profiler (0.9.7)
    mime-types (3.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0521)
    mini_portile2 (2.1.0)
    minitest (5.10.1)
    multipart-post (2.0.0)
    nested_form (0.3.2)
    netrc (0.11.0)
    nokogiri (1.7.0.1)
      mini_portile2 (~> 2.1.0)
    orm_adapter (0.5.0)
    pg (0.18.4)
    public_suffix (2.0.5)
    rack (1.6.5)
    rack-mini-profiler (0.10.1)
      rack (>= 1.2.0)
    rack-pjax (0.8.0)
      nokogiri (~> 1.5)
      rack (~> 1.1)
    rack-protection (1.5.3)
      rack
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.7.1)
      actionmailer (= 4.2.7.1)
      actionpack (= 4.2.7.1)
      actionview (= 4.2.7.1)
      activejob (= 4.2.7.1)
      activemodel (= 4.2.7.1)
      activerecord (= 4.2.7.1)
      activesupport (= 4.2.7.1)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.7.1)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.8)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-erd (1.5.0)
      activerecord (>= 3.2)
      activesupport (>= 3.2)
      choice (~> 0.2.0)
      ruby-graphviz (~> 1.2)
    rails-html-sanitizer (1.0.3)
      loofah (~> 2.0)
    rails4-autocomplete (1.1.1)
      rails (>= 3.0)
    rails_12factor (0.0.3)
      rails_serve_static_assets
      rails_stdout_logging
    rails_admin (0.8.1)
      builder (~> 3.1)
      coffee-rails (~> 4.0)
      font-awesome-rails (>= 3.0, < 5)
      haml (~> 4.0)
      jquery-rails (>= 3.0, < 5)
      jquery-ui-rails (~> 5.0)
      kaminari (~> 0.14)
      nested_form (~> 0.3)
      rack-pjax (~> 0.7)
      rails (~> 4.0)
      remotipart (~> 1.0)
      safe_yaml (~> 1.0)
      sass-rails (>= 4.0, < 6)
    rails_serve_static_assets (0.0.5)
    rails_stdout_logging (0.0.5)
    railties (4.2.7.1)
      actionpack (= 4.2.7.1)
      activesupport (= 4.2.7.1)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    raindrops (0.17.0)
    rake (11.3.0)
    redis (3.3.2)
    ref (2.0.0)
    remotipart (1.3.1)
    responders (2.3.0)
      railties (>= 4.2.0, < 5.1)
    rest-client (2.0.0)
      http-cookie (>= 1.0.2, < 2.0)
      mime-types (>= 1.16, < 4.0)
      netrc (~> 0.8)
    rest-client-logger (0.0.1)
      railties (>= 3.1)
      rest-client (>= 1.6)
    rspec (3.5.0)
      rspec-core (~> 3.5.0)
      rspec-expectations (~> 3.5.0)
      rspec-mocks (~> 3.5.0)
    rspec-core (3.5.4)
      rspec-support (~> 3.5.0)
    rspec-expectations (3.5.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.5.0)
    rspec-its (1.2.0)
      rspec-core (>= 3.0.0)
      rspec-expectations (>= 3.0.0)
    rspec-mocks (3.5.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.5.0)
    rspec-rails (3.5.2)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 3.5.0)
      rspec-expectations (~> 3.5.0)
      rspec-mocks (~> 3.5.0)
      rspec-support (~> 3.5.0)
    rspec-sidekiq (2.2.0)
      rspec (~> 3.0, >= 3.0.0)
      sidekiq (>= 2.4.0)
    rspec-support (3.5.0)
    ruby-graphviz (1.2.2)
    rubyzip (1.1.7)
    safe_yaml (1.0.4)
    sass (3.4.23)
    sass-rails (5.0.6)
      railties (>= 4.0.0, < 6)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (>= 1.1, < 3)
    sentry-raven (0.15.6)
      faraday (>= 0.7.6)
    shoulda-matchers (3.1.1)
      activesupport (>= 4.0.0)
    sidekiq (4.1.1)
      concurrent-ruby (~> 1.0)
      connection_pool (~> 2.2, >= 2.2.0)
      redis (~> 3.2, >= 3.2.1)
    simple_form (3.2.1)
      actionpack (> 4, < 5.1)
      activemodel (> 4, < 5.1)
    simplecov (0.12.0)
      docile (~> 1.1.0)
      json (>= 1.8, < 3)
      simplecov-html (~> 0.10.0)
    simplecov-html (0.10.0)
    sinatra (1.4.7)
      rack (~> 1.5)
      rack-protection (~> 1.4)
      tilt (>= 1.3, < 3)
    skinny (0.2.4)
      eventmachine (~> 1.0.0)
      thin (>= 1.5, < 1.7)
    slim (3.0.6)
      temple (~> 0.7.3)
      tilt (>= 1.3.3, < 2.1)
    spring (2.0.0)
      activesupport (>= 4.2)
    sprockets (3.7.1)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.0)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    sqlite3 (1.3.13)
    stackprof (0.2.10)
    temple (0.7.7)
    text (1.3.1)
    therubyracer (0.12.2)
      libv8 (~> 3.16.14.0)
      ref
    thin (1.5.1)
      daemons (>= 1.0.9)
      eventmachine (>= 0.12.6)
      rack (>= 1.0.0)
    thor (0.19.4)
    thread_safe (0.3.5)
    tilt (2.0.5)
    translation (1.6)
      gettext (= 3.1.7)
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uglifier (3.0.0)
      execjs (>= 0.3.0, < 3)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.7.2)
    unicorn (5.1.0)
      kgio (~> 2.6)
      raindrops (~> 0.7)
    warden (1.2.6)
      rack (>= 1.0)
    web-console (2.0.0)
      activemodel (~> 4.0)
      binding_of_caller (>= 0.7.2)
      railties (~> 4.0)
      sprockets-rails (>= 2.0, < 4.0)
    webmock (2.3.2)
      addressable (>= 2.3.6)
      crack (>= 0.3.2)
      hashdiff
    will_paginate (3.1.0)
    will_paginate-bootstrap (1.0.1)
      will_paginate (>= 3.0.3)

PLATFORMS
  ruby

DEPENDENCIES
  annotate
  awesome_print (= 1.6.1)
  axlsx (= 2.1.0.pre)
  axlsx_rails
  bootstrap-sass (= 3.3.6)
  byebug
  chosen-rails
  codeclimate-test-reporter (~> 1.0.0)
  coffee-rails (= 4.1.0)
  database_cleaner
  derailed
  devise (= 4.0.0)
  dhis2!
  factory_girl_rails (= 4.0)
  faker
  figaro (= 1.1.1)
  flamegraph
  jquery-rails (= 4.1.1)
  jquery-ui-rails
  mailcatcher
  memory_profiler
  pg (= 0.18.4)
  rack-mini-profiler
  rails (= 4.2.7.1)
  rails-erd
  rails4-autocomplete
  rails_12factor (= 0.0.3)
  rails_admin (= 0.8.1)
  rest-client (= 2.0.0)
  rest-client-logger
  rspec-its
  rspec-rails (~> 3.0)
  rspec-sidekiq (~> 2.2.0)
  rubyzip (~> 1.1.0)
  sass-rails (= 5.0.6)
  sentry-raven (= 0.15.6)
  shoulda-matchers
  sidekiq (= 4.1.1)
  simple_form (= 3.2.1)
  simplecov
  sinatra
  slim (= 3.0.6)
  spring
  stackprof
  therubyracer (= 0.12.2)
  translation (= 1.6)
  uglifier (= 3.0.0)
  unicorn (= 5.1.0)
  web-console (= 2.0)
  webmock
  will_paginate (= 3.1.0)
  will_paginate-bootstrap (= 1.0.1)

RUBY VERSION
   ruby 2.3.0p0

BUNDLED WITH
   1.13.7

捆绑安装结果:

Using rake 11.3.0
Using i18n 0.7.0
Using json 1.8.6
Using minitest 5.10.1
Using thread_safe 0.3.5
Using builder 3.2.3
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 1.6.5
Using mime-types-data 3.2016.0521
Using arel 6.0.4
Using public_suffix 2.0.5
Using execjs 2.7.0
Using awesome_print 1.6.1
Using htmlentities 4.3.4
Using rubyzip 1.1.7
Using bcrypt 3.1.11
Using benchmark-ips 2.7.2
Using debug_inspector 0.0.2
Using sass 3.4.23
Using byebug 9.0.6
Using choice 0.2.0
Using coffee-script-source 1.12.2
Using thor 0.19.4
Using concurrent-ruby 1.0.4
Using tilt 2.0.5
Using docile 1.1.5
Using simplecov-html 0.10.0
Using connection_pool 2.2.1
Using safe_yaml 1.0.4
Using daemons 1.2.4
Using database_cleaner 1.5.3
Using get_process_mem 0.2.1
Using heapy 0.1.2
Using memory_profiler 0.9.7
Using orm_adapter 0.5.0
Using unf_ext 0.0.7.2
Using netrc 0.11.0
Using diff-lcs 1.2.5
Using eventmachine 1.0.9.1
Using multipart-post 2.0.0
Using flamegraph 0.9.5
Using locale 2.1.2
Using text 1.3.1
Using hashdiff 0.3.2
Using kgio 2.11.0
Using libv8 3.16.14.17
Using sqlite3 1.3.13
Using nested_form 0.3.2
Using pg 0.18.4
Using bundler 1.13.7
Using ruby-graphviz 1.2.2
Using rails_serve_static_assets 0.0.5
Using rails_stdout_logging 0.0.5
Using remotipart 1.3.1
Using raindrops 0.17.0
Using redis 3.3.2
Using ref 2.0.0
Using rspec-support 3.5.0
Using temple 0.7.7
Using stackprof 0.2.10
Using will_paginate 3.1.0
Using faker 1.7.2
Using tzinfo 1.2.2
Using nokogiri 1.7.0.1
Using rack-test 0.6.3
Using warden 1.2.6
Using rack-protection 1.5.3
Using rack-mini-profiler 0.10.1
Using mime-types 3.1
Using addressable 2.5.0
Using autoprefixer-rails 6.6.1
Using uglifier 3.0.0
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using figaro 1.1.1
Using sprockets 3.7.1
Using haml 4.0.7
Using simplecov 0.12.0
Using crack 0.4.3
Using derailed_benchmarks 1.3.2
Using unf 0.1.4
Using thin 1.5.1
Using faraday 0.11.0
Using gettext 3.1.7
Using rails_12factor 0.0.3
Using unicorn 5.1.0
Using sidekiq 4.1.1
Using therubyracer 0.12.2
Using rspec-core 3.5.4
Using rspec-expectations 3.5.0
Using rspec-mocks 3.5.0
Using slim 3.0.6
Using will_paginate-bootstrap 1.0.1
Using activesupport 4.2.7.1
Using loofah 2.0.3
Using axlsx 2.1.0.pre
Using rack-pjax 0.8.0
Using sinatra 1.4.7
Using mail 2.6.4
Using bootstrap-sass 3.3.6
Using codeclimate-test-reporter 1.0.4
Using webmock 2.3.2
Using derailed 0.1.0
Using domain_name 0.5.20161129
Using skinny 0.2.4
Using sentry-raven 0.15.6
Using translation 1.6
Using rspec-its 1.2.0
Using rspec 3.5.0
Using rails-deprecated_sanitizer 1.0.3
Using globalid 0.3.7
Using activemodel 4.2.7.1
Using factory_girl 4.0.0
Using shoulda-matchers 3.1.1
Using spring 2.0.0
Using rails-html-sanitizer 1.0.3
Using http-cookie 1.0.3
Using mailcatcher 0.6.5
Using rspec-sidekiq 2.2.0
Using rails-dom-testing 1.0.8
Using activejob 4.2.7.1
Using activerecord 4.2.7.1
Using rest-client 2.0.0
Using actionview 4.2.7.1
Using annotate 2.7.1
Using rails-erd 1.5.0
Using dhis2 2.2.1 from git://github.com/BLSQ/dhis2.git (at master@d91e3eb)
Using actionpack 4.2.7.1
Using actionmailer 4.2.7.1
Using axlsx_rails 0.5.0
Using railties 4.2.7.1
Using sprockets-rails 3.2.0
Using kaminari 0.17.0
Using simple_form 3.2.1
Using coffee-rails 4.1.0
Using responders 2.3.0
Using factory_girl_rails 4.0.0
Using font-awesome-rails 4.7.0.1
Using jquery-rails 4.1.1
Using jquery-ui-rails 5.0.5
Using rest-client-logger 0.0.1
Using rspec-rails 3.5.2
Using sass-rails 5.0.6
Using rails 4.2.7.1
Using web-console 2.0.0
Using devise 4.0.0
Using chosen-rails 1.5.2
Using rails4-autocomplete 1.1.1
Using rails_admin 0.8.1
Bundle complete! 52 Gemfile dependencies, 150 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

2 个答案:

答案 0 :(得分:0)

gemfile所需的版本是json 1.8.6,它比你已经拥有的json 2.0.2旧,你可以试试这个

gem 'json', '1.8.6'

降级到json 1.8.6,可能会有所帮助。

答案 1 :(得分:0)

问题

很可能,Gemfile中包含json gem的行如下所示:

gem 'json', '~> 2.0', '>= 2.0.3'

或类似的东西。这告诉你需要特定版本的json gem,并且gem必须介于版本2.0.3和2.1之间。您获得的错误表明rails期望更早版本的gem。

解决方案

删除版本指示符,以便Gemfile中的json行如下所示:

gem 'json', '~> 1.8', '>= 1.8.6'

如果这不起作用,那么试试这个:

gem 'json'

修改Gemfile后忘记运行bundle install