宝石文件的使用; Ruby 版本 & Rspec

Gemfile use; Ruby Version & Rspec

我想为每个 Ruby project/app 设置关联的 Ruby 版本、rspec 版本和宝石。

在大多数情况下,我将使用 Ruby 的当前版本,但对于一些应用程序,我必须使用 Ruby -1.9.3 和适当的 rspec 版本。

宝石文件

source "https://rubygems.org"

ruby '1.9.3'
gem 'rspec', "1.9.3"
gem 'json'
gem 'spreadsheet' 
gem "pdf-reader", "~> 1.3"

运行;

bundle install 

结果;

$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Could not find gem 'rspec (= 1.9.3) ruby' in the gems available on this machine

不确定从这里开始做什么。

您指定的 RSpec 版本似乎无效。尝试列出 here 之一。实际上,如果我正确阅读文档,您可能需要 1.3.2 或更早版本才能与 Ruby 1.9.3 一起使用——哦,等等……没关系!我相信我只为您抽查了依赖项就得出了一个无效的结论。

编辑:解决有关实际配置的 ruby 版本与预期版本之间断开连接的进一步问题。 Per bundler 文档 here (second to last paragraph on page) the line "ruby '1.9.3'" serves to document your expectation that the gems will be used with that specific version of ruby and bundler raises an exception when that is not the case--as you are reporting in your configuration. The Gemfile alone cannot also configure your ruby environment, but only the ruby gems. Since it is common to use various versions of Ruby, there are a few common solutions that facilitate that. Personally, I like chruby for this, but rbenv and rvm 也是流行的替代品。希望对您有所帮助!