Jason Kenney
Jason Kenney

Reputation: 101

Is it possible to add a test that does not get autorunned?

I want to add a test for a one-off task, but once it runs, in the future it should not get run as part of the full suite.

Upvotes: 0

Views: 46

Answers (2)

blowmage
blowmage

Reputation: 8984

You can add a guard clause on the test method, or the test class for whether it should exist. For example:

def test_greet
  greeter = HelloWorld.new
  assert_equal "Hello world!", greeter.greet
end if ENV["ONEOFF"]

Or, for the whole test class:

class TestHello < Minitest::Test
  def test_greet
    greeter = HelloWorld.new
    assert_equal "Hello world!", greeter.greet
  end
end if ENV["ONEOFF"]

Then to have these run just define the ONEOFF environment variable when you run your test.

Upvotes: 1

rdnewman
rdnewman

Reputation: 1399

If you're using Rspec, checkout Rspec filtering. That may be what you want: https://www.relishapp.com/rspec/rspec-core/v/2-14/docs/filtering/inclusion-filters

Upvotes: 0

Related Questions