Hi experts, I am trying to test routing in my application, where all routes are enclosed in a namespace like so: scope ''v1'' do resource :blah end collection do something end end end Is there a clean way to set ''v1'' somewhere and just write my routing tests like so: describe ''routing for blah'' do it ''should invoke show when it receives /xyz'' do { :get => ''/blah/xyz''}.should route_to(...) end end i.e., I do not want to say { :get => ''v1/blah/xyz''}.should route_to(...) Thanks, Radhesh -- Posted via http://www.ruby-forum.com/.
On Tue, Mar 22, 2011 at 6:50 PM, Radhesh Kamath <lists at ruby-forum.com>wrote:> Hi experts, > > I am trying to test routing in my application, where all routes are > enclosed in a namespace like so: > > scope ''v1'' do > resource :blah end > collection do > something > end > end > end > > Is there a clean way to set ''v1'' somewhere and just write my routing > tests like so: > > describe ''routing for blah'' do > it ''should invoke show when it receives /xyz'' do > { :get => ''/blah/xyz''}.should route_to(...) > end > end > > i.e., I do not want to say > { :get => ''v1/blah/xyz''}.should route_to(...) > > Thanks, > Radhesh > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >You''re mapping absolute strings (URL''s) to your routes. Any string manipulation would dilute the spec. In my opinion, this is not a case of keeping things DRY. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110323/2e0eb2a4/attachment.html>
On Mar 22, 2011, at 6:50 PM, Radhesh Kamath wrote:> Hi experts, > > I am trying to test routing in my application, where all routes are > enclosed in a namespace like so: > > scope ''v1'' do > resource :blah end > collection do > something > end > end > end > > Is there a clean way to set ''v1'' somewhere and just write my routing > tests like so: > > describe ''routing for blah'' do > it ''should invoke show when it receives /xyz'' do > { :get => ''/blah/xyz''}.should route_to(...) > end > end > > i.e., I do not want to say > { :get => ''v1/blah/xyz''}.should route_to(...)I don''t understand. The path ''/blah/xyz'' does not route to (...), so why would you write an example saying that it does? Pat
Justin Ko wrote in post #988825:> On Tue, Mar 22, 2011 at 6:50 PM, Radhesh Kamath > <lists at ruby-forum.com>wrote: > >> end >> >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > You''re mapping absolute strings (URL''s) to your routes. Any string > manipulation would dilute the spec. In my opinion, this is not a case of > keeping things DRY.It''s clear that you have understood my intent: keep things DRY by specifying the prefix once, and write tests as though the prefix is implicitly specified. But what do you mean by ''dilute the spec''? Do you think it might make the spec brittle? Pat: I just want to keep things DRY by specifying the ''v1'' prefix once, so the example would be ''v1/...'', only ''v1'' would be implicitly set in some way. Best, Radhesh -- Posted via http://www.ruby-forum.com/.
On Wed, Mar 23, 2011 at 10:16 AM, Radhesh Kamath <lists at ruby-forum.com>wrote:> Justin Ko wrote in post #988825: > > On Tue, Mar 22, 2011 at 6:50 PM, Radhesh Kamath > > <lists at ruby-forum.com>wrote: > > > >> end > >> > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > > > > > You''re mapping absolute strings (URL''s) to your routes. Any string > > manipulation would dilute the spec. In my opinion, this is not a case of > > keeping things DRY. > > It''s clear that you have understood my intent: keep things DRY by > specifying the prefix once, and write tests as though the prefix is > implicitly specified. > > But what do you mean by ''dilute the spec''? > Do you think it might make the spec brittle? >Routes are basically constants. By breaking this constant up (the string) in your spec, the value drops (because of clarity), in my opinion.> > Pat: > > I just want to keep things DRY by specifying the ''v1'' prefix once, so > the example would be ''v1/...'', only ''v1'' would be implicitly set in some > way. > > Best, > Radhesh > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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/20110323/2ecdafe5/attachment.html>
On Wed, Mar 23, 2011 at 12:16 PM, Radhesh Kamath <lists at ruby-forum.com> wrote:> Justin Ko wrote in post #988825: >> On Tue, Mar 22, 2011 at 6:50 PM, Radhesh Kamath >> <lists at ruby-forum.com>wrote: >> >>> ?end >>> >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> >> You''re mapping absolute strings (URL''s) to your routes. Any string >> manipulation would dilute the spec. In my opinion, this is not a case of >> keeping things DRY. > > It''s clear that you have understood my intent: keep things DRY by > specifying the prefix once, and write tests as though the prefix is > implicitly specified. > > But what do you mean by ''dilute the spec''?It makes it hard to read. You have a new concept to understand: all the routes being specified are not the routes being specified.> Do you think it might make the spec brittle? > > Pat: > > I just want to keep things DRY by specifying the ''v1'' prefix once, so > the example would be ''v1/...'', only ''v1'' would be implicitly set in some > way.What you propose would introduce an abstraction that will make it harder to understand failures in order to save a few duplicate keystrokes. This is _not_ what DRY is about. See http://www.artima.com/intv/dry.html for some background on that. Cheers, David