Class: Spectre::EvaluationContext

Inherits:
Object
  • Object
show all
Includes:
Delegate
Defined in:
lib/spectre.rb

Overview

This context will be created by assert and expect methods. Failures are reported here.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Delegate

#instance_eval, #instance_exec, #method_missing, #respond_to_missing?

Constructor Details

#initialize(engine, desc) ⇒ EvaluationContext

Returns a new instance of EvaluationContext.



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/spectre.rb', line 155

def initialize(engine, desc, &)
  @desc = desc
  @failures = []

  engine.formatter.log(:info, desc) do
    instance_eval(&)

    if @failures.any?
      engine.logger.error("#{desc} - failed")
      [:error, :failed, nil]
    else
      engine.logger.info("#{desc} - ok")
      [:info, :ok, nil]
    end
  rescue Failure => e
    engine.logger.error("#{e.message} - failed")
    @failures << e
    [:error, :failed, nil]
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spectre::Delegate

Instance Attribute Details

#descObject (readonly)

:stopdoc:



153
154
155
# File 'lib/spectre.rb', line 153

def desc
  @desc
end

#failuresObject (readonly)

:stopdoc:



153
154
155
# File 'lib/spectre.rb', line 153

def failures
  @failures
end

Instance Method Details

#report(failure) ⇒ Object

Report a failure within the EvaluationContext.

assert 'everthing goes well' do
  report 'it does not' if some_thing_happens()
end


185
186
187
# File 'lib/spectre.rb', line 185

def report failure
  @failures << Failure.new(failure, caller_locations)
end