16

运行测试文件时出现以下错误。

$ruby test/test_gothonweb.rb
/Users/sony/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rack/test (LoadError)
    from /Users/sony/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from test/test_gothonweb.rb:3:in `<main>'

测试文件片段:

require_relative '../lib/gothonweb.rb'
require 'test/unit'
require 'rack/test'

ENV['RACK_ENV'] = 'test'

class GothonwebTest < Test::Unit::TestCase
    include Rack::Test::Methods

    def app
        Sinatra::Application
    end
end 

我认为 gem 已安装并且应该可用:

gem list

*** LOCAL GEMS ***

bundler (1.1.3)
rack (1.4.1)
rack-protection (1.2.0)
rake (0.9.2.2)
rubygems-bundler (0.9.0)
rvm (1.11.3.3)
sinatra (1.3.2)
tilt (1.3.3)

为什么你认为的错误?

4

2 回答 2

50

rack-test是一个单独的宝石。将其包含在您的 Gem 文件中。

于 2012-04-29T03:36:43.583 回答
0

这里有类似的问题,gem uninstall rack-test然后 bundle install 解决了这个问题。

https://github.com/brynary/rack-test/issues/123

于 2016-08-30T13:43:32.217 回答