Module: DoRewrite
- Defined in:
- lib/spec/spec_helper.rb
Instance Method Summary collapse
- #do_rewrite(method_name, object, verbose = false, old_and_new_are_same = true) ⇒ Object
-
#rewriters ⇒ Object
Override this and return a list of rewriters, in order, so do_rewrite can call them.
Instance Method Details
#do_rewrite(method_name, object, verbose = false, old_and_new_are_same = true) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/spec/spec_helper.rb', line 127 def do_rewrite(method_name, object, verbose = false, old_and_new_are_same = true) sexp = @methods[method_name] # Run all rewriters on the sexp result = rewriters.reduce(sexp) { |rewritee, rewriter| rewriter.process rewritee } stringifier = VirtualKeywords::SexpStringifier.new # Visually inspecting this result, it appears to be right code_result = stringifier.stringify result if verbose puts code_result end # my_* are dummy methods that do not change behavior, so both the # old and new code should produce the same result, # except that @my_*_calls is incremented old_result = object.send method_name object.instance_eval code_result #VirtualKeywords::ClassReflection.new.install_method_on_instance( #object, code_result) new_result = object.send method_name if old_and_new_are_same new_result.should eql old_result end end |
#rewriters ⇒ Object
Override this and return a list of rewriters, in order, so do_rewrite can call them
123 124 125 |
# File 'lib/spec/spec_helper.rb', line 123 def rewriters raise Abstract, 'Must provide rewriters!' end |