Setting rspec expectations for jruby java method internal call

I would really like to test java code using rspec under jruby, but I don’t see how to set expectations in the internal calls of the java method. Given the following java:

public class A { public String hi() { return hello(); } public String hello() { return "yo"; } } 

I would like to be able to:

 describe 'A' do it 'should call hello' do a = some.java.package.A.new a.should_receive(:hello).and_return('yello') a.hi end end 

Is it possible to integrate the java mocking tool backstage to do this? Has anyone already done this? I don't care if I should use a different syntax to set the wait (instead of rspec 'should_receive'), but it should be at least brief.

+4
source share
1 answer

JtestR does exactly what you want. This is a collection of Ruby libraries, combined with JRuby integration, so running tests is completely painless to configure.

It links Mocha and RSpec http://jtestr.codehaus.org/Mocks . For example, Rspec for Map, you can write such as:

 it "should be able to add an entry to it" do @hash_map.put "foo", "bar" @hash_map.get("foo").should == "bar" end 

More here

+2
source

Source: https://habr.com/ru/post/1314665/


All Articles