Programing

Ruby on Rails : test_unit에서 rspec으로 전환

crosscheck 2020. 11. 3. 07:38
반응형

Ruby on Rails : test_unit에서 rspec으로 전환


사용을 제안한 튜토리얼을 진행하고 rspec있지만 이미 많은 기본 레일 설치를 거쳤습니다. 설치를 다시 할 필요가 전혀 없습니다. 어쨌든 내가 달리면

$ rails g integration_test named

나는 얻다

  invoke  test_unit
  create    test/integration/named_test.rb

실행 bundle하면 다양한 rspec보석이 나열되지만 나열 test_unit되지 않습니다. 튜토리얼은 추가 작업을 수행하지 않고 레일을 호출 rspec하는 것 같습니다 test_unit. rspec통합 테스트 생성기 명령과 함께 사용할 레일을 얻으려면 어떻게해야 합니까?


당신에 config/application.rb파일 :

config.generators do |g|
  g.test_framework :rspec
end

이제 생성기를 실행하면 (예제 rails generate scaffold post) rspec 테스트 파일이 생성됩니다. 서버를 다시 시작해야합니다. 생성기에 대한 자세한 내용은 다음을 참조하십시오.

RailsCasts # 216 Rails 3의 제너레이터

integration_test 생성기를 실제로 사용하려면 명령을 구체적으로 수정해야합니다.

rails g integration_test named --integration-tool=rspec

Rails 3.2.8rspec-rails 2.11.4로 작업하면서 내 문제가 Gemfile에 있음을 발견했습니다. 나는했다 rspec-rails:test그룹이 아니라 :development그룹. (당신이 생성 실행중인 경우를 포함) 개발 모드에서 실행에 레일 기본값 때문에, rspec-rails당신에 있어야한다 :development는 발전기에 훅하는 그룹. 일단 그것을 제자리에두면 모든 것이 잘 작동했습니다.


Rails 3.2.12부터는 다음 단계를 순서대로 따르십시오.

rails new app_name --skip-test-unit

개발, 테스트 그룹의 Gemfile에 rspec-rails 추가

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

운영 bundle install

발전기 실행

rails generate rspec:install

... 기존 테스트 디렉토리를 정리합니다.

rm -Rf $RAILS_ROOT/test    

기본 Test :: Unit 대신 RSpec을 사용하려면 먼저 다음 명령을 실행하십시오.

$ rails generate rspec:install

이 명령은 다음 폴더 / 파일을 생성합니다.

create  .rspec
create  spec
create  spec/spec_helper.rb

이제 생성기를 사용하여 컨트롤러, 모델 등과 같은 레일 구성 요소를 생성 할 때마다 해당 RSpec을 생성합니다.


오늘이 문제를 보았습니다. application.rb는 다음으로 업데이트해야합니다.

config.generators do |g|
  g.test_framework :rspec
  g.integration_tool :rspec
end

구성 / 응용 프로그램에서이 코드를 추가하십시오.

 config.generators do |g|
       g.test_framework  :rspec
       g.integration_tool :rspec
 end

1. 새로운 Rails 앱을 만들 때 TestUnit 프레임 워크를 건너 뛰거나 test_unit 디렉터리를 생성합니다.

$rails new your_app --skip-test-unit

2. your_app / config / application.rb 파일에 아래 코드를 추가합니다.

config.generators do |g| g.test_framework :rspec end

3. your_app의 Gemfile에 아래 코드를 추가합니다.

group :test, :development do gem 'rspec-rails' end 저장하고 실행 bundle install하여 rspec gem을 설치하십시오.

4. spec / 디렉토리 초기화

rails generate rspec:install

자세한 내용은 https://github.com/rspec/rspec-rails 를 참조하십시오.


What I found that I did that some of the other methods works still is to check my spelling....I had what @tovodeverett had grouping rspec-rails with :development and :test but spelt development incorrectly. That fixed my issue but I was generating tests with test_unit instead of rspec.


$ rails g model Account
      invoke  active_record
      create    db/migrate/20140205052617_create_accounts.rb
      create    app/models/account.rb
      invoke    test_unit
      create      test/models/account_test.rb
      create      test/fixtures/accounts.yml
$ rails d model Account

Running script/rails generate rspec:install does not add rspec as default framework. Added below command in config/application.rb and then it works

config.generators do |g|
  g.test_framework :rspec
end
$ rails g model Account
      invoke  active_record
      create    db/migrate/20140205052957_create_accounts.rb
      create    app/models/account.rb
      invoke    rspec
      create      spec/models/account_spec.rb
$ rails -v
Rails 4.0.2

참고URL : https://stackoverflow.com/questions/9884033/ruby-on-rails-switch-from-test-unit-to-rspec

반응형