[Rspec-users] RSpec, REST and different formats

Chris Anderson jchris at mfdz.com
Sun Oct 29 04:29:43 EST 2006


Of course, it is important to note that Rails also supports a few other http
verbs in addition to get: post, put and delete.

I really think rspec will be the ideal vehicle for Rails integration tests,
once it is mature. I look forward to the day I can start a new application
by writing high-level integration specs, and then see those tests pass as I
stitch together the controllers and models.

Chris

On 10/28/06, Jeff Dean <jeff at jefdean.com> wrote:
>
> It looks like there's another way to do this in rails I just found in
> AWDWR:
>
> xhr(:get, :add_to_cart, :id => 11)
>
> I'm not sure if there are other methods like xml() etc... but that looks
> easier than the example I provided below.
>
> On 10/28/06, Jeff Dean <jeff at jefdean.com> wrote:
> >
> > Thanks for the quick reply -
> >
> > I would be looking for a way to easily specify the most common types in
> > shorthand, but have the ability to specify full HTTP headers if I want to.
> > Ideally I would look for a third parameter in the get/post/put/delete
> > methods that accepts a hash of http headers like http://api.rubyonrails.org/classes/ActionController/Integration/Session.html#M000083
> > .  The spec might look like:
> >
> > context "A get to /index" do
> >
> >
> > specify "from a browser should show html" do
> >     get :index
> >     # should statements...
> >
> >   end
> >
> >   specify
> >  "in xml format should render xml
> > " do
> >     get :index, {}, {:content_type=>'application/xml', :accept => 'application/xml'}
> >     # should statements...
> >   end
> >
> >
> > end
> >
> > It seems like the convention in rails right now is to request rss and
> > atom feeds by using the .rss/.atom extensions and changing the 'accepts'
> > header in application.rb - so that leaves us with 4 fairly standard
> > request types: html, javascript, xml and mobile devices (which I know little
> > about).  Since these will be so common, some syntactic sugar would be nice
> > as well - maybe something like:
> >
> > context "A get to /index" do
> >
> >
> >   specify "from an ajax call should render rjs" do
> >     get :index, {}, :format => :js # where the magic word 'format' correctly sets the accept header
> >
> >
> >     # should statements...
> >   end
> >
> > end
> >
> > References:
> >
> >    - http://www.loudthinking.com/arc/000572.html
> >
> > I'd love to see these generators and plugins become part of core, too.
> > After working with RSpec for a few days now, I doubt I'll ever go back to
> > the unit and functional tests.  Thanks for the hard work -
> >
> > Jeff
> >
> >
> > On 10/28/06, David Chelimsky < dchelimsky at gmail.com> wrote:
> > >
> > > On 10/28/06, Jeff Dean <jeff at jefdean.com> wrote:
> > > > Is anyone using RSpec with RESTful rails apps?  In my rails
> > > controllers I
> > > > check request.respond_to? and render different views accordingly.
> > > >
> > > > I noticed that the get method in the rails plugin doesn't accept
> > > headers:
> > > >
> > > > controller_mixin.rb line 92
> > > > def get(action, parameters = nil)
> > > >         @request.env['REQUEST_METHOD'] = 'GET'
> > > >         process action, parameters
> > > > end
> > > >
> > > > Has anyone found a way around this?
> > >
> > > Hi Jeff. We're getting ready to release a new version of the plugin so
> > > now is a good time to at least consider addressing this. Can you write
> > >
> > > an example of how you'd want to be able to write the spec (and
> > > controller code) for a restful get request? Don't worry about how
> > > rspec would do it. I just want to know what you want it to do.
> > >
> > > Thanks,
> > > David
> > >
> > > >
> > > > Jeff
> > > >
> > > > _______________________________________________
> > > > Rspec-users mailing list
> > > > Rspec-users at rubyforge.org
> > > > http://rubyforge.org/mailman/listinfo/rspec-users
> > > >
> > > >
> > > _______________________________________________
> > > Rspec-users mailing list
> > > Rspec-users at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/rspec-users
> > >
> >
> >
>
> _______________________________________________
> Rspec-users mailing list
> Rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>


-- 
Chris Anderson
http://mfdz.com/jchris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20061029/3b7a23a6/attachment.html 


More information about the Rspec-users mailing list