Matthew Rudy Jacobs
2008-Jun-24 15:22 UTC
[rspec-users] Rspec-Rails setting a header in stories?
Hi there, For my api controllers I need the following; request.ssl? == true and an api key "request.env[''HTTP_OUR_API_KEY'']" In my spec/controllers I just stub out the required code but in stories I don''t want any stubs. I''ve tried changing the .env of the existing request, but this doesn''t work. When "I GET /organisations/", "1" do |organisation_id| request.env[''HTTP_OUR_API_KEY''] = "craziness" request.env[''HTTPS''] = ''on'' get "api/v1/organisations/#{organisation_id}" end and I''ve tried passing the extra headers as a 3 argument to "get" When "I GET /organisations/", "1" do |organisation_id| get "api/v1/organisations/#{organisation_id}", {}, {''HTTPS'' => ''on'', ''HTTP_ASPIRE_API_KEY'' => ''something''} end but neither of these work. Anyone got any insight into this? My version of rspec-rails is as follows; module Spec module Rails module VERSION #:nodoc: BUILD_TIME_UTC = 20080528130840 end end end Thanks, MatthewRudy -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2008-Jun-24 15:28 UTC
[rspec-users] Rspec-Rails setting a header in stories?
On Jun 24, 2008, at 10:22 AM, Matthew Rudy Jacobs wrote:> Hi there, > > For my api controllers I need the following; > request.ssl? == true > and > an api key "request.env[''HTTP_OUR_API_KEY'']" > > In my spec/controllers I just stub out the required code > but in stories I don''t want any stubs.Stories wrap Rails IntegrationTest, not Rails FunctionalTest, so what you have access to is different. The methods look the same, but they actually go through routing and work a little differently. Check out: http://api.rubyonrails.org/classes/ActionController/Integration/Session.html Cheers, David> I''ve tried changing the .env of the existing request, > but this doesn''t work. > > When "I GET /organisations/", "1" do |organisation_id| > request.env[''HTTP_OUR_API_KEY''] = "craziness" > request.env[''HTTPS''] = ''on'' > get "api/v1/organisations/#{organisation_id}" > end > > and I''ve tried passing the extra headers as a 3 argument to "get" > > When "I GET /organisations/", "1" do |organisation_id| > get "api/v1/organisations/#{organisation_id}", {}, {''HTTPS'' => ''on'', > ''HTTP_ASPIRE_API_KEY'' => ''something''} > end > > but neither of these work. > > Anyone got any insight into this? > > My version of rspec-rails is as follows; > module Spec > module Rails > module VERSION #:nodoc: > BUILD_TIME_UTC = 20080528130840 > end > end > end > > Thanks, > > MatthewRudy > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Matthew Rudy Jacobs
2008-Jun-24 15:33 UTC
[rspec-users] Rspec-Rails setting a header in stories?
David Chelimsky wrote:> On Jun 24, 2008, at 10:22 AM, Matthew Rudy Jacobs wrote: > >> Hi there, >> >> For my api controllers I need the following; >> request.ssl? == true >> and >> an api key "request.env[''HTTP_OUR_API_KEY'']" >> >> In my spec/controllers I just stub out the required code >> but in stories I don''t want any stubs. > > Stories wrap Rails IntegrationTest, not Rails FunctionalTest, so what > you have access to is different. The methods look the same, but they > actually go through routing and work a little differently. > > Check out: > http://api.rubyonrails.org/classes/ActionController/Integration/Session.html > > Cheers, > DavidOh really. Cheers David... so the "3rd argument" solution should be working. Will have to take a closer look... Thanks again -- Posted via http://www.ruby-forum.com/.
Matthew Rudy Jacobs
2008-Jun-24 16:34 UTC
[rspec-users] Rspec-Rails setting a header in stories?
David Chelimsky wrote:> On Jun 24, 2008, at 10:22 AM, Matthew Rudy Jacobs wrote: > >> Hi there, >> >> For my api controllers I need the following; >> request.ssl? == true >> and >> an api key "request.env[''HTTP_OUR_API_KEY'']" >> >> In my spec/controllers I just stub out the required code >> but in stories I don''t want any stubs. > > Stories wrap Rails IntegrationTest, not Rails FunctionalTest, so what > you have access to is different. The methods look the same, but they > actually go through routing and work a little differently. > > Check out: > http://api.rubyonrails.org/classes/ActionController/Integration/Session.html > > Cheers, > DavidI think much of my problem was not quite understanding how stories were supposed to work, (notably I was trying to redefine "When I call the api" in two different scenarios, but only one of these gets used in both cases) But I think I''ve got an agreeable end-product. http://pastie.org/221205 Thanks once more. MatthewRudy -- Posted via http://www.ruby-forum.com/.