Thanks for the quick reply - <br><br>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
<a href="http://api.rubyonrails.org/classes/ActionController/Integration/Session.html#M000083">http://api.rubyonrails.org/classes/ActionController/Integration/Session.html#M000083</a>. The spec might look like:<br><br><pre>
<span class="ident">context</span> <span class="punct">"</span><span class="string">A get to /index</span><span class="punct">"</span> <span class="keyword">do</span><span class="keyword"></span><br><br> <span class="ident">
specify</span> <span class="punct">"</span><span class="string">from a browser should show html</span><span class="punct">"</span> <span class="keyword">do</span><br> get :index<br> # should statements...
<span class="keyword"></span><br> <span class="keyword"> end</span><br><br> <span class="ident">specify</span> <span class="punct">"</span><span class="string">in xml format should render xml</span><span class="punct">
"</span> <span class="keyword">do</span><br> get :index, {}, {:content_type=>'application/xml', :accept => 'application/xml'}<br> # should statements... <span class="keyword"><br> end</span><br><br><span class="keyword">
end</span>
</pre>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:
<br><pre><span class="ident">context</span> <span class="punct">"</span><span class="string">A get to /index</span><span class="punct">"</span> <span class="keyword">do</span><span class="keyword"></span><br><br>
<span class="ident">specify</span> <span class="punct">"</span><span class="string">from an ajax call should render rjs</span><span class="punct">"</span> <span class="keyword">do</span><br> get :index, {}, :format => :js # where the magic word 'format' correctly sets the accept header
<span class="keyword"><br></span> # should statements... <span class="keyword"></span><br><span class="keyword"> end</span><span style="font-family: arial,sans-serif;"><br><br>end<br></span></pre>
References:<br>
<ul><li><a href="http://www.loudthinking.com/arc/000572.html">http://www.loudthinking.com/arc/000572.html</a></li></ul>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 -
<br><br>Jeff<br><br><br><div><span class="gmail_quote">On 10/28/06, <b class="gmail_sendername">David Chelimsky</b> <<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 10/28/06, Jeff Dean <<a href="mailto:jeff@jefdean.com">jeff@jefdean.com</a>> wrote:<br>> Is anyone using RSpec with RESTful rails apps? In my rails controllers I<br>> check request.respond_to? and render different views accordingly.
<br>><br>> I noticed that the get method in the rails plugin doesn't accept headers:<br>><br>> controller_mixin.rb line 92<br>> def get(action, parameters = nil)<br>> @request.env['REQUEST_METHOD'] = 'GET'
<br>> process action, parameters<br>> end<br>><br>> Has anyone found a way around this?<br><br>Hi Jeff. We're getting ready to release a new version of the plugin so<br>now is a good time to at least consider addressing this. Can you write
<br>an example of how you'd want to be able to write the spec (and<br>controller code) for a restful get request? Don't worry about how<br>rspec would do it. I just want to know what you want it to do.<br><br>Thanks,<br>David
<br><br>><br>> Jeff<br>><br>> _______________________________________________<br>> Rspec-users mailing list<br>> <a href="mailto:Rspec-users@rubyforge.org">Rspec-users@rubyforge.org</a><br>> <a href="http://rubyforge.org/mailman/listinfo/rspec-users">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>><br>><br>_______________________________________________<br>Rspec-users mailing list<br><a href="mailto:Rspec-users@rubyforge.org">Rspec-users@rubyforge.org</a>
<br><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br>