मेरे पास मेरे रेल 3.1 एप्लिकेशन में निम्न spec_helper.rb फ़ाइल है। मैं परीक्षण के लिए पर्यावरण को तेजी से लोड करने के लिए स्पार्क का उपयोग कर रहा हूं। मेरे सभी परीक्षण मिश्रण में स्पार्क जोड़ने से पहले काम करते थे। स्पार्क जोड़ने के बाद, परीक्षण डेटाबेस के बीच टेस्ट डेटाबेस को ठीक से साफ़ नहीं किया जा रहा था, जिसने मेरी कुछ उम्मीदों को फेंक दिया था।स्पार्क, आरएसपीसी और डेटाबेस_कलैनर विकास डेटाबेस को नष्ट कर रहे हैं
अन्य निर्देशों के बाद, मैंने नीचे सूचीबद्ध कोड के साथ मिश्रण में डेटाबेस_क्लेनर जोड़ा; हालांकि, अब, विकास डेटाबेस साफ-सफाई के साथ-साथ परीक्षण डेटाबेस भी हो रहा है। ENV ["RAILS_ENV"] कॉल इस कॉल के दौरान परीक्षण लौटा रही है।
क्या डाटाबेसCleaner.clean_with (: truncation) के लिए केवल कॉल डेटाबेस को प्रभावित करने के लिए कॉल को स्पष्ट रूप से सीमित करने का कोई तरीका है?
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'shoulda/matchers/integrations/rspec'
require 'database_cleaner'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :mocha
config.formatter = 'documentation'
config.use_transactional_fixtures = true
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
end
Spork.each_run do
FactoryGirl.reload
end
अपडेट: (: प्रत्येक) यहाँ मेरी database.yml फ़ाइल
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
इसके अलावा, मैं पहले में clean_with कॉल ले जाकर बुनियादी समस्या को हल काम किया है है अनुभाग, लेकिन यह धीमा परीक्षण महत्वपूर्ण रूप से चलता है।
आपका 'Database.yml' क्या है? – Bohdan
जानकारी को शामिल करने के लिए प्रश्न को अपडेट किया गया –
मुझे भी एक ही समस्या का सामना करना पड़ रहा है, वर्तमान में मैं ऐसी चीजों को रोकने के लिए 'RAILS_ENV = test bundle exec rake spec' का उपयोग करता हूं। – subosito