2015-12-23 20 views
0

我有水豚,當我運行我的精選測試提出了一個錯誤,它說測試環境中的待定遷移,但是當運行其他類型的測試一切都很好。我已經在測試環境中運行了所有的遷移,我已經在測試和開發環境中運行rails。我如何設置水豚與鐵軌4

這是我的Gemfile

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

謝謝!

UPDATE:

我只是嘗試使用這個命令:

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

一切都確定了該命令。然後,我跑我的服務器: rails s -e test

在我的瀏覽器

同樣的錯誤, 「的ActiveRecord :: PendingMigrationError」 http://localhost:3000/

然後我跑遷移命令 斌/耙分貝:遷移RAILS_ENV =測試

但它提出了一個錯誤「ActiveRecord :: StatementInvalid:PG :: DuplicateTable:ERROR:relation」users「already exists」

和我運行功能測試時出現同樣的錯誤。

這裏是我的助手:https://gist.github.com/israelb/e2f4b10ba5f94e1e8df2

+0

能否請您提供您的'rails_helper.rb'和' spec_helper.rb'? – jverban

+0

運行建議的bin/rake數據庫會發生什麼情況:migrate RAILS_ENV = tests? –

+0

爲什麼你甚至在測試環境中運行'rails s'? O_o –

回答

0

可能會有某種形式的遷移問題。試試rake db:test:prepare看看是否有幫助。

+0

它沒有工作,謝謝! –

0

我找到了解決辦法,我在我的config /環境/ 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