Rspecs stubbed return values lost after Array.#to_java


#1

Trying to upgrade from jruby-1.1.2 to the 1.1.6RC1 I’m running into
problems with stubbed behavior(rspec) on java methods being lost
after [].to_java. See below.

require ‘MyClass’

describe “[].to_java” do

Works in jruby-1.1.2 and jruby-1.1.3 but broken in jruby > 1.1.4

it “should behave consistently with stubbed and real return
values” do
real = Java::MyClass.new
stubbed = Java::MyClass.new

 real.stringProperty = 'hello'
 stubbed.stub!(:stringProperty).and_return'hello'

 java_array = [real].to_java(Java::MyClass)
 real.stringProperty.should == 'hello'
 java_array[0].stringProperty.should == 'hello'

 java_array = [stubbed].to_java(Java::MyClass)
 stubbed.stringProperty.should == 'hello'
 java_array[0].stringProperty.should == 'hello' #fails here

end

end

//MyClass.java
public class MyClass {
public String stringProperty;
}

jruby-1.1.3/bin/jruby $GEM_HOME/bin/spec -v
rspec 1.1.11

jruby-1.1.3/bin/jruby $GEM_HOME/bin/spec -fs reproduce.rb

[].to_java

  • should behave consistently with stubbed or directly set java
    properties

Finished in 0.074 seconds

1 example, 0 failures

jruby-1.1.6RC1/bin/jruby $GEM_HOME/bin/spec -fs reproduce.rb

‘[].to_java should behave consistently with stubbed or directly set
java properties’ FAILED
expected: “hello”,
got: nil (using ==)
reproduce.rb:19:

WDYT?
-lenny


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#2

Actually it looks like this is more about to_java is returning a java
array with entirely different objects.

this works up in 1.1.2 and 1.1.3 but fails with jruby >= 1.1.4

it “should do shallow copies” do
o = Java::MyClass.new

 java_array = [o].to_java(Java::MyClass)

 o.equal?(java_array[0]).should be_true

end

-lenny

On Dec 5, 2008, at 12:23 AM, Lenny M. wrote:

values" do
java_array = [stubbed].to_java(Java::MyClass)
}
Finished in 0.074 seconds
reproduce.rb:19:

WDYT?
-lenny


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email