Class: RLab::Assert::Assertion::SubjectThunk

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

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ SubjectThunk

Returns a new instance of SubjectThunk.



91
92
93
# File 'lib/rlab/assert/assertion.rb', line 91

def initialize block
  @block = block
end

Instance Method Details

#callObject



95
96
97
98
# File 'lib/rlab/assert/assertion.rb', line 95

def call
  return @subject if subject_resolved?
  @subject = @block.call
end

#expect_errorObject



100
101
102
103
104
105
106
107
108
# File 'lib/rlab/assert/assertion.rb', line 100

def expect_error
  raise "called after initially fetched" if subject_resolved?
  @block.call
  nothing_raised = true
rescue => error
  @subject = error
ensure
  raise NothingRaised.new if nothing_raised
end

#subject_resolved?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/rlab/assert/assertion.rb', line 110

def subject_resolved?
  instance_variable_defined? :@subject
end