Class: MiniTest::Spec

Inherits:
Unit::TestCase show all
Extended by:
DSL
Defined in:
lib/minitest/spec.rb,
lib/minitest/benchmark.rb

Overview

MiniTest::Spec – The faster, better, less-magical spec framework!

For a list of expectations, see MiniTest::Expectations.

Defined Under Namespace

Modules: DSL

Constant Summary

TYPES =

:nodoc:

DSL::TYPES

Constants inherited from Unit::TestCase

Unit::TestCase::PASSTHROUGH_EXCEPTIONS

Constants included from Assertions

Assertions::UNDEFINED

Instance Attribute Summary

Attributes included from DSL

#desc

Attributes inherited from Unit::TestCase

#__name__

Class Method Summary collapse

Methods included from DSL

after, before, children, create, describe_stack, it, let, name, nuke_test_methods!, register_spec_type, spec_type, subject, to_s

Methods inherited from Unit::TestCase

#assert_performance, #assert_performance_constant, #assert_performance_exponential, #assert_performance_linear, #assert_performance_logarithmic, #assert_performance_power, bench_exp, bench_linear, benchmark_methods, benchmark_suites, current, #fit_error, #fit_exponential, #fit_linear, #fit_logarithmic, #fit_power, i_suck_and_my_tests_are_order_dependent!, inherited, #initialize, #io, #io?, make_my_diffs_pretty!, parallelize_me!, #passed?, reset, #run, #setup, #sigma, #teardown, test_methods, test_order, test_suites, #validation_for_fit

Methods included from Unit::Guard

#jruby?, maglev?, #mri?, #rubinius?, #windows?

Methods included from Assertions

#_assertions, #_assertions=, #assert, #assert_empty, #assert_equal, #assert_in_delta, #assert_in_epsilon, #assert_includes, #assert_instance_of, #assert_kind_of, #assert_match, #assert_nil, #assert_operator, #assert_output, #assert_predicate, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_silent, #assert_throws, #capture_io, #capture_subprocess_io, diff, #diff, diff=, #exception_details, #flunk, #message, #mu_pp, #mu_pp_for_diff, #pass, #refute, #refute_empty, #refute_equal, #refute_in_delta, #refute_in_epsilon, #refute_includes, #refute_instance_of, #refute_kind_of, #refute_match, #refute_nil, #refute_operator, #refute_predicate, #refute_respond_to, #refute_same, #skip, #skipped?, #synchronize

Methods included from Unit::LifecycleHooks

#after_setup, #after_teardown, #before_setup, #before_teardown

Constructor Details

This class inherits a constructor from MiniTest::Unit::TestCase

Class Method Details

.bench(name, &block) ⇒ Object

This is used to define a new benchmark method. You usually don't use this directly and is intended for those needing to write new performance curve fits (eg: you need a specific polynomial fit).

See ::bench_performance_linear for an example of how to use this.



352
353
354
# File 'lib/minitest/benchmark.rb', line 352

def self.bench name, &block
  define_method "bench_#{name.gsub(/\W+/, '_')}", &block
end

.bench_performance_constant(name, threshold = 0.99, &work) ⇒ Object

Create a benchmark that verifies that the performance is constant.

describe "my class" do
  bench_performance_constant "zoom_algorithm!" do |n|
    @obj.zoom_algorithm!(n)
  end
end


396
397
398
399
400
# File 'lib/minitest/benchmark.rb', line 396

def self.bench_performance_constant name, threshold = 0.99, &work
  bench name do
    assert_performance_constant threshold, &work
  end
end

.bench_performance_exponential(name, threshold = 0.99, &work) ⇒ Object

Create a benchmark that verifies that the performance is exponential.

describe "my class" do
  bench_performance_exponential "algorithm" do |n|
    @obj.algorithm(n)
  end
end


411
412
413
414
415
# File 'lib/minitest/benchmark.rb', line 411

def self.bench_performance_exponential name, threshold = 0.99, &work
  bench name do
    assert_performance_exponential threshold, &work
  end
end

.bench_performance_linear(name, threshold = 0.99, &work) ⇒ Object

Create a benchmark that verifies that the performance is linear.

describe "my class" do
  bench_performance_linear "fast_algorithm", 0.9999 do |n|
    @obj.fast_algorithm(n)
  end
end


381
382
383
384
385
# File 'lib/minitest/benchmark.rb', line 381

def self.bench_performance_linear name, threshold = 0.99, &work
  bench name do
    assert_performance_linear threshold, &work
  end
end

.bench_range(&block) ⇒ Object

Specifies the ranges used for benchmarking for that class.

bench_range do
  bench_exp(2, 16, 2)
end

See Unit::TestCase.bench_range for more details.



365
366
367
368
369
370
# File 'lib/minitest/benchmark.rb', line 365

def self.bench_range &block
  return super unless block

  meta = (class << self; self; end)
  meta.send :define_method, "bench_range", &block
end