[rspec-users] Rspec doesn't pickup the status code correctly.

J2M james2mccarthy at gmail.com
Mon Aug 4 11:31:28 EDT 2008



On Aug 4, 5:16 am, Steve <vertebr... at gmail.com> wrote:
> J2M wrote:
> > I'm setting the status code on a controller action but rspec doesn't
> > seem to be catching it in my spec. It works in the browser.
>
> > This is the controller method, called via xhr with header Accept:
> > 'application/json'
>
> >   def validate
> >     account = Account.new(:login => params[:login])
> >     account.valid?
> >     unless (errors = account.errors['login'])
> >       url = ['http:','', request.host, params[:login]].join('/')
> >       respond_to do |format|
> >         format.json { render :json => { :url => url } }
> >       end
> >     else
> >       url = ['http:','', request.host].join('/')
> >       respond_to do |format|
> >         format.json { render :json => {:errors => errors, :url =>
> > url }, :status => 409}
> >       end
> >     end
> >   end
>
> I don't know if it's the cause, but your unless statement is an
> assignment, and not an equality comparison:
>
> unless (errors = account.errors['login'])

That's just me being lazy I'm assigning errors I could have put that
as;

errors = account.errors['login'] if account.errors['login']

But it isn't the cause as it works in the wild, it is just the spec
that fails.

Thanks,
James




More information about the rspec-users mailing list