Class: Neiltest::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/neiltest/test_case.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestCase

Returns a new instance of TestCase.



19
20
21
22
# File 'lib/neiltest/test_case.rb', line 19

def initialize
  self.results = []
  run
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



3
4
5
# File 'lib/neiltest/test_case.rb', line 3

def results
  @results
end

Instance Method Details

#assert(value, message = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/neiltest/test_case.rb', line 24

def assert(value, message = nil)
  if value
    add_result Result.new(type: :pass)
  else
    add_result Result.new(type: :fail, backtrace: caller, message: message || "Expected a truthy but got #{value}")
  end
end

#assert_equal(expected, actual, message = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/neiltest/test_case.rb', line 40

def assert_equal(expected, actual, message = nil)
  if expected == actual
    add_result Result.new(type: :pass)
  else
    add_result Result.new(type: :fail, backtrace: caller, message: message || "Expected #{expected} but got #{actual}")
  end
end

#assert_not_equal(first, second, message = nil) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/neiltest/test_case.rb', line 48

def assert_not_equal(first, second, message = nil)
  if first != second
    add_result Result.new(type: :pass)
  else
    add_result Result.new(type: :fail, backtrace: caller, message: message || "Expected #{first} to be different from #{second}")
  end
end

#refute(value, message = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/neiltest/test_case.rb', line 32

def refute(value, message = nil)
  if !value
    add_result Result.new(type: :pass)
  else
    add_result Result.new(type: :fail, backtrace: caller, message: message || "Expected a falsy but got #{value}")
  end
end