我正在使用Michael Hartl的Ruby on Rails Tutorial来学习Rails。我在3.2.2节(测试驱动开发)中,当我运行以下命令来运行rspec测试时:
$ bundle exec rspec spec / requests / static_pages_spec.rb
我收到以下错误:
c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/childprocess-0.5.1/lib/childprocess/windows.rb:1:in `require': cannot load such file -- ffi (LoadError) from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/childprocess-0.5.1/lib/childprocess/windows.rb:1:in `<top (required)>' from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/childprocess-0.5.1/lib/childprocess.rb:176:in `require'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/childprocess-0.5.1/lib/childprocess.rb:176:in `<top (required)>'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver.rb:1:in `require'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver.rb:1:in `<top (required)>'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.35.1/lib/selenium-webdriver.rb:1:in `require'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.35.1/lib/selenium-webdriver.rb:1:in `<top (required)>'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from d:/source/training/ruby/railstutorial/sample_app/config/application.rb:12:in `<top (required)>'
from d:/source/training/ruby/railstutorial/sample_app/config/environment.rb:2:in `require'
from d:/source/training/ruby/railstutorial/sample_app/config/environment.rb:2:in `<top (required)>'
from d:/source/training/ruby/railstutorial/sample_app/spec/spec_helper.rb:3:in `require'
from d:/source/training/ruby/railstutorial/sample_app/spec/spec_helper.rb:3:in `<top (required)>'
from d:/source/training/ruby/railstutorial/sample_app/spec/requests/static_pages_spec.rb:1:in `require'
from d:/source/training/ruby/railstutorial/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
这是我的Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.3'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '~> 2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
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
这是我的static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit 'static_pages/home'
expect(page).to have_content('Sample App')
end
end
end
当我评论这一行时
#require 'spec_helper'
然后出现红色失败的测试,但有一些错误,说它无法识别某些功能,如访问。 我尝试安装错误信息表示无法加载的ffi,但仍然是,我收到了这个错误。
Os: Windows 7 x64 有什么帮助吗?
由于
答案 0 :(得分:1)
根据此https://github.com/ffi/ffi/issues/176,您应该将其安装为
gem install ffi --platform=ruby
答案 1 :(得分:0)
每次找到时,都必须在gemfile.lock中替换del X86 for X64。例如,您必须将此 ffi(1.9.3-x86-mingw32)替换为此 ffi(1.9.3-x64-mingw32)。
进行这些更改后,保存gemfile.lock并捆绑安装
答案 2 :(得分:0)
如果以上解决方案都不起作用,请尝试在gem文件中明确声明gem。它对黄瓜有用。
gem 'ffi'
注意:您可能仍需要按照MikeZ提到的安装gem
gem install ffi --platform=ruby