class Matest::Evaluator
Constants
- MAX_INSPECT_SIZE
Public Class Methods
new(example, block)
click to toggle source
# File lib/matest/evaluator.rb, line 18 def initialize(example, block) @example = example @block = block end
Public Instance Methods
eval_string(exp_string)
click to toggle source
# File lib/matest/evaluator.rb, line 23 def eval_string(exp_string) limit_length(eval_in_context(exp_string).inspect) rescue StandardError => ex EvalErr.new("#{ex.class}: #{ex.message}") end
Private Instance Methods
eval_in_context(exp_string)
click to toggle source
# File lib/matest/evaluator.rb, line 41 def eval_in_context(exp_string) exp_proc = "proc { #{exp_string} }" blk = eval(exp_proc, @block.binding) @example.instance_eval(&blk) end
limit_length(string)
click to toggle source
# File lib/matest/evaluator.rb, line 33 def limit_length(string) if string.size > MAX_INSPECT_SIZE string[0..MAX_INSPECT_SIZE] + " (...truncated...)" else string end end