0

我继承了一些我试图在 Rails 3.0 应用程序上运行的 RSpec,但我遇到了一些问题。出于某种原因,RSpecs 在我的开发数据库而不是我的测试数据库上运行。我究竟做错了什么?

我在 cmd 行中调用我的规范(在 Windows 中):

bundle exec rspec foo_controller_spec.rb

我的宝石文件:

group :development, :test do
  gem 'rspec-rails'
end

group :test do  
  gem 'rspec'
  gem 'webrat'
  gem 'pickle'
  gem 'shoulda'
  gem 'shoulda-matchers'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'factory_girl_rails'
  gem 'launchy'
  gem "mocha", :require => false
  gem 'fixture_builder'
  gem 'ZenTest'
  gem 'assert_difference'
  gem 'database_cleaner'
  gem 'term-ansicolor'
  gem 'spork'
  gem 'assert_difference'
end

spec_helper.rb

require 'rubygems'
require 'spork'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'capybara/rspec'
  require 'fixture_builder'
  require 'database_cleaner'
  require "authlogic/test_case" 
  require 'chargify_api_ares'
  require 'term/ansicolor'

    Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
    DatabaseCleaner.strategy = :truncation

    RSpec.configure do |config|
      config.mock_with :rspec
      config.color_enabled = true
      config.include AssertDifference
      config.include Webrat::HaveTagMatcher
      config.fixture_path = "#{::Rails.root}/spec/fixtures"
      config.include Devise::TestHelpers, :type => :controller
      config.use_transactional_fixtures = true
      config.include AssertDifference
      config.include(MailerMacros)
      config.before(:each) { reset_email }

      config.before(:suite) do
        DatabaseCleaner.strategy = :transaction
        DatabaseCleaner.clean_with(:deletion)
      end

      config.before(:each) do
        DatabaseCleaner.start
      end

      config.after(:each) do
        DatabaseCleaner.clean
      end
    end
end

 Spork.each_run do
 end
4

1 回答 1

0

你有没有尝试过?

rake spec

这是在 Rails 项目中运行 RSpec 的方式(至少通常如此)。

或者

rake spec:controllers

例如,仅运行与您的控制器相关的规范

于 2012-04-20T19:59:00.363 回答