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

J2M james2mccarthy at gmail.com
Tue Aug 5 06:20:11 EDT 2008


I'm not having much luck posting here, every other reply seems to go
astray! So if I double post sorry!

I'm using
Rails 2.1
Rspec 1.1.4

Any ideas why this isn't giving the correct response in Rspec but is
in the wild?


On Aug 4, 4:31 pm, J2M <james2mccar... at gmail.com> wrote:
> 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
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list