Class: TestRunner::Assert::Assertion

Inherits:
Object
  • Object
show all
Defined in:
lib/test_runner/assert/assertion.rb

Direct Known Subclasses

Refutation

Defined Under Namespace

Classes: Refutation, SubjectThunk

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject_proc, checks) ⇒ Assertion

Returns a new instance of Assertion.



8
9
10
11
12
13
14
# File 'lib/test_runner/assert/assertion.rb', line 8

def initialize subject_proc, checks
  @subject_proc = subject_proc
  @checks = checks
  @passes = []
  @fails  = []
  @trace = caller_locations
end

Instance Attribute Details

#failsObject (readonly)

Returns the value of attribute fails.



4
5
6
# File 'lib/test_runner/assert/assertion.rb', line 4

def fails
  @fails
end

#passesObject (readonly)

Returns the value of attribute passes.



5
6
7
# File 'lib/test_runner/assert/assertion.rb', line 5

def passes
  @passes
end

#sourceObject

Returns the value of attribute source.



6
7
8
# File 'lib/test_runner/assert/assertion.rb', line 6

def source
  @source
end

Instance Method Details

#build_checksObject



23
24
25
26
27
28
# File 'lib/test_runner/assert/assertion.rb', line 23

def build_checks
  @checks.map do |check_name, argument|
    TestRunner::Config.internal_logger.debug "Resolving check #{check_name.inspect}, arg=#{argument.inspect}"
    resolve_check check_name, argument
  end
end

#callObject



16
17
18
19
20
21
# File 'lib/test_runner/assert/assertion.rb', line 16

def call
  perform_checks
  freeze
  raise to_error if failed?
  subject
end

#failed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/test_runner/assert/assertion.rb', line 30

def failed?
  fails.any?
end

#fileObject



34
35
36
# File 'lib/test_runner/assert/assertion.rb', line 34

def file
  @trace[0].path
end

#freezeObject



38
39
40
41
# File 'lib/test_runner/assert/assertion.rb', line 38

def freeze
  passes.freeze
  fails.freeze
end

#lineObject



43
44
45
# File 'lib/test_runner/assert/assertion.rb', line 43

def line
  @trace[0].lineno
end

#passed?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/test_runner/assert/assertion.rb', line 47

def passed?
  not failed?
end

#perform_checksObject



51
52
53
54
55
56
57
# File 'lib/test_runner/assert/assertion.rb', line 51

def perform_checks
  build_checks.each do |check|
    check.evaluate
    ary = if check.passed? then passes else fails end
    ary.push check
  end
end

#resolve_check(check_name, argument) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/test_runner/assert/assertion.rb', line 59

def resolve_check check_name, argument
  check = Checks.resolve check_name do
    check_name = :include if check_name == :includes
    argument = [check_name, *argument]
    Checks[:predicate]
  end
  check.new subject_thunk, argument
end

#subjectObject



68
69
70
# File 'lib/test_runner/assert/assertion.rb', line 68

def subject
  subject_thunk.call
end

#subject_thunkObject



72
73
74
# File 'lib/test_runner/assert/assertion.rb', line 72

def subject_thunk
  @subject_thunk ||= SubjectThunk.new @subject_proc
end

#to_errorObject



76
77
78
# File 'lib/test_runner/assert/assertion.rb', line 76

def to_error
  AssertionFailed.new self
end

#traceObject



80
81
82
# File 'lib/test_runner/assert/assertion.rb', line 80

def trace
  BacktraceFilter.(@trace)
end