“你的应用程序中没有安装bcrypt-ruby。”但在我看来,我有太多的版本;)(Hartl教程6.3)

时间:2014-03-28 09:38:21

标签: ruby-on-rails rspec gem

我正在学习Hartl Tutorial,我需要安装geb bcrypt-ruby。我把它添加到Gemfile

    gem 'rails', '4.0.0.rc2'
    gem 'bootstrap-sass', '2.3.2.0'
    gem 'sprockets', '2.11.0'
    gem 'bcrypt-ruby', '3.1.2'

一切似乎都没问题,但如果我开始运行rspec spec /那么我就会收到错误:

  

您的应用程序中没有安装bcrypt + ruby​​。请将它添加到您的Gemfile和rund bundle install中   D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:224:在replace_gem'中阻止:不能激活bcrypt-ruby<〜> ~3.0.0),已经激活了bcrypt-ruby-3.1.5-x86-mingw32。确保将所有依赖项添加到Gemfile。 (GEM :: LoadError)

在Gemfile锁中有行:

    bcrypt (3.1.7-x86-mingw32)
    bcrypt-ruby (3.1.5-x86-mingw32)
      bcrypt (>= 3.1.3)

我尝试删除Gemfile.lock并生成新的但没有帮助。我的ruby版本是1.9.3p429和rails 4.0.0.rc2。我的操作系统是64位Win7

热烈欢迎任何好的建议;)

完整错误:

    D:\Projects\sample_app>rspec spec\
    You don't have bcrypt-ruby installed in your application. Please add it to your
    Gemfile and run bundle install
    D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:224:in `block in replace_gem': can't activate bcrypt-ruby (~> 3.0.0), already activated bcrypt-ruby-3.1.2-x86-mingw32. Make sure all dependencies are added to Gemfile. (Gem::LoadError)
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activemodel-4.0.0.rc2/lib/active_model/secure_password.rb:47:in `has_secure_password'
    from D:/Projects/sample_app/app/models/user.rb:7:in `<class:User>'
    from D:/Projects/sample_app/app/models/user.rb:1:in `<top (required)>'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `block in require'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:213:in `load_dependency'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:329:in `require_or_load'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:462:in `load_missing_constant'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:183:in `const_missing'
    from D:/Projects/sample_app/spec/models/user_spec.rb:3:in `<top (required)>'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
    from D:/RoR/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

3 个答案:

答案 0 :(得分:0)

对于此错误,我发现从/lib/active_model/secure_password.rb删除版本的依赖项就可以了。

请确保在转移到制作时将其重新添加,以便以后不会出现其他错误

答案 1 :(得分:0)

我通过编辑

中的gem版本来修复此错误
  

/lib/active_model/secure_password.rb

gem&#39; bcrypt-ruby&#39;,&#39; 3.0.1&#39;宝石&#39; bcrypt-ruby&#39;,&#39; 3.1.5&#39;

<强>段

begin
              gem 'bcrypt-ruby', '3.1.5'
              require 'bcrypt'
            rescue LoadError
              $stderr.puts "You don't have bcrypt-ruby installed in your application. Please add it to your Gemfile and run bundle install"
              raise
            end

答案 2 :(得分:0)

我有同样的问题。我做了以下工作,然后再次工作

  1. 从Gemfile中删除bcrypt
  2. 运行bundle install
  3. 添加bcrypt返回
  4. 运行bundle install