如何将rspec 2测试组织为“单元”(快速)和“集成”(慢)类别?
rspec命令运行所有单元测试,而不是使用“集成”测试。发布于 2012-04-05 13:26:28
我们有相同性质的群体。然后,我们在本地的开发框和CI上一个一个地运行。
你可以简单的做
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发布于 2012-04-05 13:18:53
一种方法是标记您的RSpec测试用例,如下所示:
it "should do some integration test", :integration => true do
# something
end当您执行您的测试用例时,请使用以下代码:
rspec . --tag integration这将使用标记:integration => true执行所有测试用例。有关更多信息,请参阅此页面。
发布于 2014-02-22 19:59:20
我必须按照以下方式配置我的unit和feature测试:
require 'rspec/rails'
namespace :spec do
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = Dir['spec/*/**/*_spec.rb'].reject{ |f| f['/features'] }
end
RSpec::Core::RakeTask.new(:feature) do |t|
t.pattern = "spec/features/**/*_spec.rb"
end
end必须在@KensoDev给出的答案中添加require 'rspec/rails'并将Rspec更改为RSpec。
https://stackoverflow.com/questions/10029250
复制相似问题