如何设置带有导轨4的水豚

时间:2015-12-23 23:39:51

标签: ruby-on-rails capybara bdd

我有水豚,当我运行我的精选测试时出现错误,它说明了测试环境中的待定迁移,但是当运行其他类型的测试时,一切都很好。我已经在测试环境中运行了所有迁移,我已经在测试和开发环境中运行了。

这是我的宝石文件

group :development, :test do 
    .... other gems ....
    gem 'rspec-rails'
    gem 'factory_girl_rails'
    gem 'database_cleaner'
    gem 'capybara', '~> 2.5.0'
    gem 'capybara-webkit', '~> 1.7.1'
    gem 'selenium-webdriver'
    gem 'poltergeist'
    gem 'launchy-rails', '~> 0.0.1'
end

这是我的测试

# spec/features/sign_in_spec.rb
require 'rails_helper'

feature 'Visitor signs up' do

  it "signs me in", :type => :feature do
    visit new_user_session_path
    puts "page:    #{page.html.inspect}"    
    save_and_open_page
  end
end

enter image description here

谢谢!

更新:

我只是尝试使用此命令:

bin/rake db:drop db:create db:migrate RAILS_ENV=test 

该命令一切正常。然后我运行我的服务器: rails s -e test

我的浏览器中出现相同的错误," ActiveRecord :: PendingMigrationError" http://localhost:3000/

然后我运行migrate命令     bin / rake db:migrate RAILS_ENV = test

但它引发了一个错误" ActiveRecord :: StatementInvalid:PG :: DuplicateTable:ERROR:relation" users"已经存在"

当我运行功能测试时出现同样的错误。

以下是我的助手:https://gist.github.com/israelb/e2f4b10ba5f94e1e8df2

2 个答案:

答案 0 :(得分:0)

可能存在某种迁移问题。试试rake db:test:prepare看看是否有帮助。

答案 1 :(得分:0)

我找到了解决方案,我在config / enviroment / test.rb文件中遇到了问题,我不得不改变这个问题:

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # The test environment is used exclusively to run your application's
  # test suite. You never need to work with it otherwise. Remember that
  # your test database is "scratch space" for the test suite and is wiped
  # and recreated between test runs. Don't rely on the data there!
  config.cache_classes = true

  # Do not eager load code on boot. This avoids loading your whole application
  # just for the purpose of running a single test. If you are using a tool that
  # preloads Rails for running tests, you may have to set it to true.
  config.eager_load = false

  # Configure static file server for tests with Cache-Control for performance.
  config.serve_static_files   = true
  config.static_cache_control = 'public, max-age=3600'

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Raise exceptions instead of rendering exception templates.
  config.action_dispatch.show_exceptions = false

  # Disable request forgery protection in test environment.
  config.action_controller.allow_forgery_protection = false

  # Tell Action Mailer not to deliver emails to the real world.
  # The :test delivery method accumulates sent emails in the
  # ActionMailer::Base.deliveries array.
  config.action_mailer.delivery_method = :test

  # Randomize the order test cases are executed.
  config.active_support.test_order = :random

  # Print deprecation notices to the stderr.
  config.active_support.deprecation = :stderr

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end