【发布时间】:2011-12-05 14:15:00
【问题描述】:
我正在使用rails-rspec gem,我有几个规格(模型、控制器等)。当我跑步时:
bundle exec rake
一切都经过测试。但是,我想在数据库创建后(在测试环境中)通过播种一些数据(来自 db/seeds.rb)来改进我的规范。
我的 spec/spec_helper.rb 文件如下所示:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'ruby-debug'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
config.include SpecHelper
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
stub_xmpp_rest_client!
end
config.after(:each) do
DatabaseCleaner.clean
end
config.include Devise::TestHelpers, :type => :controller
config.include Delorean
config.after(:each) { back_to_the_present }
config.include Factory::Syntax::Methods
config.extend ControllerMacros, :type => :controller
end
最好的方法是什么?谢谢。
【问题讨论】:
标签: ruby-on-rails-3 testing rspec rake