rspec 2 テストを「ユニット」(高速) と「統合」(低速) のカテゴリに分類するにはどうすればよいですか?
- コマンドだけですべての単体テストを実行できるようにしたいのです
rspec
が、「統合」テストは実行できません。 - 「統合」テストのみを実行できるようにしたい。
rspec 2 テストを「ユニット」(高速) と「統合」(低速) のカテゴリに分類するにはどうすればよいですか?
rspec
が、「統合」テストは実行できません。同じ性質のグループがあります。次に、ローカルの開発ボックスと CI の両方で 1 つずつ実行します。
あなたは簡単にできる
bundle exec rake spec:unit
bundle exec rake spec:integration
bundle exec rake spec:api
これが spec.rake の外観です
namespace :spec do
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = Dir['spec/*/**/*_spec.rb'].reject{ |f| f['/api/v1'] || f['/integration'] }
end
RSpec::Core::RakeTask.new(:api) do |t|
t.pattern = "spec/*/{api/v1}*/**/*_spec.rb"
end
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = "spec/integration/**/*_spec.rb"
end
end
これを行う1つの方法は、RSpecテストケースに次のようにタグを付けることです。
it "should do some integration test", :integration => true do
# something
end
テストケースを実行するときは、次を使用します。
rspec . --tag integration
これにより、タグが付いたすべてのテストケースが実行されます:integration => true
。詳細については、このページを参照してください。
https://github.com/rspec/rspec-railsに注意してください。gem を「group :development, :test」の下に配置するように指示されています。
group :development, :test do
gem 'rspec-rails', '~> 2.0'
end
ただし、これを :test group onlyの下にのみ配置すると、
group :test do
gem 'rspec-rails', '~> 2.0'
end
その後、上記のエラーが発生します。
HTH