Ruby on rails 3.2 Rails 3.2:从Rspec切换到Test::Unit

Ruby on rails 3.2 Rails 3.2:从Rspec切换到Test::Unit,ruby-on-rails-3.2,rspec-rails,testunit,Ruby On Rails 3.2,Rspec Rails,Testunit,我创建了一个新的Rails3.2.x应用程序,它带有-T选项,用于无测试,因为我想使用Rspec进行测试 现在我想把它恢复到Test::Unit。我如何才能做到这一点,使所有的rake任务都能正常工作,并使用Test::Unit而不是RSpec Test shell生成新的框架?在搜索和黑客攻击之后,以下是它能为我工作的原因 从文件中删除rspec和rspec轨道 运行“gemlistrspec--local”,并为每个rspec gem执行“gem卸载” 删除Gemfile.lock rm-r

我创建了一个新的Rails3.2.x应用程序,它带有-T选项,用于无测试,因为我想使用Rspec进行测试


现在我想把它恢复到Test::Unit。我如何才能做到这一点,使所有的rake任务都能正常工作,并使用Test::Unit而不是RSpec Test shell生成新的框架?

在搜索和黑客攻击之后,以下是它能为我工作的原因

  • 从文件中删除rspec和rspec轨道
  • 运行“gemlistrspec--local”,并为每个rspec gem执行“gem卸载”
  • 删除Gemfile.lock
  • rm-r规格/
  • 捆绑安装
  • mkdir试验/
  • 将“require'rails/all'”添加到config/application.rb
  • 创建文件test/test_helper.rb,并将以下代码放入其中:

    ENV["RAILS_ENV"] = "test"
    require File.expand_path('../../config/environment', __FILE__)
    require 'active_support'
    require 'rails/test_help'
    # require 'factory_girl_rails'  #use if you are using FactoryGirl for fixtures
    
    class ActiveSupport::TestCase
      # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
      #
      # Note: You'll currently still have to declare fixtures explicitly in integration tests
      # -- they do not yet inherit this setting 
      fixtures :all
    
      # Add more helper methods to be used by all tests here...
    end
    
  • 之后,您可以使用

    rails g integration_test SomeStories
    
    或者您可以在test/unit下添加单元测试,然后使用

    rake test
    rake test:recent