[jruby-user] rspec 1.3 stubbing

3 views
Skip to first unread message

GregD

unread,
Jan 6, 2011, 10:56:01 AM1/6/11
to us...@jruby.codehaus.org
All,

Anyone using rspec 1.3 and stubbing Java methods?

I tried this on a java static that would hit the db and I don't want
that for these unit tests. It did not work as expected.

in my before block:

JavaClass.stub!(:staticJavaMethod).and_return(some_value)

I tried the ruby form of the method like :static_java_method. I tried
with or without .with(params).

Is it the java method signature part that does not allow this?
Anybody even attempt this? I've googled and jtestr looks to allow for
mocks and stubs, but I'm not familiar with jtestr and my initial
thought is yuk because the use of ant.


Thanks,

GregD

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Nick Sieger

unread,
Jan 6, 2011, 3:22:01 PM1/6/11
to us...@jruby.codehaus.org
On Thu, Jan 6, 2011 at 9:56 AM, GregD <gdit...@fuse.net> wrote:
> All,
>
> Anyone using rspec 1.3 and stubbing Java methods?
>
> I tried this on a java static that would hit the db and I don't want
> that for these unit tests. It did not work as expected.
>
> in my before block:
>
> JavaClass.stub!(:staticJavaMethod).and_return(some_value)
>
> I tried the ruby form of the method like :static_java_method.  I tried
> with or without .with(params).
>
> Is it the java method signature part that does not allow this?
> Anybody even attempt this?  I've googled and jtestr looks to allow for
> mocks and stubs, but I'm not familiar with jtestr and my initial
> thought is yuk because the use of ant.

Only the Ruby side of things will see the stubbed method. Any Java
code will still call the real thing, unfortunately.

/Nick

Ian Dees

unread,
Jan 6, 2011, 6:40:14 PM1/6/11
to us...@jruby.codehaus.org
Hi, all.

>> Anyone using rspec 1.3 and stubbing Java methods?

The JtestR project supports stubbing some Java methods through Mocha,
which can be used with RSpec. The docs
(http://docs.codehaus.org/display/JTESTR/Mocks) weren't clear on
whether or not this includes static methods, but it may be worth a
try.

--Ian

Reply all
Reply to author
Forward
0 new messages