【发布时间】:2014-05-07 16:28:49
【问题描述】:
我正在通过 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:in 'block in replace_gem':can't activate bcrypt-ruby ~3.0.0),已经激活 bcrypt-ruby-3.1.5-x86-mingw32。确保将所有依赖项添加到 Gemfile。 (Gem::LoadError)
在 Gemfile lock 中有几行:
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'
【问题讨论】:
-
你需要从这里安装开发工具包github.com/oneclick/rubyinstaller/wiki/development-kit然后你试试
gem install bcrypt-ruby -
bcrypt-ruby gem 已更名为 bcrypt。您应该安装“bcrypt”,而不是安装“bcrypt-ruby”。请相应地更新您的依赖项。我应该如何更新这些依赖项?
-
bcrypt 和 bcrypt-ruby 两个 gem 都存在,想你想用哪个rubygems.org/gems/bcrypt-ruby
-
因为我是 RoR 领域的新手,我现在尝试的只是一步一步按照 Hartl 教程进行操作,然后我希望正确安装 bcrypt-ruby 3.1.2 并且
rspec spec/会通过测试:) -
OK - 我自己终于找到了解决方案:Gemfile 应该有
gem 'bcrypt-ruby', '~>3.0.0'。
标签: ruby-on-rails rspec gem