[rspec-users] GET a path in a controller spec

Nick Hoffman lists at ruby-forum.com
Sun Jan 31 17:02:05 EST 2010

One of my controller actions sends a redirect if the request URI begins
with /foods/search

  34  def search
  35    return redirect_to "/#{params[:name]}" if
request.request_uri.match /^\/foods\/search/

Unfortunately, I can't figure out how to spec this.

>From everything that I've read while researching this problem, it seems
that #get and #post only accept the action to call, and a hash of
parameters. IE:
  get :action, :some => 'param'
As a result, I can't do this:
  121  it 'redirects /foods/search/almonds to /almonds' do
  122    get '/foods/search/almonds'
  123    response.should redirect_to "/almonds"
  124  end

How can I spec this?

Thanks for your help,
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list