Cucumber Rails 3.1 uninitialized constant ActionCo

2019-01-27 23:19发布

I am using a Rails 3.1 application and I was integrating cucumber to my app but when i try to run it I get this strange error, can someone help me please?

Using the default profile...
uninitialized constant ActionController::Dispatcher (NameError)
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-rails-0.3.2/lib/cucumber/rails/action_controller.rb:51:in `rescue in <top (required)>'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-rails-0.3.2/lib/cucumber/rails/action_controller.rb:42:in `<top (required)>'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-rails-0.3.2/lib/cucumber/rails/world.rb:27:in `<top (required)>'
/Users/chinog9/INNKU/tacos/features/support/env.rb:11:in `<top (required)>'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/rb_support/rb_language.rb:143:in `load'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime/support_code.rb:176:in `load_file'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime/support_code.rb:78:in `block in load_files!'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime/support_code.rb:77:in `each'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime/support_code.rb:77:in `load_files!'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime.rb:137:in `load_step_definitions'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime.rb:39:in `run!'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/cli/main.rb:43:in `execute!'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/cli/main.rb:20:in `execute'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/bin/cucumber:14:in `<top (required)>'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/bin/cucumber:19:in `load'
/Users/chinog9/.rvm/gems/ruby-1.9.2-p180/bin/cucumber:19:in `<main>'

Here is my env.rb:

ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')

require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'

require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript

Capybara.default_selector = :css

ActionController::Base.allow_rescue = false


Cucumber::Rails::World.use_transactional_fixtures = true

if defined?(ActiveRecord::Base)
  begin
    require 'database_cleaner'
    DatabaseCleaner.strategy = :truncation
  rescue LoadError => ignore_if_database_cleaner_not_present
  end
end

And here is my Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.0.rc4'

gem 'sqlite3'
gem 'nifty-generators'

gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-script'
gem 'uglifier'

gem 'jquery-rails'

gem 'ruby-debug19', :require => 'ruby-debug'

group :development, :test do 
    gem 'capybara'
    gem 'database_cleaner'
    gem 'cucumber-rails'
    gem 'cucumber'
    gem 'rspec-rails', '>=2.6'
    gem 'rspec-rails-mocha'
    gem 'spork', '~> 0.9.0.rc'
    gem 'factory_girl_rails'
    gem 'launchy'
    gem "ruby-debug19"
    gem 'turn', :require => false
    gem "selenium-client"
end

gem "mocha", :group => :test

Thanks! :)

3条回答
【Aperson】
2楼-- · 2019-01-27 23:48

I had a similar issue to this and I believe its RVM that is causing the problem.

Basically its the dependencies Ruby is compiled against; using rvm notes

sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev

The above is for MRI

If any of these is not installed, then install them, then uninstall/install 1.9.2-p180

Hope that helps

查看更多
一夜七次
3楼-- · 2019-01-27 23:49

I had a same issue and solved upgrading cucumber-rails to 1.0.5. Try this in Gemfile.

gem "cucumber-rails", "1.0.5"

And rerun installer

script/rails g cucumber:install your-language --your-options
查看更多
混吃等死
4楼-- · 2019-01-27 23:55

For me the magic was require: false

gem 'cucumber-rails', '~>1.4.0', require: false
查看更多
登录 后发表回答