2

I have a suite of tests that I run, but would like to ignore a few tests locally, since they require a Java version that is different and consistently fail in my environment. I'm okay with ignoring these tests (we have integrated testing anyways)

How can I specify to Rails to not run certain tests but run all others? I'm just tired of seeing the errors, and it could lead me to miss some legit test failures...

Any help would be appreciated!

scarver2
  • 7,887
  • 2
  • 53
  • 61
Mark Kadlec
  • 8,036
  • 17
  • 60
  • 96

2 Answers2

2

In RSpec one can use exclusion filters and then from the command line, skip specific tests.

In your case, tag the description blocks as java: true.

describe "code for JVM in production", java: true do
  it "java-specific test" do
  end
end

Then run rspec . --tag ~java:true RSpec will ignore/skip the tests matching java: true tag.

NOTE: It is not necessary to set the other tests to java: false

Alternatively, you can amend your spec_helper.rb with a configuration to skip these tests when run locally using an environment variable.

RSpec.configure do |c|
  if RUBY_PLATFORM.include?('darwin') # assumes Macintosh
    c.filter_run_excluding java: true
  end
end

CITE:

Community
  • 1
  • 1
scarver2
  • 7,887
  • 2
  • 53
  • 61
  • Thanks @scarver2, but I was hoping to do this locally since our tests are all in source control, any idea how I could ignore the tests in my local machine? – Mark Kadlec Aug 19 '15 at 15:57
  • @MarkKadlec Thank you for the additional info. I completely changed my answer to cater to RSpec. RSpec provides an excellent mechanism for skipping tests that match specific tags. – scarver2 Aug 20 '15 at 14:40
  • that's a great answer, thanks, I'm going to implement the spec_helper.rb method! – Mark Kadlec Aug 20 '15 at 15:41
0

Use the if or unless conditional in the describe or context block.

@scarver2's answer is really great and I just wanted to add a more lightweight alternative as well.

You can also use the if or unless conditional in the describe or context block, like:

describe "code for JVM in production", unless: RUBY_PLATFORM.include?('darwin') do
  it "java-specific test" do
  end
end
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245