2012-03-13 5 views
0

업데이트 : 이것은 내 데이터베이스에 관한 것이 아니라 Spree가 내 테스트에서 오염 된 메모리 캐시에 저장된 환경 설정에 관한 것으로 밝혀졌습니다. 아래 내 대답을 참조하십시오.Rspec 환경 설정 값이 바뀌고 개발 환경이 오염 됨


나는 루비 1.9.3-P0, RSpec에 레일 2.8.1, 2.8.0 RSpec에와, 레일 3.1.4에 이어지고 응용 프로그램을 실행하고 있습니다.

Rspec이 개발 시스템에서 Webrick과 이상하게 상호 작용하여 테스트 데이터베이스 사용으로 Webrick 인스턴스가 실행 중으로 전환되고 있다고 생각하게 만듭니다.

내가 내 HomeController 하나의 사양이 있습니다

require 'spec_helper' 

describe HomeController do 
    render_views 

describe "GET 'index'" do 
    it "should be successful" do 
    get 'index' 
    response.should be_success 
    end 
end 

end 

내가 내 로컬 호스트 (개발 시스템)에에 WEBrick을 부팅을 내 홈 페이지는 브라우저에서 잘 작동합니다. 인덱스 액션이 홈 페이지에 해당하는 HomeController에서 Rspec을 처음 실행할 때 내 테스트가 통과합니다.

이전에 텍스트 데이터로 채워진 데이터베이스 필드가 이제는 없기 때문에 Rspec이 실행 된 후 Webrick에서 페이지가 분리됩니다. 후속 Rspec 반복도 중단됩니다.

그래서 Rspec이 Webrick을 개발 데이터베이스를 사용하지 않고 만들고 테스트 데이터베이스를 사용하기 시작했는데 그 이유는 무엇입니까? spec_helper.rb의 라인이 ENV["RAILS_ENV"] ||= 'test'입니까?

은 (여기 내 spec_helper.rb 소독 database.yml을 :)

spec_helper.rb (나는 Spork 및 자동 측정이 설치되어있는,하지만 난 그들도 실행하고 있지 않다 때이 오류가 발생합니다.)

require 'rubygems' 
require 'spork' 
#uncomment the following line to use spork with the debugger 
#require 'spork/ext/ruby-debug' 

Spork.prefork do 
    # Loading more in this block will cause your tests to run faster. However, 
    # if you change any configuration or code from libraries loaded here, you'll 
    # need to restart spork for it take effect. 
# This file is copied to ~/spec when you run 'ruby script/generate rspec' 
# from the project root directory. 
ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 
require 'rspec/rails' 
# require 'capybara/rspec' 

# Requires supporting files with custom matchers and macros, etc, 
# in ./support/ and its subdirectories. 
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} 

#require 'factories' 

RSpec.configure do |config| 
    # == Mock Framework 
    # 
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 
    # 
    # config.mock_with :mocha 
    # config.mock_with :flexmock 
    # config.mock_with :rr 
    config.mock_with :rspec 

    config.fixture_path = "#{::Rails.root}/spec/fixtures" 

    #config.include Devise::TestHelpers, :type => :controller 
    # If you're not using ActiveRecord, or you'd prefer not to run each of your 
    # examples within a transaction, comment the following line or assign false 
    # instead of true. 
    config.use_transactional_fixtures = true 
end 

@configuration ||= AppConfiguration.find_or_create_by_name("Default configuration") 

PAYMENT_STATES = Payment.state_machine.states.keys unless defined? PAYMENT_STATES 
SHIPMENT_STATES = Shipment.state_machine.states.keys unless defined? SHIPMENT_STATES 
ORDER_STATES = Order.state_machine.states.keys unless defined? ORDER_STATES 

# Usage: 
# 
# context "factory" do 
# it { should have_valid_factory(:address) } 
# end 
RSpec::Matchers.define :have_valid_factory do |factory_name| 
    match do |model| 
    Factory(factory_name).new_record?.should be_false 
    end 
end 
end 

Spork.each_run do 
    # This code will be run each time you run your specs. 
end 
입니다

database.yml을

+0

Webrick을 재부팅 한 후에 전체 프로세스가 다시 시작된다는 것을 추가해야합니다. Webrick은 누락 된 데이터베이스 필드를 찾습니다 (아마 개발 데이터베이스에 있음). 그리고 Rspec은 하나의 반복에 대해서도 마찬가지입니다. –

+0

나는 WEBRick 대신에 Unicorn을 사용했고, 같은 오류를 재현했다 (Rspec을 두 번 실행해야했지만). –

+0

또한 Ruby 1.9.2에 문제가 있습니다. 내가 ENV [ "RAILS_ENV"] || = 'test''를 주석 처리하면, Rspec은 계속해서 통과하고 문제는 사라집니다. 그러나 그것은 옳은 대답이 될 수 없습니다! ENV [ "RAILS_ENV"] = 'test' '로 설정하면 문제가 남아 있습니다. –

답변

0

그것은이 데이터베이스와의 캐시에 저장된 환경 설정과 문제, 그리고되지 않았 음을 밝혀졌습니다.

조쉬 제이콥스는 응답 (그리고 아주 잘 설명) here

이 솔루션은 테스트 및 개발을 위해 다른 캐시 저장소를 구성하는 것입니다. test.rb에서 config.cache_store = : memory_store를 추가하고 다시 시작한 spork를 실행하면 모든 것이 작동합니다.

관련 문제