[rspec-devel] [ rspec-Bugs-6575 ] Parse error in aliasing the partial mock original method

noreply at rubyforge.org noreply at rubyforge.org
Thu Nov 9 13:32:46 EST 2006


Bugs item #6575, was opened at 2006-11-08 14:24
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6575&group_id=797

Category: mock module
Group: None
>Status: Open
Resolution: Accepted
Priority: 3
Submitted By: Brian Takita (btakita)
>Assigned to: Brian Takita (btakita)
Summary: Parse error in aliasing the partial mock original method

Initial Comment:
Here is code that caused the error in Rspec 0.7.0. It worked in version 0.6.*:

@rake_application = @builder.rake_application = mock("rake_application")
...
@rake_application.should_receive(:last_comment=).with("Builds the #{extension} extension")

----

/usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/mocks/mock_handler.rb:116:in `metaclass_eval': (eval):2:in `metaclass_eval': compile error (SyntaxError)
(eval):2: parse error, unexpected tIDENTIFIER, expecting $
            alias_method :original_exists?_before_proxy, :exists?
                                                       ^	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/mocks/mock_handler.rb:56:in `define_expected_method'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/mocks/mock_handler.rb:45:in `__add'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/mocks/mock_handler.rb:26:in `add_message_expectation'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/mocks/mock_methods.rb:5:in `should_receive'
	from /home/btakita/workspace/fjson/spec/mkmf_rake_builder_spec.rb:127:in `__instance_exec0'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/extensions/object.rb:15:in `send'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/extensions/object.rb:15:in `instance_exec'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/specification.rb:28:in `run'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/context.rb:45:in `run'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/context.rb:44:in `each'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/context.rb:44:in `run'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/context_runner.rb:25:in `run'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/context_runner.rb:24:in `each'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/context_runner.rb:24:in `run'
	from /usr/local/lib/ruby/gems/1.8/gems/rspec-0.7.0/lib/spec/runner/extensions/kernel.rb:11:in `context_runner'
	from /home/btakita/workspace/fjson/spec/mkmf_rake_builder_spec.rb:4


----------------------------------------------------------------------

>Comment By: Brian Takita (btakita)
Date: 2006-11-09 10:32

Message:
I'm going to attatch a patch that puts the original method
object into a hash rather than relying on method aliasing.

This will make this code less fragile.

----------------------------------------------------------------------

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2006-11-08 15:48

Message:
Fixed in r1059

----------------------------------------------------------------------

Comment By: Brian Takita (btakita)
Date: 2006-11-08 15:23

Message:
Here is a quick fix I put into my spec_helper.rb

module Spec
  module Mocks
    class MockHandler
      def __pre_proxied_method_name method_name
       
"original_#{method_name.to_s.delete('!').delete('=').delete('?').delete('[').delete('\]')}_before_proxy"
      end
    end
  end
end

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6575&group_id=797


More information about the rspec-devel mailing list