Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.1.4, JRuby 1.1.5
-
Fix Version/s: JRuby 1.2
-
Component/s: Java Integration
-
Labels:None
-
Testcase included:yes
Description
Maybe this is necessary, but it can have non-intuitive results when testing because stubbed behavior disappears on objects that are passed into java methods in java arrays.
e.g the spec below began failing for me after 1.1.3 since the stubbed stuff is defined on the java objects directly.
def new_fig_details(values)
..
fig.stub!(:finalPercent).and_return(values[:percent]) #finalPercent is read only method
..
fig
end
...
it "should be able to handle multiple figures" do
fig = new_fig_details(:num => 1, :width => 12, :height => 11,
:picas => 12, :percent => 1.00, :col_size => 1.0, :total => 11)
fig2 = new_fig_details(:num => 2, :width => 11, :height => 12,
:picas => 13, :percent => 2.00, :col_size => 3.0, :total => 16)
@data.figureDetails = [fig, fig2].to_java(LengthCheck::FigureDetail)
expected =
" 1 1 12 11 12 1.00 1.0 11\n" +
" 2 2 11 12 13 2.00 3.0 16\n"
@substitutions.do_figure_substitutions!(@text)
@text.should == expected
end
The workaround is to stub behavior directly on the java array elements.
ex.
@data.figureDetails = [fig, fig2].to_java(LengthCheck::FigureDetail)
@data.figureDetails[0].stub!(:finalPercent).and_return(1.00)
@data.figureDetails[1].stub!(:finalPercent).and_return(2.00)