Hello, My first time here, and I'm pretty new to rspec, and indeed BDD/TDD, so bear with me
I am trying to spec a fairly simple controller update action for an account. The account belongs_to :user and user has_one :account. the route is PUT: /users/1/account here's the action def update @account = @user.account respond_to do |format| if @account.update_attributes(params[:account]) flash[:notice] = ' Account was successfully updated.' format.html { redirect_to(user_account_path( @user)) } else format.html { render :action => "edit" } end end end I'm trying to avoid fixtures, and I'm using rspec's own mock framework In normal operation the @user instance variable is assigned in a before_filter (get_user) - so i figured if I stub that I could then assign user: before(:each) do controller.stub!(:get_user).and_return(true) instance_variable_set('@user', mock_model(User)) end I tried other variations on this - like instance_variable_set('@user', User.new) and others but @user is never assigned -- (actually I did have that bit working when I started this mail, but I messed it up somehow) .. anyway - then the problem I couldn't get past after that - and the reason I started writing this mail was: .... how do I stub out that user's call to :account and get it to return an account, so that update_attributes is called? -- ( when I was using mocha.. which I abandoned for other reasons - there was "any_instance_of" but I can't find similar in rspecs own mocking - and it felt a bit wishy-washy anyway.) It seems there is plenty of help around on speccing RESTful controllers, but not when resources are nested Any input on this will be much appreciated, and really improve my understanding of mocking. So thanks in advance! Julian
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users