uninitialized constant ActiveRecord(NameError) - 黄瓜和奶酪的例子

时间:2014-05-01 13:57:23

标签: ruby-on-rails ruby activerecord gem rubygems

我是红宝石的新手,并在他的书“黄瓜和奶酪”中跟随Cheezy的例子。

我的gemfile看起来像这样:

source 'https://rubygems.org'

gem 'cucumber'
gem 'rspec'
gem 'page-object'
gem 'pry-debugger'
gem 'faker'
gem 'data_magic'
gem 'debugger', '1.6.6'
gem 'require_all'
gem 'activerecord', '3.2.1'
gem 'factory_girl'
gem 'database_cleaner'
gem 'sqlite3'

我有一个名为database.rb(生活在支持下)的文件,其中包含:

require 'active_record'
require 'database_cleaner'
require 'factory_girl'
require 'sqlite3'

ActiveRecord::Base.establish_connection(
    :adapter => 'sqlite3',
    :database => '../puppies/db/development.sqlite3')

我的env.rb文件包含:

require 'rspec-expectations'
require 'page-object'
require 'page-object/page_factory'
require 'watir-webdriver'
require 'data_magic'
require 'require_all'

require_all File.dirname(__FILE__) + '/pages'

PageObject::PageFactory.routes= {
    :default => [[HomePage, :view_details_for_puppy],
    [DetailsPage, :add_to_cart],
    [ShoppingCartPage, :complete_adoption],
    [CheckoutPage, :checkout]]}

World(PageObject::PageFactory)

我的课程页面:

User.rb

class User < ActiveRecord::Base
end

Order.rb

class Order < ActiveRecord::Base
  has_many :adoption
end

User.rb

class User < ActiveRecord::Base
  has_many :adoption
end

Adoption.rb

class Adoption < ActiveRecord::Base
  belongs_to :order
  belongs_to :puppy
end

尝试运行第一个CRUD方案时出现此错误:

test_puppies_one djLaX805$ bundle exec cucumber -t @crud1

uninitialized constant ActiveRecord (NameError)
/Users/djLaX805/RubymineProjects/Learning Ruby on a MAC/test_puppies_one/features/support/pages/database/adoption.rb:1:in `<top (required)>'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/require_all-1.3.2/lib/require_all.rb:109:in `require'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/require_all-1.3.2/lib/require_all.rb:109:in `block in require_all'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/require_all-1.3.2/lib/require_all.rb:107:in `each'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/require_all-1.3.2/lib/require_all.rb:107:in `require_all'
/Users/djLaX805/RubymineProjects/Learning Ruby on a MAC/test_puppies_one/features/support/env.rb:8:in `<top (required)>'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/rb_support/rb_language.rb:95:in `load'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/rb_support/rb_language.rb:95:in `load_code_file'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/runtime/support_code.rb:180:in `load_file'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/runtime/support_code.rb:82:in `each'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/runtime.rb:184:in `load_step_definitions'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/runtime.rb:42:in `run!'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/lib/cucumber/cli/main.rb:47:in `execute!'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/gems/cucumber-1.3.14/bin/cucumber:13:in `<top (required)>'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/bin/cucumber:23:in `load'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/bin/cucumber:23:in `<main>'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/Users/djLaX805/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'

有什么想法?我按照他的方式完成了他的书。

1 个答案:

答案 0 :(得分:-1)

我几分钟前就遇到过这个问题,并通过使用它来解决它     rails g cucumber:安装 命令。