I am testing Java classes with RSpec and JRuby.
How can I stub out a call to super in an imported Java class in my RSpec test?
For example:
I have 2 Java classes:
public class A{
public String foo() {
return "bar";
}
}
public class B extends A
public String foo() {
// B code
return super.foo();
}
}
I am just trying to test the code in B.foo and not the code in A.foo with JRuby. How can I stub out the call to the super class method in my RSpec test?
rspec test:
java_import Java::B
describe B do
it "should not call A.foo" do
# some code to stub out A.foo
b = B.new
b.foo.should_not == "bar"
end
end
I have tried including a module with a new foo method in B s class hoping that it would hit the module method first but B still makes a call to A. The inserting module technique works in Ruby but not with JRuby and imported Java classes.
Any other ideas to stub out the superclass method to get my RSpec test to pass?