Sha256: b76474281c0b2fea457d57912150e3b70ccbd1472300599f515f66706e333ad6
Contents?: true
Size: 875 Bytes
Versions: 25
Compression:
Stored size: 875 Bytes
Contents
module Matest class EvalErr def initialize(str) @string = str end def size inspect.size end def to_s @string end def inspect @string end end class Evaluator def initialize(example, block) @example = example @block = block end def eval_string(exp_string) limit_length(eval_in_context(exp_string).inspect) rescue StandardError => ex EvalErr.new("#{ex.class}: #{ex.message}") end private MAX_INSPECT_SIZE = 2000 def limit_length(string) if string.size > MAX_INSPECT_SIZE string[0..MAX_INSPECT_SIZE] + " (...truncated...)" else string end end def eval_in_context(exp_string) exp_proc = "proc { #{exp_string} }" blk = eval(exp_proc, @block.binding) @example.instance_eval(&blk) end end end
Version data entries
25 entries across 25 versions & 1 rubygems