[rspec-users] Spec'ing the result of rescue_from

David Chelimsky dchelimsky at gmail.com
Mon Jun 22 18:43:14 EDT 2009


On Mon, Jun 22, 2009 at 5:19 PM, PJ Kelly<pj at crushlovely.com> wrote:
> Hey All,
>
> In my app, I have actions that are restricted to only POST requests in
> config/routes.rb.  We were getting a fair number of MethodNotAllowed
> errors on these actions.  In most cases, we're ok with sending the
> user back to the homepage, however there are a few exceptions where
> we'd like to send them a specific action.  My spec looks like this:
>
>  describe "GET process_step_2" do
>    it "should redirect to step_2" do
>      rescue_action_in_public!
>      get :process_step_2
>      response.should redirect_to(application_step_2_url)
>    end
>  end
>
> Then my application controller, I decided to rescue_from, so it looks
> like this:
>
> class ApplicationController < ActionController::Base
>  rescue_from ActionController::MethodNotAllowed, :with
> => :invalid_method
>
>  protected
>
>  def invalid_method
>    redirect_to previous_step_url
>  end
>
>  def previous_step_url
>    case request.env["REQUEST_URI"]
>    when /step_2\/process/
>      application_step_2_url
>    else
>      root_url
>    end
>  end
> end
>
> The spec fails even though when you re-create the situation in the
> browser, the code works.

What's the failure message?

>
> What am I doing wrong here?  Am I even going about this in the right
> way?
>
> Thanks in advance for your help.
>
> Best, PJ
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list