我一直在我的应用程序中使用黄瓜,这是一个在ruby 1.8.6中运行的rails 2.2.2应用程序(升级现在不是一个选项)。黄瓜很好,现在我正在尝试使用水豚。我已经安装了capybara (1.1.1)
gem并将require 'capybara/rails'
行放在我的features/support/env.rb file
中。
现在,当我运行黄瓜时,我收到了这个错误:
Using the default profile...
uninitialized constant Rack::Builder (NameError)
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in `load_missing_constant'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in `const_missing'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/capybara-1.1.1/lib/capybara/rails.rb:4
/home/max/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
/home/max/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
/home/max/work/charanga/elearn_container/elearn/features/support/env.rb:10
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/rb_support/rb_language.rb:143:in `load'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime/support_code.rb:171:in `load_file'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime/support_code.rb:83:in `load_files!'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime/support_code.rb:82:in `each'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime.rb:137:in `load_step_definitions'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime.rb:39:in `run!'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/cli/main.rb:43:in `execute!'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/cli/main.rb:20:in `execute'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/cucumber-1.1.1/bin/cucumber:14
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/bin/cucumber:19:in `load'
/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/bin/cucumber:19
这是错误文件:
#/home/max/.rvm/gems/ruby-1.8.6-p420@elearning-resource/gems/capybara-1.1.1/lib/capybara/rails.rb
require 'capybara'
require 'capybara/dsl'
Capybara.app = Rack::Builder.new do
map "/" do
if Rails.version.to_f >= 3.0
run Rails.application
else # Rails 2
use Rails::Rack::Static
run ActionController::Dispatcher.new
end
end
end.to_app
Capybara.asset_root = Rails.root.join('public')
Capybara.save_and_open_page_path = Rails.root.join('tmp/capybara')
因此,第4行正在使用Rack::Builder.new
行创建错误。但为什么?有任何想法吗?我已经安装了Rack gem。
谢谢,最大
答案 0 :(得分:3)
尝试在require 'rack/builder'
的{{1}}之前添加require 'capybara/rails'
。低于2.3的Rails版本不会在内部使用Rack,因此不会像Capybara那样加载Rack :: Builder。
答案 1 :(得分:1)
您是否使用了cucumber-rails宝石?
https://github.com/jnicklas/capybara说,要么使用gem,要么如果你没有使用rails,请将这两行放在:
require 'capybara/cucumber'
Capybara.app = MyRackApp
答案 2 :(得分:0)
试试这个
gem install rack
require 'rack' # in features/support/env.rb before every require
Rack :: Builder在机架库中定义。