Forum: Ruby Mock a %x call

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-05-19 16:07
Hi,

Is it possible to mock such method call?

I tried: Kernel.expects(:'%x').returns('whatever').

But I get the following error:
SyntaxError: compile error
/usr/local/ruby1.8.7/lib/ruby/gems/1.8/gems/mocha-0.9.5/lib/mocha/class_method.rb:40:
syntax error, unexpected '(', expecting '\n' or ';'
def %x(*args, &block); mocha.method_missing(:%x, *args, &block); end
4d5b5dd4e263d780a5dfe7ac8b8ac98c?d=identicon&s=25 Tim Pease (Guest)
on 2009-05-19 20:26
(Received via mailing list)
On Tue, May 19, 2009 at 8:07 AM, Fernando Perez <pedrolito@lavache.com>
wrote:
> def %x(*args, &block); mocha.method_missing(:%x, *args, &block); end
The various % constructs in ruby are handled by the parser and,
therefore, cannot be mocked using method stubbing employed by mocha,
rspec mocks, et al.

Blessings,
TwP
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2009-05-20 00:17
(Received via mailing list)
Hi,

At Tue, 19 May 2009 23:07:58 +0900,
Fernando Perez wrote in [ruby-talk:336901]:
> I tried: Kernel.expects(:'%x').returns('whatever').
>
> But I get the following error:
> SyntaxError: compile error
> /usr/local/ruby1.8.7/lib/ruby/gems/1.8/gems/mocha-0.9.5/lib/mocha/class_method.rb:40:
> syntax error, unexpected '(', expecting '\n' or ';'
> def %x(*args, &block); mocha.method_missing(:%x, *args, &block); end

Maybe, expects(:`)?
This topic is locked and can not be replied to.