# File lib/mspec/runner/evaluate.rb, line 6 def self.desc @desc ||= "evaluates " end
# File lib/mspec/runner/evaluate.rb, line 2 def self.desc=(desc) @desc = desc end
# File lib/mspec/runner/evaluate.rb, line 10 def initialize(ruby, desc) @ruby = ruby @desc = desc || self.class.desc end
# File lib/mspec/runner/evaluate.rb, line 38 def define(&block) ruby = @ruby desc = @desc evaluator = self specify "#{desc} #{format ruby}" do evaluator.instance_eval(ruby) evaluator.instance_eval(&block) end end
Formats the Ruby source code for reabable output in the -fs formatter option. If the source contains no newline characters, wraps the source in single quotes to set if off from the rest of the description string. If the source does contain newline characters, sets the indent level to four characters.
# File lib/mspec/runner/evaluate.rb, line 20 def format(ruby, newline=true) if /\n/ =~ ruby lines = ruby.rstrip.each_line.to_a if /( *)/ =~ lines.first if $1.size > 4 dedent = $1.size - 4 ruby = lines.map { |l| l[dedent..-1] }.join else indent = " " * (4 - $1.size) ruby = lines.map { |l| "#{indent}#{l}" }.join end end "\n#{ruby}" else "'#{ruby}'" end end