[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Mock a %x call

Fernando Perez

5/19/2009 2:08:00 PM

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
--
Posted via http://www.ruby-....

2 Answers

Tim Pease

5/19/2009 6:26:00 PM

0

On Tue, May 19, 2009 at 8:07 AM, Fernando Perez <pedrolito@lavache.com> wrote:
> 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

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

Nobuyoshi Nakada

5/19/2009 10:16:00 PM

0

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(:`)?

--
Nobu Nakada