Priit Tamboom
2007-Aug-15 19:14 UTC
[rspec-users] nuby: how spec redirect_to at ApplicationController
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 pending "I tried to use controller.login_required.should be_redirected and got NoMethodError with nil object didn''t expect error." end end 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070816/9f4d994e/attachment.html
Courtenay
2007-Aug-15 20:30 UTC
[rspec-users] nuby: how spec redirect_to at ApplicationController
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" doheh. "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 >
David Chelimsky
2007-Aug-15 20:48 UTC
[rspec-users] nuby: how spec redirect_to at ApplicationController
On 8/15/07, Courtenay <court3nay at gmail.com> wrote:> On 8/15/07, Priit Tamboom <priit.tamboom at gmail.com> wrote:> > describe ApplicationController do > > it "method login_required should redirect to home path without login" do > > heh. "it" is so out of place here :)I agree. The goal is to describe behaviours of objects, not methods. So, I''d write: it "should redirect anonymous user to home path" Cheers, David
Priit Tamboom
2007-Aug-24 09:57 UTC
[rspec-users] nuby: how spec redirect_to at ApplicationController
On 8/16/07, David Chelimsky <dchelimsky at gmail.com> wrote:> > On 8/15/07, Courtenay <court3nay at gmail.com> wrote: > > On 8/15/07, Priit Tamboom <priit.tamboom at gmail.com> wrote: > > > > describe ApplicationController do > > > it "method login_required should redirect to home path without > login" do > > > > heh. "it" is so out of place here :) > > I agree. The goal is to describe behaviours of objects, not methods. > So, I''d write: > > it "should redirect anonymous user to home path" > > Cheers, > David > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >Thanks for great answers! By the way, David, your blog post was good additional help about what to do with application methods: http://blog.davidchelimsky.net/articles/2007/06/03/oxymoron-testing-behaviour-of-abstractions I wonder how far you go just testing "concrete" controllers. For example, if I move login methods from application controller to module under lib directory then do you change your style (write separate spec for module) or just keep testing concrete controllers as usually you do. Oki, Priit -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070824/8f3dbf9f/attachment-0001.html
David Chelimsky
2007-Aug-24 14:05 UTC
[rspec-users] nuby: how spec redirect_to at ApplicationController
On 8/24/07, Priit Tamboom <priit.tamboom at eesti.ee> wrote:> On 8/16/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > On 8/15/07, Courtenay <court3nay at gmail.com> wrote: > > > On 8/15/07, Priit Tamboom <priit.tamboom at gmail.com> wrote: > > > > > > describe ApplicationController do > > > > it "method login_required should redirect to home path without > login" do > > > > > > heh. "it" is so out of place here :) > > > > I agree. The goal is to describe behaviours of objects, not methods. > > So, I''d write: > > > > it "should redirect anonymous user to home path" > > > > Cheers, > > David > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > Thanks for great answers! > > By the way, David, your blog post was good additional help about what to do > with application methods: > http://blog.davidchelimsky.net/articles/2007/06/03/oxymoron-testing-behaviour-of-abstractions > > I wonder how far you go just testing "concrete" controllers. For example, if > I move login methods from application controller to module under lib > directory then do you change your style (write separate spec for module) or > just keep testing concrete controllers as usually you do.Typically I''d only move something up to Application when I find that I need it in two controllers. But I start by implementing it (spec-first) in both. Then I''ve got duplicated specs and duplicated code. Then I''d extract a shared behaviour, followed by moving the method up to Application. Which extraction happens first is not important - what IS important is that they are separate activities and you don''t start the second extraction until you have a green bar. Cheers, David> > Oki, > Priit > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >