[rspec-users] Possible improvements to routing spec API

Lalish-Menagh, Trevor trev at trevreport.org
Tue Jul 6 19:16:00 EDT 2010

Hi David,

You make a good point. I was talking with a coworker about this
problem, and he suggested a simpler format, that I think will coincide
some with Wincent's thoughts. Here is my next stab
describe "routing" do
  it "recognizes and generates #index" do
    get("/days").should have_routing('days#index')

  it "generates #index" do
    get("/days").should generate('days#index')

  it "recognizes #index" do
    ('days#index').should recognize get("/days")

  describe "nested in students" do
    it "recognizes #index" do
      ('days#index').with(:student_id => "1").should recognize

- I am using have_routing, recognize, and generate because those are
the verbs used in Rails for the functions we are wrapping.
- I like using the word "with" to represent "extras," in the Rails API
(see http://edgeapi.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html),
since I think it fits here, and we already use with in RSpec in other
places (like stubs, etc.).
- I like using get('path') since it is similar to the routing calls in
the Rails 3 route file, and I think it is easy to intuit.
- We can use the hash notation to conform to Rails 3, with an option
to provide a full hash as well (Rails 2 style).
- The format still reads like English, and using "have_routing"
instead of "routes_to" avoids the "_to" and "_from" problem that we
have been talking about, PLUS it makes it easier to draw a
relationship between the RSpec command and the Test::Unit command
- Using these verbs still allow "should_not" to make sense.


On Tue, Jul 6, 2010 at 9:14 AM, David Chelimsky <dchelimsky at gmail.com> wrote:
> Hey Trevor,
> These are all great DSL ideas, but they strike me as being sufficiently different from anything else in either RSpec or Rails that it would be for confusing for users.
> Do you have any thoughts on the other proposals?
> Cheers,
> David

Trevor Lalish-Menagh
484.868.6150 mobile
trev at trevreport.org

More information about the rspec-users mailing list