Module: Minitest::Guard

Included in:
Test, Test
Defined in:
lib/minitest.rb

Overview

Provides a simple set of guards that you can use in your tests to skip execution if it is not applicable. These methods are mixed into Test as both instance and class methods so you can use them inside or outside of the test methods.

def test_something_for_mri
  skip "bug 1234"  if jruby?
  # ...
end

if windows? then
  # ... lots of test methods ...
end

Instance Method Summary collapse

Instance Method Details

#jruby?(platform = RUBY_PLATFORM) ⇒ Boolean

Is this running on jruby?

Returns:

  • (Boolean)


954
955
956
# File 'lib/minitest.rb', line 954

def jruby? platform = RUBY_PLATFORM
  "java" == platform
end

#maglev?(platform = defined?(RUBY_ENGINE) && RUBY_ENGINE) ⇒ Boolean

Is this running on maglev?

Returns:

  • (Boolean)


961
962
963
964
965
966
# File 'lib/minitest.rb', line 961

def maglev? platform = defined?(RUBY_ENGINE) && RUBY_ENGINE
  where = Minitest.filter_backtrace(caller).first
  where = where.split(/:in /, 2).first # clean up noise
  warn "DEPRECATED: `maglev?` called from #{where}. This will fail in Minitest 6."
  "maglev" == platform
end

#mri?(platform = RUBY_DESCRIPTION) ⇒ Boolean

Is this running on mri?

Returns:

  • (Boolean)


971
972
973
# File 'lib/minitest.rb', line 971

def mri? platform = RUBY_DESCRIPTION
  /^ruby/ =~ platform
end

#osx?(platform = RUBY_PLATFORM) ⇒ Boolean

Is this running on macOS?

Returns:

  • (Boolean)


978
979
980
# File 'lib/minitest.rb', line 978

def osx? platform = RUBY_PLATFORM
  /darwin/ =~ platform
end

#rubinius?(platform = defined?(RUBY_ENGINE) && RUBY_ENGINE) ⇒ Boolean

Is this running on rubinius?

Returns:

  • (Boolean)


985
986
987
988
989
990
# File 'lib/minitest.rb', line 985

def rubinius? platform = defined?(RUBY_ENGINE) && RUBY_ENGINE
  where = Minitest.filter_backtrace(caller).first
  where = where.split(/:in /, 2).first # clean up noise
  warn "DEPRECATED: `rubinius?` called from #{where}. This will fail in Minitest 6."
  "rbx" == platform
end

#windows?(platform = RUBY_PLATFORM) ⇒ Boolean

Is this running on windows?

Returns:

  • (Boolean)


995
996
997
# File 'lib/minitest.rb', line 995

def windows? platform = RUBY_PLATFORM
  /mswin|mingw/ =~ platform
end