It looks like there's another way to do this in rails I just found in AWDWR:<br><br>xhr(:get, :add_to_cart, :id => 11)<br><br>I'm not sure if there are other methods like xml() etc... but that looks easier than the example I provided below.
<br><br><div><span class="gmail_quote">On 10/28/06, <b class="gmail_sendername">Jeff Dean</b> <<a href="mailto:jeff@jefdean.com">jeff@jefdean.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;">
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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://api.rubyonrails.org/classes/ActionController/Integration/Session.html#M000083
</a>. The spec might look like:<br><br><pre><span>context</span> <span>"</span><span>A get to /index</span><span>"</span> <span>do</span><span></span><br><br> <span>
specify</span> <span>"</span><span>from a browser should show html</span><span>"</span> <span>do</span><br> get :index<br> # should statements... <br><span></span><br> <span> end</span><br><br> <span>specify
</span> <span>"</span><span>in xml format should render xml</span><span>
"</span> <span>do</span><br> get :index, {}, {:content_type=>'application/xml', :accept => 'application/xml'}<br> # should statements... <span><br> end</span><br><br><span>
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>context</span> <span>"</span><span>A get to /index</span><span>"</span> <span>do</span><span></span><br><br>
<span>specify</span> <span>"</span><span>from an ajax call should render rjs</span><span>"</span> <span>do</span><br> get :index, {}, :format => :js # where the magic word 'format' correctly sets the accept header
<br><span><br></span> # should statements... <span></span><br><span> 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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">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><span class="sg"><br>Jeff</span><div><span class="e" id="q_10e909de984880b3_2"><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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Rspec-users@rubyforge.org</a><br>> <a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>><br>><br>_______________________________________________<br>Rspec-users mailing list<br><a href="mailto:Rspec-users@rubyforge.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Rspec-users@rubyforge.org</a>
<br><a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br>
</span></div></blockquote></div><br>