[rspec-users] trying to spec login requirement with a shared example

Jay Donnell jaydonnell at yahoo.com
Wed Feb 6 20:50:36 EST 2008

In all of my controller specs I have tests that look something like this.

it "should require login" do
  get :edit, :id => '7'
  response.should redirect_to(new_session_path)

I'd like to move this to a shared example, but the request call (get() or post()) varies with each example. Is there a good way to tell the shared example how to request the page?

I thought about doing something like this

describe "whatever" do
  def request_page
    get :edit, :id => '7'

  # use shared example

then in the shared example I would call request_page() instead. Although this is slightly more DRY it isn't saving me any lines of code and it feels like there could be a better way. Another idea I had was to make a helper function that returns a Proc (basically I'm faking currying) and I could bind that Proc to something like @request_proc and then run the proc in the shared example. 

Anyone have any better ideas?


Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping

More information about the rspec-users mailing list