Hi all, This is probably a stupid question, but I can''t figure out how to do this..... If I have some routes which require SSL, how do I test that with RSpec? For example: # routes.rb scope :constraints => { :protocol => "https" } do match ''/foos.(:format)'' => ''foos#index'', :via => :get, :constraints => { :format => /(json|xml)/ } end In my routing spec, I''ve tried the following variants with no luck: describe "routing to foos" do it "routes /foos.json to foos#index" do { :get => "/foos.json", :protocol => "https" }.should route_to( :controller => "foos", :action => "index", :format => "json" ) end describe "routing to foos" do it "routes /foos.json to foos#index" do { :get => "/foos.json" }.should route_to( :controller => "foos", :action => "index", :format => "json", :protocol => "https" ) end Thanks in advance for any help. BP
Anybody? On Dec 9, 3:22?pm, Brian Ploetz <bplo... at gmail.com> wrote:> Hi all, > > This is probably a stupid question, but I can''t figure out how to do > this..... > > If I have some routes which require SSL, how do I test that with > RSpec? For example: > > # routes.rb > scope :constraints => { :protocol => "https" } do > ? match ''/foos.(:format)'' => ''foos#index'', :via => :get, :constraints > => { :format => /(json|xml)/ } > end > > In my routing spec, I''ve tried the following variants with no luck: > > describe "routing to foos" do > ? it "routes /foos.json to foos#index" do > ? ? { :get => "/foos.json", :protocol => "https" }.should route_to( > ? ? ? :controller => "foos", > ? ? ? :action => "index", > ? ? ? :format => "json" > ? ? ) > ? end > > describe "routing to foos" do > ? it "routes /foos.json to foos#index" do > ? ? { :get => "/foos.json" }.should route_to( > ? ? ? :controller => "foos", > ? ? ? :action => "index", > ? ? ? :format => "json", > ? ? ? :protocol => "https" > ? ? ) > ? end > > Thanks in advance for any help. > BP > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote:> Anybody? > > On Dec 9, 3:22 pm, Brian Ploetz <bplo... at gmail.com> wrote: >> Hi all, >> >> This is probably a stupid question, but I can''t figure out how to do >> this..... >> >> If I have some routes which require SSL, how do I test that with >> RSpec? For example: >> >> # routes.rb >> scope :constraints => { :protocol => "https" } do >> match ''/foos.(:format)'' => ''foos#index'', :via => :get, :constraints >> => { :format => /(json|xml)/ } >> end >> >> In my routing spec, I''ve tried the following variants with no luck: >> >> describe "routing to foos" do >> it "routes /foos.json to foos#index" do >> { :get => "/foos.json", :protocol => "https" }.should route_to( >> :controller => "foos", >> :action => "index", >> :format => "json" >> ) >> end >> >> describe "routing to foos" do >> it "routes /foos.json to foos#index" do >> { :get => "/foos.json" }.should route_to( >> :controller => "foos", >> :action => "index", >> :format => "json", >> :protocol => "https" >> ) >> end >> >> Thanks in advance for any help.There is an open issue in the Rails tracker about this [1]. assert_recognizes, to which "should route_to" delegates, does not yet support constraints. Sadly, this means there is no good way to do this at the moment. [1] https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_recognizes-does-not-support-constraints for more info. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101213/24c146bd/attachment-0001.html>
OK, cool. I''ll avoid banging my head against the wall in the mean time. :-) Thanks alot David. BP On Dec 13, 9:16?am, David Chelimsky <dchelim... at gmail.com> wrote:> On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote: > > > > > Anybody? > > > On Dec 9, 3:22 pm, Brian Ploetz <bplo... at gmail.com> wrote: > >> Hi all, > > >> This is probably a stupid question, but I can''t figure out how to do > >> this..... > > >> If I have some routes which require SSL, how do I test that with > >> RSpec? For example: > > >> # routes.rb > >> scope :constraints => { :protocol => "https" } do > >> ? match ''/foos.(:format)'' => ''foos#index'', :via => :get, :constraints > >> => { :format => /(json|xml)/ } > >> end > > >> In my routing spec, I''ve tried the following variants with no luck: > > >> describe "routing to foos" do > >> ? it "routes /foos.json to foos#index" do > >> ? ? { :get => "/foos.json", :protocol => "https" }.should route_to( > >> ? ? ? :controller => "foos", > >> ? ? ? :action => "index", > >> ? ? ? :format => "json" > >> ? ? ) > >> ? end > > >> describe "routing to foos" do > >> ? it "routes /foos.json to foos#index" do > >> ? ? { :get => "/foos.json" }.should route_to( > >> ? ? ? :controller => "foos", > >> ? ? ? :action => "index", > >> ? ? ? :format => "json", > >> ? ? ? :protocol => "https" > >> ? ? ) > >> ? end > > >> Thanks in advance for any help. > > There is an open issue in the Rails tracker about this [1]. assert_recognizes, to which "should route_to" delegates, does not yet support constraints. Sadly, this means there is no good way to do this at the moment. > > [1]https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_rec...for more info. > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Actually, Rails seems to correctly support *some* routing constraints in tests (:format being one), but not others (:protocol being one). I''m coming up with a failing test which I''ll attach to that Rails ticket, but just noting it here as an FYI to others... On Dec 13, 9:43?am, Brian Ploetz <bplo... at gmail.com> wrote:> OK, cool. I''ll avoid banging my head against the wall in the mean > time. :-) > > Thanks alot David. > BP > > On Dec 13, 9:16?am, David Chelimsky <dchelim... at gmail.com> wrote: > > > On Dec 13, 2010, at 7:55 AM, Brian Ploetz wrote: > > > > Anybody? > > > > On Dec 9, 3:22 pm, Brian Ploetz <bplo... at gmail.com> wrote: > > >> Hi all, > > > >> This is probably a stupid question, but I can''t figure out how to do > > >> this..... > > > >> If I have some routes which require SSL, how do I test that with > > >> RSpec? For example: > > > >> # routes.rb > > >> scope :constraints => { :protocol => "https" } do > > >> ? match ''/foos.(:format)'' => ''foos#index'', :via => :get, :constraints > > >> => { :format => /(json|xml)/ } > > >> end > > > >> In my routing spec, I''ve tried the following variants with no luck: > > > >> describe "routing to foos" do > > >> ? it "routes /foos.json to foos#index" do > > >> ? ? { :get => "/foos.json", :protocol => "https" }.should route_to( > > >> ? ? ? :controller => "foos", > > >> ? ? ? :action => "index", > > >> ? ? ? :format => "json" > > >> ? ? ) > > >> ? end > > > >> describe "routing to foos" do > > >> ? it "routes /foos.json to foos#index" do > > >> ? ? { :get => "/foos.json" }.should route_to( > > >> ? ? ? :controller => "foos", > > >> ? ? ? :action => "index", > > >> ? ? ? :format => "json", > > >> ? ? ? :protocol => "https" > > >> ? ? ) > > >> ? end > > > >> Thanks in advance for any help. > > > There is an open issue in the Rails tracker about this [1]. assert_recognizes, to which "should route_to" delegates, does not yet support constraints. Sadly, this means there is no good way to do this at the moment. > > > [1]https://rails.lighthouseapp.com/projects/8994/tickets/5805-assert_rec...more info. > > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users