So, I have a code that is very simplified, looks like this:
class B
def initialize opts
@opts = opts
end
end
class A
def initialize opts
@b = B.new opts
end
end
In other words, when I initialize A with parameters, it creates B and passes it a modified set of parameters.
I would like to verify that B.new is getting the right arguments. Right now, I'm doing it this way using RSpec / RR:
@b = Object.new
stub(B).new { |options|
options[:foo].should == 'whatever'
@b
}
A.new({:foo => 'whatever'})
But this has two problems.
Firstly, I cannot create a real copy Bwith actual parameters. If I call B.new inside the block, it invokes the plastered version and the loop until the stack appears. I can set @b = B.newbefore starting, but I still don't know the parameters that will be passed, defeating the test point.
( , - : , unit test A B, , , , .)
-, should , it ... do ... end. B (. ), .
?