#121 new
Chad Humphries

[#14304] Specify the controller request in the description options

Reported by Chad Humphries | November 19th, 2007 @ 06:31 AM

I was experimenting with metaprogramming some of my examples, in order to keep my specs DRY, and I needed some way to programmatically specify what the request being tested was. I came up with this:

describe ArticlesController, :request => { :get => :show, :id => 53 } do
  it "should find the article" do
    Article.expects(:find).with(53)
    send_request
  end
end

Here is my code: http://pastie.caboo.se/101764

I would be willing to make this into a patch if it sounds like a good idea?

Comments and changes to this ticket

  • Chad Humphries

    Chad Humphries November 19th, 2007 @ 06:32 AM

    Date: 2007-10-06 14:08

    Sender: Scott Taylor

    Personally, I really like this option. I've found myself doing

    the same thing over and over again:

    describe SomeController do

    def do_action

    get :something, :id => 1

    end

    it "should blah blah" do

    do_action

    assertion

    end

    it "should do blah blah" do

    assertion

    do_action

    end

    1. ...

    end

    The question is not whether RSpec is too bloated (nor that the

    example is not DRY)- the question is if it makes the tests more

    readable or understandable. Maybe with the right syntax it

    would.

    Date: 2007-10-06 11:36

    Sender: Jonathan Leighton

    Mike: I agree with you in general but I created it in order

    to solve the problem of knowing what request to use if I was

    defining my own example generator such as

    "it_should_redirect_to :index".

    I guess another approach might be to have the last argument

    specify the request, eg:

    it_should_redirect_to :index, :get => :create

    I'm going to stick a post on my blog about it, though I

    doubt many people will read that ;)

    Date: 2007-09-30 21:16

    Sender: Mike Mangino

    I don't care for this at all. If you want this behavior, you

    could easily define the send_request method yourself. It just

    seems like a really obscure syntax. I'd rather the action performed

    by send_request be made more explicit.

    Date: 2007-09-30 11:05

    Sender: David Chelimsky

    It sounds like a good idea, but I'd like to get more feedback

    first.

    How about blogging it or releasing it as a plugin so people can

    get some experience with it. If the feedback is generally positive

    I'd be open to adding it.

    The only reason I'm not jumping on it is that I've been feeling

    as though RSpec has become too bloated as it is, and I'm hesitant

    to add any new features without careful consideration.

    It does sound like a good idea, and I'll be exploring it myself

    on my own projects.

    Cheers,

    David

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

People watching this ticket