[rspec-users] RSpec Routing DSL

Joe Fiorini joe at faithfulgeek.org
Tue Oct 19 14:25:55 EDT 2010


David: you're right, it's not very rspecish :) There are two changes I
made that I wonder if we could see in core are:

1) printing out the path and method in specdoc output
2) setting default scope options per context (not quite working in my
example yet)

Thoughts?

Wincent: I like what you've come up with. Much more rspecish than
mine. Doesn't seem too different from what's in rspec-rails 2.0.

On Oct 19, 3:05 am, Wincent Colaiuta <w... at wincent.com> wrote:
> El 18/10/2010, a las 20:20, Joe Fiorini escribió:
>
> > I started testing routes for the first time in Rails 3 this weekend
> > during Rails Rumble. I was so exhausted that I found writing route
> > specs a very painful task. I came up with my own routing DSL and I'd
> > love to see it get included in RSpec itself. Before I start adding the
> > code to rspec-rails, I'd like to get some feedback and see if there
> > are some ways we could clean it up. Basically the DSL looks like:
>
> > describe "My routes" do
>
> >  get "/blog" => { controller: "blogs-controller", action: "index" }
>
> > end
>
> > You can see all the details and the module used to make it work here:
> >http://gist.github.com/630176. Thoughts?
>
> I felt the same pain a while back and proposed a DSL too, but it never really got anywhere as there was no consensus about what a new DSL should look like. Full thread here:
>
>  http://groups.google.com/group/rspec/browse_thread/thread/50b46ca3e4b...
>
> I never got as far as submitting a patch because I didn't really like the alternative proposals so wasn't going to code them up (I'd already posted my own working proposal).
>
> After several iterations, the implementation that I am currently using consists of "map_to", "map_from", "have_routing" (ie. map both ways) and "be_recognized" matchers; these were chosen largely because they don't clash with the existing matchers in RSpec and so I can use them on an "opt-in" basis:
>
>  http://gist.github.com/633716
>
> Some sample specs:
>
>  http://gist.github.com/633723
>
> <tangent>
>
> One thing to note is how there are two assertions in there where I use "map_to" instead of "have_routing" because of what looks to be a bug in the Rails routing assertion macros. I think there is a Lighthouse ticket for this but the only ones related to "assert_generates" which I can find right now are:
>
>  https://rails.lighthouseapp.com/projects/8994/tickets/5260
>  https://rails.lighthouseapp.com/projects/8994/tickets/5005
>  https://rails.lighthouseapp.com/projects/8994/tickets/5689
>
> At least one of those issues (#5260, #5005) is supposedly resolved in 3.0.2. #5698 was marked as invalid. Tangentially related is this old ticket which I posted:
>
>  https://rspec.lighthouseapp.com/projects/5645/tickets/907
>
> I thought someone posted a pretty good analysis of exactly what the breakage is and why it happens, but I can't find it. :-( Guess when I get time will have to do some analysis of the Rails codebase and figure out what's happening and put together another ticket.
>
> While Googling, found this, however, describing changes in 2.0.0:
>
>  http://github.com/rspec/rspec-rails/issues/221
>
> Which notes that RSpec's "route_to" now delegates to "assert_recognizes" (a one-way assertion) rather than "assert_routing" (a two-way assertion).
>
> </tangent>
>
> Cheers,
> Wincent
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list