Max Williams
2008-Feb-22 13:26 UTC
[rspec-users] Testing misc methods in ApplicationController
I''m already successfully testing before_filters in application_controller courtesy of this blog post: http://www.movesonrails.com/articles/2008/01/23/spec-ing-your-application-controller However, i can;''t work out how to test the sort of method that is added to application_controller so that all controllers can use it. It must be something simple that i''m doing wrong/omitting, can anyone help? eg if i have this empty method in application_controller def andreplace(str) end and my spec looks like this: describe ApplicationController do describe "andreplace(str)" do it "should format ands for ferret search" do andreplace("foo and bar").should eql("+foo +bar") end end end Currently, the test breaks, saying: NoMethodError in ''ApplicationController andreplace(str) should format ands for ferret search'' undefined method `andreplace'' for #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_1:0xb64f7160> What''s going wrong here, anyone know? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080222/a5ae09d4/attachment.html
David Chelimsky
2008-Feb-22 13:46 UTC
[rspec-users] Testing misc methods in ApplicationController
On Fri, Feb 22, 2008 at 7:26 AM, Max Williams <toastkid.williams at gmail.com> wrote:> I''m already successfully testing before_filters in application_controller > courtesy of this blog post: > http://www.movesonrails.com/articles/2008/01/23/spec-ing-your-application-controller > > However, i can;''t work out how to test the sort of method that is added to > application_controller so that all controllers can use it. It must be > something simple that i''m doing wrong/omitting, can anyone help? > > eg if i have this empty method in application_controller > > def andreplace(str) > end > > and my spec looks like this: > > describe ApplicationController do > describe "andreplace(str)" do > it "should format ands for ferret search" do > andreplace("foo and bar").should eql("+foo +bar")Try this: controller.andreplace("foo and bar").should eql("+foo +bar")> end > end > end > > Currently, the test breaks, saying: > NoMethodError in ''ApplicationController andreplace(str) should format ands > for ferret search'' > undefined method `andreplace'' for > #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_1:0xb64f7160>This is a pointer to the problem - the error is telling you that the #andreplace message is going to the ExampleGroup, not the controller. HTH, David> > > What''s going wrong here, anyone know? > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Max Williams
2008-Feb-22 13:58 UTC
[rspec-users] Testing misc methods in ApplicationController
doh...dammit, i thought i''d tried that. I''m losing it... thanks! On 22/02/2008, David Chelimsky <dchelimsky at gmail.com> wrote:> > On Fri, Feb 22, 2008 at 7:26 AM, Max Williams > <toastkid.williams at gmail.com> wrote: > > I''m already successfully testing before_filters in > application_controller > > courtesy of this blog post: > > > http://www.movesonrails.com/articles/2008/01/23/spec-ing-your-application-controller > > > > However, i can;''t work out how to test the sort of method that is added > to > > application_controller so that all controllers can use it. It must be > > something simple that i''m doing wrong/omitting, can anyone help? > > > > eg if i have this empty method in application_controller > > > > def andreplace(str) > > end > > > > and my spec looks like this: > > > > describe ApplicationController do > > describe "andreplace(str)" do > > it "should format ands for ferret search" do > > andreplace("foo and bar").should eql("+foo +bar") > > > Try this: > > controller.andreplace("foo and bar").should eql("+foo +bar") > > > > end > > end > > end > > > > Currently, the test breaks, saying: > > NoMethodError in ''ApplicationController andreplace(str) should format > ands > > for ferret search'' > > undefined method `andreplace'' for > > > #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_1:0xb64f7160> > > > This is a pointer to the problem - the error is telling you that the > #andreplace message is going to the ExampleGroup, not the controller. > > HTH, > David > > > > > > > > What''s going wrong here, anyone know? > > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080222/3c3edc44/attachment.html
David Chelimsky
2008-Feb-22 14:02 UTC
[rspec-users] Testing misc methods in ApplicationController
On Fri, Feb 22, 2008 at 7:58 AM, Max Williams <toastkid.williams at gmail.com> wrote:> doh...dammit, i thought i''d tried that. I''m losing it... > > thanks!You''re welcome. Cheers, David> > > > On 22/02/2008, David Chelimsky <dchelimsky at gmail.com> wrote: > > On Fri, Feb 22, 2008 at 7:26 AM, Max Williams > > <toastkid.williams at gmail.com> wrote: > > > I''m already successfully testing before_filters in > application_controller > > > courtesy of this blog post: > > > > http://www.movesonrails.com/articles/2008/01/23/spec-ing-your-application-controller > > > > > > However, i can;''t work out how to test the sort of method that is added > to > > > application_controller so that all controllers can use it. It must be > > > something simple that i''m doing wrong/omitting, can anyone help? > > > > > > eg if i have this empty method in application_controller > > > > > > def andreplace(str) > > > end > > > > > > and my spec looks like this: > > > > > > describe ApplicationController do > > > describe "andreplace(str)" do > > > it "should format ands for ferret search" do > > > andreplace("foo and bar").should eql("+foo +bar") > > > > > > Try this: > > > > controller.andreplace("foo and bar").should eql("+foo +bar") > > > > > > > end > > > end > > > end > > > > > > Currently, the test breaks, saying: > > > NoMethodError in ''ApplicationController andreplace(str) should format > ands > > > for ferret search'' > > > undefined method `andreplace'' for > > > > #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_1:0xb64f7160> > > > > > > This is a pointer to the problem - the error is telling you that the > > #andreplace message is going to the ExampleGroup, not the controller. > > > > HTH, > > David > > > > > > > > > > > > > What''s going wrong here, anyone know? > > > > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Fernando Perez
2009-Feb-14 00:26 UTC
[rspec-users] Testing misc methods in ApplicationController
How do you spec protected controller methods such as before_filters and helpers that with the params and session hashes? I cannot call controller.my_method if my_method is protected.> Try this: > > controller.andreplace("foo and bar").should eql("+foo +bar")-- Posted via http://www.ruby-forum.com/.
Mark Wilden
2009-Feb-14 00:49 UTC
[rspec-users] Testing misc methods in ApplicationController
On Fri, Feb 13, 2009 at 4:26 PM, Fernando Perez <lists at ruby-forum.com> wrote:> How do you spec protected controller methods such as before_filters and > helpers that with the params and session hashes?You spec the public interface that calls (or causes to be called) the protected methods. ///ark
Nick Hoffman
2009-Feb-14 02:19 UTC
[rspec-users] Testing misc methods in ApplicationController
On 13/02/2009, at 7:26 PM, Fernando Perez wrote:> How do you spec protected controller methods such as before_filters > and > helpers that with the params and session hashes? > > I cannot call controller.my_method if my_method is protected. > >> Try this: >> >> controller.andreplace("foo and bar").should eql("+foo +bar")Hey Fernando. As Mark said, the idea behind BDD is to spec the behaviour of your controller, rather than each specific method. So write specs for all of the different behaviours that your controller can exhibit. This will result in your protected and private methods being called. Cheers, Nick
Possibly Parallel Threads
- - 2.3.2 uninitialized constant ApplicationController
- Plugin: can't call before_filter in ApplicationController
- Inheriting from AdminController intstead from ApplicationController
- has_many_polymorphs is breaking my spec file
- any tricks re using " eql(5.5)", but where 5.5 is a decimal not float?