class Given::Evaluator
Constants
- MAX_INSPECT_SIZE
Public Class Methods
new(example, block)
click to toggle source
# File lib/given/evaluator.rb 19 def initialize(example, block) 20 @example = example 21 @block = block 22 end
Public Instance Methods
eval_string(exp_string)
click to toggle source
# File lib/given/evaluator.rb 24 def eval_string(exp_string) 25 limit_length(eval_in_context(exp_string).inspect) 26 rescue StandardError => ex 27 EvalErr.new("#{ex.class}: #{ex.message}") 28 end
location()
click to toggle source
# File lib/given/evaluator.rb 30 def location 31 Given.location_of(@block) 32 end
Private Instance Methods
eval_in_context(exp_string)
click to toggle source
# File lib/given/evaluator.rb 46 def eval_in_context(exp_string) 47 exp_proc = "proc { #{exp_string} }" 48 blk = eval(exp_proc, @block.binding) 49 @example.instance_eval(&blk) 50 end
limit_length(string)
click to toggle source
# File lib/given/evaluator.rb 38 def limit_length(string) 39 if string.size > MAX_INSPECT_SIZE 40 string[0..MAX_INSPECT_SIZE] + " (...truncated...)" 41 else 42 string 43 end 44 end