rails 3.1.3 / cucumber / database_cleaner / mongo_mapper

时间:2012-02-28 12:09:23

标签: ruby-on-rails-3.1 cucumber

在这个环境中,是否还有人在运行黄瓜测试时遇到麻烦?

错误

Exception encountered by DatabaseCleaner in Cucumber After block: ActiveRecord::ConnectionNotEstablished
  ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in `retrieve_connection'
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `retrieve_connection'
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.2.1/lib/cucumber/rails/hooks/active_record.rb:6:in `connection'
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.7.1/lib/database_cleaner/active_record/truncation.rb:130:in `clean'
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.7.1/lib/database_cleaner/base.rb:77:in `clean'
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.7.1/lib/database_cleaner/configuration.rb:56:in `block in clean'
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.7.1/lib/database_cleaner/configuration.rb:56:in `each'
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.7.1/lib/database_cleaner/configuration.rb:56:in `clean'
  /home/jonas/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.2.1/lib/cucumber/rails/hooks/database_cleaner.rb:9:in `After'

功能性/支撑性/ env.rb

  7 require 'cucumber/rails'
  8 require 'database_cleaner'
  9 require 'database_cleaner/cucumber'
 10 require 'database_cleaner/mongo_mapper/truncation'
...
 41 # Remove/comment out the lines below if your app doesn't have a database.
 42 # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
 43 begin
 44   DatabaseCleaner.strategy = :truncation
 45 rescue NameError
 46   raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
 47 end

我不知道该怎么做。

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我的所有“步骤”都通过了,但由于ActiveRecord与数据库清理程序的混合,我的方案失败了。

 Scenario: User is not signed up                               # features/users/sign_in.feature:6
    Given I am not logged in                                    # features/step_definitions/user_steps.rb:86
    And no user exists with an email of "user@invalidemail.com" # features/step_definitions/user_steps.rb:1
    When I go to the sign in page                               # features/step_definitions/web_steps.rb:48
    And I sign in as "user@invalidemail.com/please"             # features/step_definitions/user_steps.rb:61
    Then I should see "Invalid email or password."              # features/step_definitions/web_steps.rb:105
    And I go to the home page                                   # features/step_definitions/web_steps.rb:48
    And I should be signed out                                  # features/step_definitions/user_steps.rb:81
  ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/cucumber-rails-1.3.0/lib/cucumber/rails/hooks/active_record.rb:6:in `connection'
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/database_cleaner-0.7.2/lib/database_cleaner/active_record/truncation.rb:130:in `clean'
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/database_cleaner-0.7.2/lib/database_cleaner/base.rb:77:in `clean'
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/database_cleaner-0.7.2/lib/database_cleaner/configuration.rb:56:in `block in clean'
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/database_cleaner-0.7.2/lib/database_cleaner/configuration.rb:56:in `each'
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/database_cleaner-    0.7.2/lib/database_cleaner/configuration.rb:56:in `clean'
      /Users/ashr/.rvm/gems/ruby-1.9.3-p0@travel/gems/cucumber-rails-    1.3.0/lib/cucumber/rails/hooks/database_cleaner.rb:9:in `After'

Failing Scenarios:
cucumber features/users/sign_in.feature:6 # Scenario: User is not signed up

1 scenario (1 failed)
7 steps (7 passed)

我在执行黄瓜测试时得到了一些提示:

$bundle exec cucumber --verbose features/users/sign_in.feature:15

WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb).

https://rspec.lighthouseapp.com/projects/16211/tickets/165(相关票证)

奇怪的是,它在前一步骤中没有失败。

spec_helper.rb

RSpec.configure do |config|
    # == Mock Framework
    config.mock_with :rspec    

    config.before(:suite) do
      DatabaseCleaner.strategy = :truncation
      DatabaseCleaner.clean_with(:truncation)
      ...
    end

    ...
    config.before(:each) do
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end
...
end

特征性/支撑性/ config.rb

Class ...
  ...
End
begin
  DatabaseCleaner.strategy = :truncation, { :except => %w[oauth_tokens client_applications] }
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

答案 1 :(得分:0)

我不得不删除DatebaseCleaner