[Rspec-users] RSpec, REST and different formats
Jeff Dean
jeff at jefdean.com
Sat Oct 28 16:30:37 EDT 2006
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20061028/78ca665d/attachment-0001.html
More information about the Rspec-users
mailing list