在 Rails 中,您可以忽略 运行 中的特定测试吗?
In Rails, can you ignore specific tests from running?
我有一套 运行 的测试,但想忽略 本地 的一些测试,因为它们需要 Java 版本是不同的,并且在我的环境中一直失败。我可以忽略这些测试(无论如何我们都有集成测试)
我如何指定 Rails 不是 运行 某些测试而是 运行 所有其他测试?我只是厌倦了看到这些错误,这可能会让我错过一些合法的测试失败...
如有任何帮助,我们将不胜感激!
在 RSpec 中,可以使用排除过滤器,然后从命令行跳过特定测试。
在您的情况下,将描述块标记为 java: true
。
describe "code for JVM in production", java: true do
it "java-specific test" do
end
end
然后 运行 rspec . --tag ~java:true
RSpec 将 ignore/skip 匹配 java: true
标签的测试。
注意:没有必要将其他测试设置为 java: false
或者,您可以修改 spec_helper.rb 配置以在 运行 本地使用环境变量时跳过这些测试。
RSpec.configure do |c|
if RUBY_PLATFORM.include?('darwin') # assumes Macintosh
c.filter_run_excluding java: true
end
end
引用:
在 describe
或 context
块中使用 if
或 unless
条件。
@scarver2 的回答非常好,我也想添加一个更轻量级的替代方案。
您还可以在 describe
或 context
块中使用 if
或 unless
条件,例如:
describe "code for JVM in production", unless: RUBY_PLATFORM.include?('darwin') do
it "java-specific test" do
end
end
我有一套 运行 的测试,但想忽略 本地 的一些测试,因为它们需要 Java 版本是不同的,并且在我的环境中一直失败。我可以忽略这些测试(无论如何我们都有集成测试)
我如何指定 Rails 不是 运行 某些测试而是 运行 所有其他测试?我只是厌倦了看到这些错误,这可能会让我错过一些合法的测试失败...
如有任何帮助,我们将不胜感激!
在 RSpec 中,可以使用排除过滤器,然后从命令行跳过特定测试。
在您的情况下,将描述块标记为 java: true
。
describe "code for JVM in production", java: true do
it "java-specific test" do
end
end
然后 运行 rspec . --tag ~java:true
RSpec 将 ignore/skip 匹配 java: true
标签的测试。
注意:没有必要将其他测试设置为 java: false
或者,您可以修改 spec_helper.rb 配置以在 运行 本地使用环境变量时跳过这些测试。
RSpec.configure do |c|
if RUBY_PLATFORM.include?('darwin') # assumes Macintosh
c.filter_run_excluding java: true
end
end
引用:
在 describe
或 context
块中使用 if
或 unless
条件。
@scarver2 的回答非常好,我也想添加一个更轻量级的替代方案。
您还可以在 describe
或 context
块中使用 if
或 unless
条件,例如:
describe "code for JVM in production", unless: RUBY_PLATFORM.include?('darwin') do
it "java-specific test" do
end
end