Class: RLab::Assert::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/rlab/assert/check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject_thunk, argument) ⇒ Check

Returns a new instance of Check.



8
9
10
11
# File 'lib/rlab/assert/check.rb', line 8

def initialize subject_thunk, argument
  @argument = argument
  @subject_thunk = subject_thunk
end

Instance Attribute Details

#argumentObject (readonly)

Returns the value of attribute argument.



6
7
8
# File 'lib/rlab/assert/check.rb', line 6

def argument
  @argument
end

Instance Method Details

#evaluateObject



13
14
15
16
# File 'lib/rlab/assert/check.rb', line 13

def evaluate
  self.class.block.call self, @argument
  freeze
end

#expect_errorObject



18
19
20
# File 'lib/rlab/assert/check.rb', line 18

def expect_error
  @subject_thunk.expect_error
end

#fail(message) ⇒ Object



22
23
24
25
# File 'lib/rlab/assert/check.rb', line 22

def fail message
  passed = negated? ^ yield
  @fail_message = message unless passed
end

#fail_messageObject



27
28
29
# File 'lib/rlab/assert/check.rb', line 27

def fail_message
  "expected #{Assert.inspect subject} to#{" not" if negated?} #{@fail_message}"
end

#failed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rlab/assert/check.rb', line 31

def failed?
  @fail_message ? true : false
end

#negateObject



39
40
41
# File 'lib/rlab/assert/check.rb', line 39

def negate
  @negated = !@negated
end

#negated?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rlab/assert/check.rb', line 35

def negated?
  @negated ? true : false
end

#passed?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/rlab/assert/check.rb', line 43

def passed?
  not failed?
end

#subjectObject



47
48
49
# File 'lib/rlab/assert/check.rb', line 47

def subject
  @expected_error or @subject_thunk.call
end