Rspec에서 특정 테스트만 실행하려면 어떻게 해야 합니까?
주어진 레이블로 테스트만 실행하는 방법이 있다고 생각합니다.아는 사람?
예제에 태그를 지정할 수 있습니다.:focus
해시 특성.예를들면,
# spec/foo_spec.rb
RSpec.describe Foo do
it 'is never executed' do
raise "never reached"
end
it 'runs this spec', focus: true do
expect(1).to eq(1)
end
end
rspec --tag focus spec/foo_spec.rb
GitHub에 대한 자세한 정보.(더 나은 링크를 가진 고객에게 조언을 부탁합니다.)
(업데이트)
이제 Rspec은 relishapp.com 에서 완벽하게 문서화되었습니다.자세한 내용은 --tag 옵션 섹션을 참조하십시오.
v2.6부터 이러한 태그는 구성 옵션을 포함하여 훨씬 더 쉽게 표현할 수 있습니다.treat_symbols_as_metadata_keys_with_true_values
이를 통해 다음 작업을 수행할 수 있습니다.
describe "Awesome feature", :awesome do
어디에:awesome
마치 그런 것처럼 취급됩니다.:awesome => true
.
또한 RSpec이 자동으로 '집중' 테스트를 실행하도록 구성하는 방법은 다음 답변을 참조하십시오.이것은 특히 가드와 잘 작동합니다.
--example(또는 -e) 옵션을 사용하여 특정 문자열이 포함된 모든 테스트를 실행할 수 있습니다.
rspec spec/models/user_spec.rb -e "User is admin"
저는 그것을 가장 많이 사용합니다.
RSpec이 에서 구성되어 있는지 확인합니다.spec_helper.rb
주의를 기울이는focus
:
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
그런 다음 사양에 다음을 추가합니다.focus: true
주장으로서:
it 'can do so and so', focus: true do
# This is the only test that will run
end
또한 변경하여 테스트에 초점을 맞출 수 있습니다.it
로.fit
(또는 를 사용한 테스트 제외)xit
), 예를 들어 다음과 같습니다.
fit 'can do so and so' do
# This is the only test that will run
end
또는 라인 번호를 전달할 수 있습니다.rspec spec/my_spec.rb:75
라인 번호는 단일 사양 또는 컨텍스트/콘텍스트 블록을 가리킬 수 있습니다(해당 블록에서 모든 사양 실행).
여러 줄 번호를 콜론과 함께 문자열로 묶을 수도 있습니다.
$ rspec ./spec/models/company_spec.rb:81:82:83:103
출력:
Run options: include {:locations=>{"./spec/models/company_spec.rb"=>[81, 82, 83, 103]}}
RSpec 2.4(아마도) 기준으로 다음을 추가할 수 있습니다.f
또는x
로.it
,specify
,describe
그리고.context
:
fit 'run only this example' do ... end
xit 'do not run this example' do ... end
http://rdoc.info/github/rspec/rspec-core/RSpec/Core/ExampleGroup#fit-class_method http://rdoc.info/github/rspec/rspec-core/RSpec/Core/ExampleGroup#xit-class_method
반드시 가지고 있어야 합니다.config.filter_run focus: true
그리고.config.run_all_when_everything_filtered = true
당신의spec_helper.rb
.
최신 버전의 RSpec에서는 지원을 구성하는 것이 훨씬 쉽습니다.fit
:
# spec_helper.rb
# PREFERRED
RSpec.configure do |c|
c.filter_run_when_matching :focus
end
# DEPRECATED
RSpec.configure do |c|
c.filter_run focus: true
c.run_all_when_everything_filtered = true
end
참조:
https://relishapp.com/rspec/rspec-core/docs/filtering/filter-run-when-matching
https://relishapp.com/rspec/rspec-core/v/3-7/docs/configuration/run-all-when-everything-filtered
또한 다음과 같은 사양을 실행할 수 있습니다.focus: true
부전승으로
spec/spec_message.message
RSpec.configure do |c|
c.filter_run focus: true
c.run_all_when_everything_filtered = true
end
그런 다음 간단히 실행합니다.
$ rspec
집중 테스트만 실행됩니다.
제거할 때focus: true
모든 테스트가 다시 정상적으로 실행됩니다.
더 많은 정보: https://www.relishapp.com/rspec/rspec-core/v/2-6/docs/filtering/inclusion-filters
다음과 같이 실행할 수 있습니다.rspec spec/models/user_spec.rb -e "SomeContext won't run this"
.
다음을 사용하여 모든 메타데이터에서 간단히 실행할 수 있습니다.filter_run_including
그리고.filter_run_excluding
더 많은 유연성을 제공합니다.
예를 들어, 아래 라인에서는 레일 시스템 테스트만 실행할 수 있습니다.
config.filter_run_including type: :system
그리고 이 라인은 레일 시스템 테스트를 제외한 모든 것을 실행할 수 있습니다.
config.filter_run_excluding type: :system
언급URL : https://stackoverflow.com/questions/5069677/how-do-i-run-only-specific-tests-in-rspec
'programing' 카테고리의 다른 글
Oracle varchar2의 문자열 16진수 값을 표시하시겠습니까? (0) | 2023.06.10 |
---|---|
입력 텍스트 상자에서 값 가져오기 (0) | 2023.05.31 |
node.js 앱을 백그라운드 서비스로 실행하려면 어떻게 해야 합니까? (0) | 2023.05.31 |
하위 프로세스 호출에서 종료 코드 및 stderr 가져오기 (0) | 2023.05.31 |
NSZombie란 무엇입니까? (0) | 2023.05.31 |