[rspec-devel] [ rspec-Feature Requests-14304 ] Specify the controller request in the description options

noreply at rubyforge.org noreply at rubyforge.org
Sat Oct 6 14:08:03 EDT 2007


Feature Requests item #14304, was opened at 2007-09-28 16:39
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=14304&group_id=797

Category: rails plugin
Group: None
Status: Open
Priority: 3
Submitted By: Jonathan Leighton (jonleighton)
Assigned to: Nobody (None)
Summary: Specify the controller request in the description options

Initial Comment:
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?

----------------------------------------------------------------------

Comment By: Scott Taylor (smtlaissezfaire)
Date: 2007-10-06 18:08

Message:
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

  # ...

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.  

----------------------------------------------------------------------

Comment By: Jonathan Leighton (jonleighton)
Date: 2007-10-06 15:36

Message:
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 ;)

----------------------------------------------------------------------

Comment By: Mike Mangino (mmangino)
Date: 2007-10-01 01:16

Message:
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.

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-09-30 15:05

Message:
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

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=14304&group_id=797


More information about the rspec-devel mailing list