/ / Rails 3.2: Przełączanie z Rspec na Test :: Unit - ruby-on-rails-3.2, rspec-rails, testunit

Railsy 3.2: Przełączanie z Rspec na Test :: Unit - ruby-on-rails-3.2, rspec-rails, testunit

Stworzyłem nową aplikację Rails 3.2.x z opcją -T bez testów, ponieważ chciałem użyć Rspec do testowania.

Teraz chcę przywrócić go do Test :: Unit. Jak mogę to zrobić, że wszystkie zadania rake działają, a nowe scaffolds są generowane z Test :: Unit zamiast powłok testowych RSpec?

Odpowiedzi:

3 dla odpowiedzi № 1

Po przeszukiwaniu i hakowaniu, oto, co sprawiło, że zadziałało to dla mnie.

  1. Usuń rspec i rspec-rails z Gemfile
  2. Uruchom "gem list rspec --local" i wykonaj "gem uninstall" dla każdego z tych klejnotów rspec.
  3. Usuń Gemfile.lock
  4. rm -r spec /
  5. instalacja pakietu
  6. test mkdir /
  7. Dodaj "require" rail / all "" do config / application.rb
  8. Utwórz test pliku / test_helper.rb i umieść w nim następujący kod:

    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
    

Następnie możesz wygenerować testy za pomocą

rails g integration_test SomeStories

Lub możesz po prostu dodać testy jednostkowe w ramach testu / jednostki, a następnie je uruchomić

rake test
rake test:recent