Module: Minitest::Meaningful

Defined in:
lib/minitest/meaningful.rb,
lib/minitest/meaningful/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

MultipleAnnotationsError =
Class.new(StandardError)
VERSION =
"0.3.0"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.enabledObject

Returns the value of attribute enabled.



8
9
10
# File 'lib/minitest/meaningful.rb', line 8

def enabled
  @enabled
end

Class Method Details

.included(base) ⇒ Object



33
34
35
# File 'lib/minitest/meaningful.rb', line 33

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#capture_exceptionsObject



64
65
66
67
68
69
70
71
72
# File 'lib/minitest/meaningful.rb', line 64

def capture_exceptions
  return super unless @should_fail

  yield
rescue *Minitest::Test::PASSTHROUGH_EXCEPTIONS
  raise
rescue Assertion => e
  @did_fail = true
end

#important!Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/minitest/meaningful.rb', line 74

def important!
  if @should_fail
    if @important_backtrace
      raise MultipleAnnotationsError
    else
      @important_backtrace = caller
    end
  else
    unless self.class.meaningful_methods.keys.include?(name.to_s)
      exception = Minitest::Assertion.new("Test uses `important!` without `assert_meaningful`.")
      raise exception
    end

    yield
  end
end

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/minitest/meaningful.rb', line 38

def run
  @should_fail = Meaningful.enabled

  super

  if @should_fail
    if !@important_backtrace
      exception = Minitest::Assertion.new("Expected test to have `important!` setup.")
      exception.set_backtrace(self.class.meaningful_methods[name.to_s])
      self.failures << exception
    elsif !@did_fail
      exception = Minitest::Assertion.new("Expected test to fail without `important!` setup.")
      exception.set_backtrace(@important_backtrace)
      self.failures << exception
    end
  end

  Result.from(self)
rescue MultipleAnnotationsError
  exception = Minitest::Assertion.new("Test uses `important!` more than once.")
  exception.set_backtrace(@important_backtrace)
  self.failures << exception

  Result.from(self)
end