[rspec-users] [newbie]: How to test for operations inside a block?
mark at mwilden.com
Mon Sep 22 12:24:19 EDT 2008
On Mon, Sep 22, 2008 at 9:07 AM, Carmine Moleti <lists at ruby-forum.com>wrote:
> def create
> authenticate_with_open_id(params[:identity_url], :required => [
> :nickname, :email ], :optional => :fullname) do |result, identity_url,
> if result.successful?
> @user = User.new
> @user.identity_url = identity_url
> @user.roles << Role.find_by_name('operator')
> @user.user_type = 'operator'
> redirect_to users_path
> redirect_to new_user_path
> How am I supposed to write a spec to test the code shown above?
The first thing I would do would be to refactor this code into the User
model. The controller shouldn't be concerned with assigning the user_type,
The first test pass successfully while the second throws havocs on me.
> It complains on the "@user.should_receive(:save..." part.
> It also complained when I wrote
> "User.should_receive(:new).and_return(@user)", so I changed
> it to "User.stub!(:new)...". But I don't fully understand why I had to
> do so.
Others may have more insight, but I would want to know what the specific
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users