Class: MiniTest::Spec

Inherits:
Unit::TestCase show all
Defined in:
lib/minitest/spec.rb

Constant Summary collapse

@@describe_stack =
[MiniTest::Spec]

Instance Attribute Summary

Attributes inherited from Unit::TestCase

#__name__

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Unit::TestCase

inherited, #passed?, reset, #run, #setup, #teardown, test_methods, test_order, test_suites

Methods included from Assertions

#_assertions, #_assertions=, #assert, #assert_block, #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_raises, #assert_respond_to, #assert_same, #assert_send, #assert_throws, #capture_io, #exception_details, #flunk, #message, #mu_pp, #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_respond_to, #refute_same, #skip

Constructor Details

#initialize(name) ⇒ Spec

Returns a new instance of Spec.



75
76
77
78
# File 'lib/minitest/spec.rb', line 75

def initialize name
  super
  @@current_spec = self
end

Class Method Details

.after(type = :each, &block) ⇒ Object



100
101
102
103
# File 'lib/minitest/spec.rb', line 100

def self.after(type = :each, &block)
  raise "unsupported after type: #{type}" unless type == :each
  define_inheritable_method :teardown, &block
end

.before(type = :each, &block) ⇒ Object



95
96
97
98
# File 'lib/minitest/spec.rb', line 95

def self.before(type = :each, &block)
  raise "unsupported before type: #{type}" unless type == :each
  define_inheritable_method :setup, &block
end

.currentObject



71
72
73
# File 'lib/minitest/spec.rb', line 71

def self.current
  @@current_spec
end

.define_inheritable_method(name, &block) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/minitest/spec.rb', line 86

def self.define_inheritable_method name, &block
  super_method = self.superclass.instance_method name

  define_method name do
    super_method.bind(self).call if super_method # regular super() warns
    instance_eval(&block)
  end
end

.describe_stackObject



67
68
69
# File 'lib/minitest/spec.rb', line 67

def self.describe_stack
  @@describe_stack
end

.it(desc, &block) ⇒ Object



105
106
107
# File 'lib/minitest/spec.rb', line 105

def self.it desc, &block
  define_method "test_#{desc.gsub(/\W+/, '_').downcase}", &block
end

.nuke_test_methods!Object



80
81
82
83
84
# File 'lib/minitest/spec.rb', line 80

def self.nuke_test_methods!
  self.public_instance_methods.grep(/^test_/).each do |name|
    send :remove_method, name rescue nil
  end
end