[rspec-users] nuby: how spec redirect_to at ApplicationController

Courtenay court3nay at gmail.com
Wed Aug 15 16:30:04 EDT 2007


On 8/15/07, Priit Tamboom <priit.tamboom at gmail.com> wrote:
> Good morning rspec people!
>
> Still rspec nuby: I must do something wrong obviously.
>
> How can I spec about redirect_to at ApplicationController
>
> describe ApplicationController do
>    it "method login_required should redirect to home path without login" do

heh.  "it" is so out of place here :)

>      pending "I tried to use
> controller.login_required.should be_redirected
>         and got NoMethodError with nil object didn't expect error."
>    end
> end
>

like
  controller.should_receive(:redirect_to)
  controller.send :login_required

??

or

  controller.should_receive(:current_user).and_return(nil)
  get :foo
  response.should redirect_to(...)



> class ApplicationController < ActionController::Base
>   # using it with before_filter
>   def login_required
>      # I took out everything except redirecting to make the point simple
>      redirect_to home_path  # tried also redirect_to "/"
>   end
> end
>
> However the code does work manually testing with browser.
>
> Thanks for any help,
> Priit
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list