I''m trying to test some code that can loop once or multiple times and assign some values to another object. I want to test one of the values being assigned to the object in the loop. e.g. class Foo def bar values = returns_an_array_of_values baz = Baz.new values.each_with_index do |value, index| baz.field1 = Constant baz.field2 = index baz.field3 = value end end end it "should assign increasing index values to field3" do quxxo = mock Baz.stub!(:new => quxxo) quxxo.should_receive(:field2=).with(1,2,3) end This doesn''t work. I tried a few different variants. quxxo.should_receive(:field2=).with(1).with(2).with(3) that doesn''t work either. Any suggestions on how to set expectations for a single mock to receive the same message multiple time with different arguments with the express purpose of validating the arguments? Thanks... cr
On Jun 17, 2010, at 11:07 AM, Chuck Remes wrote:> I''m trying to test some code that can loop once or multiple times and assign some values to another object. I want to test one of the values being assigned to the object in the loop. > > e.g. > > class Foo > def bar > values = returns_an_array_of_values > > baz = Baz.new > > values.each_with_index do |value, index| > baz.field1 = Constant > baz.field2 = index > baz.field3 = value > end > end > end > > > > it "should assign increasing index values to field3" do > quxxo = mock > Baz.stub!(:new => quxxo) > > quxxo.should_receive(:field2=).with(1,2,3) > end > > This doesn''t work. I tried a few different variants. > > quxxo.should_receive(:field2=).with(1).with(2).with(3) > > that doesn''t work either. > > Any suggestions on how to set expectations for a single mock to receive the same message multiple time with different arguments with the express purpose of validating the arguments?quxxo.stub(:field2=) quxxo.should_receive(:field2=).with(1) quxxo.should_receive(:field2=).with(2) quxxo.should_receive(:field2=).with(3) Cheers, David
On Jun 17, 2010, at 12:22 PM, David Chelimsky wrote:> On Jun 17, 2010, at 11:07 AM, Chuck Remes wrote: > >> it "should assign increasing index values to field3" do >> quxxo = mock >> Baz.stub!(:new => quxxo) >> >> quxxo.should_receive(:field2=).with(1,2,3) >> end >> >> This doesn''t work. I tried a few different variants. >> >> quxxo.should_receive(:field2=).with(1).with(2).with(3) >> >> that doesn''t work either. >> >> Any suggestions on how to set expectations for a single mock to receive the same message multiple time with different arguments with the express purpose of validating the arguments? > > quxxo.stub(:field2=) > quxxo.should_receive(:field2=).with(1) > quxxo.should_receive(:field2=).with(2) > quxxo.should_receive(:field2=).with(3)Ah, so obvious in retrospect. Many thanks... cr