When working with views, I use instance methods of ApplicationHelper: # app/helpers/application_helper.rb: module ApplicationHelper def distribute(total, min, cutof, list) [1,2,3] end end # app/views/planner/_mta_colors.rhtml: <td> <% ... dist = distribute(total_v_px, 4, 0, colors.collect{|color| color[1]}) ... %> So to test the distribute method in ApplicationHelper, I have to extend my spec models: describe ApplicationHelper do extend(ApplicationHelper) it "doesn''t find what it''s looking for do distribute(1,2,3,[4,5,6]).should eql([1,2,3]) end end This could use some documentation. -- View this message in context: http://www.nabble.com/ApplicationHelper-tp16149622p16149622.html Sent from the rspec-users mailing list archive at Nabble.com.
You could just write specs for ApplicationHelper::distribute -Corey On Wed, Mar 19, 2008 at 3:55 PM, nzook <Nathan.Zook at amd.com> wrote:> > When working with views, I use instance methods of ApplicationHelper: > > # app/helpers/application_helper.rb: > module ApplicationHelper > def distribute(total, min, cutof, list) > [1,2,3] > end > end > > # app/views/planner/_mta_colors.rhtml: > <td> > <% > ... > dist = distribute(total_v_px, 4, 0, colors.collect{|color| color[1]}) > ... > %> > > So to test the distribute method in ApplicationHelper, I have to extend my > spec models: > describe ApplicationHelper do > extend(ApplicationHelper) > it "doesn''t find what it''s looking for do > distribute(1,2,3,[4,5,6]).should eql([1,2,3]) > end > end > > This could use some documentation. > > > -- > View this message in context: > http://www.nabble.com/ApplicationHelper-tp16149622p16149622.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- http://www.coreyhaines.com The Internet''s Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080320/c47494c2/attachment.html
If I need to have it interact with the object it is mixed into, I usually put the following above my examples class TestMixer include MyMixIn end or, even, class TestMixer end then, in the spec, TestMixer.include MyMixIn On Thu, Mar 20, 2008 at 2:30 PM, Corey Haines <coreyhaines at gmail.com> wrote:> You could just write specs for ApplicationHelper::distribute > > -Corey > > > On Wed, Mar 19, 2008 at 3:55 PM, nzook <Nathan.Zook at amd.com> wrote: > > > > > When working with views, I use instance methods of ApplicationHelper: > > > > # app/helpers/application_helper.rb: > > module ApplicationHelper > > def distribute(total, min, cutof, list) > > [1,2,3] > > end > > end > > > > # app/views/planner/_mta_colors.rhtml: > > <td> > > <% > > ... > > dist = distribute(total_v_px, 4, 0, colors.collect{|color| color[1]}) > > ... > > %> > > > > So to test the distribute method in ApplicationHelper, I have to extend > > my > > spec models: > > describe ApplicationHelper do > > extend(ApplicationHelper) > > it "doesn''t find what it''s looking for do > > distribute(1,2,3,[4,5,6]).should eql([1,2,3]) > > end > > end > > > > This could use some documentation. > > > > > > -- > > View this message in context: > > http://www.nabble.com/ApplicationHelper-tp16149622p16149622.html > > Sent from the rspec-users mailing list archive at Nabble.com. > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > -- > http://www.coreyhaines.com > The Internet''s Premiere source of information about Corey Haines-- http://www.coreyhaines.com The Internet''s Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080320/2fcbc900/attachment.html
That shouldn''t be needed. In my spec''s it works fine. does: describe ApplicationHelper do it "doesn''t find what it''s looking for do helper.distribute(1,2,3,[4,5,6]).should eql([1,2,3]) end end work? I know that there was some talk of introducing an explicit helper object on the list. JD On Mar 20, 2008, at 11:30 AM, Corey Haines wrote:> You could just write specs for ApplicationHelper::distribute > > -Corey > > On Wed, Mar 19, 2008 at 3:55 PM, nzook <Nathan.Zook at amd.com> wrote: > > When working with views, I use instance methods of ApplicationHelper: > > # app/helpers/application_helper.rb: > module ApplicationHelper > def distribute(total, min, cutof, list) > [1,2,3] > end > end > > # app/views/planner/_mta_colors.rhtml: > <td> > <% > ... > dist = distribute(total_v_px, 4, 0, colors.collect{|color| color[1]}) > ... > %> > > So to test the distribute method in ApplicationHelper, I have to > extend my > spec models: > describe ApplicationHelper do > extend(ApplicationHelper) > it "doesn''t find what it''s looking for do > distribute(1,2,3,[4,5,6]).should eql([1,2,3]) > end > end > > This could use some documentation. > > > -- > View this message in context: http://www.nabble.com/ApplicationHelper-tp16149622p16149622.html > Sent from the rspec-users mailing list archive at Nabble.com. > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > http://www.coreyhaines.com > The Internet''s Premiere source of information about Corey Haines > _______________________________________________ > 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/20080320/df6316f9/attachment-0001.html