#446 √ awaiting-patch
Nicholas Hubbard

rspec_scaffold_generator

Reported by Nicholas Hubbard | June 23rd, 2008 @ 05:02 AM | in No-Milestone-Assigned

I was wondering if it would be possible to get an option added to the rspec_scaffold_generator that would allow us to specify not to use a name space on the model name.

This would make life so much easier when I am generating a namespaced controller for a non-namespaced model.

Comments and changes to this ticket

  • Michael Moen

    Michael Moen July 16th, 2008 @ 01:53 AM

    • → Tag changed from “” to “rspec_on_rails”

    Nicholas I was planning on looking into this before I saw your ticket. I wanted to find out from David if there was anybody working on this or any of the other namespaced "quirks" I want to take care of. David, are you watching? ;-)

  • David Chelimsky

    David Chelimsky July 16th, 2008 @ 05:55 AM

    Michael - I'm not working on anything right now, nor is anyone else that I know of. Your contributions would be welcome.

  • David Chelimsky

    David Chelimsky July 16th, 2008 @ 05:55 AM

    • → State changed from “new” to “awaiting-patch”
    • → Assigned user changed from “” to “David Chelimsky”
  • Michael Moen

    Michael Moen July 16th, 2008 @ 06:05 AM

    David,

    I tried to get the rspec-dev repo going and well... I'm a git:tard...

    What the heck did I miss, I did:

    git-clone git://github.com/dchelimsky/rspec-dev.git

    cd rspec-dev

    rake git:update

    ~/gitroot/rspec-dev$ rake git:update

    (in /Users/mmoen/gitroot/rspec-dev)

    rake aborted!

    no such file to load -- spec/version

    /Users/mmoen/gitroot/rspec-dev/rakefile:5

    Thanks,

    Michael

  • David Chelimsky

    David Chelimsky July 16th, 2008 @ 06:25 AM

    You're fine. my setup was running fine after removing the target of

    that require because I had an old gem installed :(

    Working on the fix right now. Coming shortly ...

  • David Chelimsky

    David Chelimsky July 16th, 2008 @ 06:34 AM

    Michael - go ahead and give it another shot.

    David

  • David Chelimsky

    David Chelimsky July 16th, 2008 @ 06:35 AM

    Michael - go ahead and try again (w/ a clean clone).

    Cheers,

    David

  • Michael Moen

    Michael Moen July 16th, 2008 @ 06:45 AM

    Apparently git doesn't like me. Must have been one too many "git the

    f**k outa here" comments :-/

    mmoen@shiny:~/gitroot$ git-clone git://github.com/dchelimsky/rspec-

    dev.git

    Initialize rspec-dev/.git

    Initialized empty Git repository in /Users/mmoen/gitroot/rspec-dev/.git/

    remote: Counting objects: 46912, done.

    remote: Compressing objects: 100% (10724/10724), done.

    remote: Total 46912 (delta 33458), reused 46912 (delta 33458)

    Receiving objects: 100% (46912/46912), 6.02 MiB | 348 KiB/s, done.

    Resolving deltas: 100% (33458/33458), done.

    mmoen@shiny:~/gitroot$ cd rspec-dev

    mmoen@shiny:~/gitroot/rspec-dev$ rake git:update

    (in /Users/mmoen/gitroot/rspec-dev)

    ** Fetching TextMate Bundle

    Initialize RSpec.tmbundle/.git

    Initialized empty Git repository in /Users/mmoen/gitroot/rspec-dev/

    RSpec.tmbundle/.git/

    remote: Counting objects: 46207, done.

    remote: Compressing objects: 100% (10518/10518), done.

    remote: Total 46207 (delta 33052), reused 46207 (delta 33052)

    Receiving objects: 100% (46207/46207), 5.91 MiB | 406 KiB/s, done.

    Resolving deltas: 100% (33052/33052), done.

    ** Fetching rspec

    fatal: could not create work tree dir 'example_rails_app/vendor/

    plugins/rspec'.

    ** Fetching rspec-rails

    fatal: could not create work tree dir 'example_rails_app/vendor/

    plugins/rspec-rails'.

    ** Updating rspec-dev

    Current branch master is up to date.

    *** all repos updated successfully ***

    On Jul 15, 2008, at 11:35 PM, Lighthouse wrote:

  • Michael Moen

    Michael Moen July 16th, 2008 @ 06:45 AM

    David,

    Are you on IRC someplace?

    Michael

    On Jul 15, 2008, at 11:35 PM, Lighthouse wrote:

  • Michael Moen

    Michael Moen July 16th, 2008 @ 05:38 PM

    Ok.. now that I got some sleep, it appears that example_rails_app/vendor/plugins is not in the git repo. Is that intentional? If so the docs for contributing should be updated saying that it needs to be created before doing the rake git:update

    Thanks,

    Michael

  • Michael Moen

    Michael Moen July 17th, 2008 @ 12:47 AM

    David,

    Here is an initial patch that does what Nicholas and I are looking for. Feel free to tell me I'm nuts.

    It doesn't generate the proper namespaced routes (yet) but that's a trivial thing to add by hand.

    There isn't any coverage on this stuff yet. I need to figure out how/where to put the specs. Any pointers would be great.

    Thanks,

    Michael

  • David Chelimsky

    David Chelimsky July 17th, 2008 @ 12:51 AM

    Michael - all we've been doing for the generated code is generating it and then running the generated examples. Take a look at rspec-dev/pre_commit/lib/pre_commit/rspec_on_rails.rb to see how we're doing this.

    Cheers,

    David

  • Michael Moen

    Michael Moen July 17th, 2008 @ 05:53 PM

    David,

    I managed to get my head around the testing, thanks.

    I currently have it passing the tests on everything but Rails 1.2.6. I'm attaching the patch set for you to look at if you want. I still need to figure out how to completely deal with the route generation issues in 1.2.6.

    Thanks for the help,

    Michael

  • Michael Moen

    Michael Moen July 17th, 2008 @ 05:56 PM

    Nicholas,

    I'm also attaching the rspec-rails plugin I'm using now, as long as you aren't on Rails 1.2.6 you can use it.

    ./script/generate rspec_scaffold admin/foo --skip-model-namespace && rake db:migrate && rake spec

    will generate the correct model, controllers, specs and pass all specs.

    Michael

  • Nicholas Hubbard

    Nicholas Hubbard July 17th, 2008 @ 10:01 PM

    This is awesome. Thanks for all the work. I'm on 2.1 so no problems here.

  • Michael Moen

    Michael Moen July 17th, 2008 @ 10:07 PM

    There are still some gotchas in there. I found that generating an rspec_scaffold for admin/person chokes badly. I need to look into it and see what's up. But I should probably do some real work for a bit.

  • Michael Moen
  • Michael Moen

    Michael Moen August 17th, 2008 @ 07:20 PM

    David, I finally found a little "extra" time to finish up the Rails 1.2.6 spec failures.

    I'm attaching the patches and a copy of the current rspec-rails plugin in case anybody wants to use it now.

    Thanks, Michael

  • Michael Moen
  • David Chelimsky

    David Chelimsky August 17th, 2008 @ 07:53 PM

    Hi Michael,

    This looks really good in general, and I appreciate your effort, but it constitutes a fundamental change in approach that I'm not ready to commit to.

    Currently, the rspec generators only generate rspec code examples, deferring to the rails generators for the application code.

    Your patches have rspec generating the application code. My objection to this is grounded in two points:

    1. Maintenance. Since we're replacing application code, rspec is now duplicating the effort of the rails-generators to generate the same material. When this code changes in rails, the code in rspec should change as well.

    2. Role. RSpec offers a different way of approaching code examples for rails, but does not question or challenge the design choices made in the application code. Using our own generators would change the nature of rspec in that regard.

    Now I'm not completely opposed to this, but I would like to sit back and consider whether or not this is the right direction for rspec to take?

    Anybody else have any opinions?

  • Michael Moen

    Michael Moen August 17th, 2008 @ 08:03 PM

    David,

    I completely agree with you that rspec shouldn't be generating model/controller/routing code.

    The next step I plan to take, time permitting, is to move the Rails hacks up in to Rails and see if they are interested in incorporating the changes.

    I started out making the changes at the rspec level because I'm working on a project that could benefit heavily from the changes and it's easier to have a plugin already in the app than make sure everybody has the patched Rails installed.

    I honestly didn't expect to see this get into master as is. That's why I uploaded the zipped plugin for anybody that wanted to use it.

    Thanks again for taking the time to look at this stuff and providing a great tool to begin with.

    Michael

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins