[rspec-users] Stubbing @instance.association.build

Nickolay Kolev nmkolev at gmail.com
Wed Feb 17 09:03:48 EST 2010


> I don't see @new_course getting defined anywhere. Try assigning it a
> non-nil value in each of the POST examples (or in before(:each) in
> that group).

Thanks, David!

Am I right in assuming that I have to check that @new_course received
a "save" and returned true in the same it-block?

This works:

it "should build the new course" do
 
@teacher.courses.should_receive(:build).with(@valid_course_attributes).and_return(@new_course)
  @new_course.should_receive(:save).and_return(true)
  do_post
end

This does not (naturally):

it "should build the new course" do
 
@teacher.courses.should_receive(:build).with(@valid_course_attributes).and_return(@new_course)
  do_post
end

it "should build the new course" do
  @new_course.should_receive(:save).and_return(true)
  do_post
end

Is there a way to propagate the @new_course instance variable to the
next it-block?

Best,
Nickolay


More information about the rspec-users mailing list