If a helper method can be used for multiple model specs, obviously it should not be placed within a specific model''s spec helper file. Is there a recommended file in which to put such a method? Maybe spec/ helpers/application_helper_spec.rb ? -Nick
On Wed, Aug 27, 2008 at 2:38 PM, Nick Hoffman <nick at deadorange.com> wrote:> If a helper method can be used for multiple model specs, obviously it should > not be placed within a specific model''s spec helper file. Is there a > recommended file in which to put such a method? Maybe > spec/helpers/application_helper_spec.rb ?This is a very confusing question. Model''s don''t typically get individual spec helper files, so I''m not sure what you''re getting at. Can you give an example?
On 2008-08-28, at 08:02, David Chelimsky wrote:> On Wed, Aug 27, 2008 at 2:38 PM, Nick Hoffman <nick at deadorange.com> > wrote: >> If a helper method can be used for multiple model specs, obviously >> it should >> not be placed within a specific model''s spec helper file. Is there a >> recommended file in which to put such a method? Maybe >> spec/helpers/application_helper_spec.rb ? > > This is a very confusing question. Model''s don''t typically get > individual spec helper files, so I''m not sure what you''re getting at. > Can you give an example?I asked because I had begun to abstract my #describe_properties method away from the Property model so that it can be used with any model. Now that the method''s been converted from this: http://pastie.org/261175 to this: http://pastie.org/261829 I''d like to use it with multiple models. Cheers, Nick
You can put it in a module and include it for model specs in spec_helper.rb Spec::Runner.configure do |config| # ... config.include DescribeModelAttributeSpecHelper, :type => :model end Zach On Thu, Aug 28, 2008 at 12:41 PM, Nick Hoffman <nick at deadorange.com> wrote:> On 2008-08-28, at 08:02, David Chelimsky wrote: >> >> On Wed, Aug 27, 2008 at 2:38 PM, Nick Hoffman <nick at deadorange.com> wrote: >>> >>> If a helper method can be used for multiple model specs, obviously it >>> should >>> not be placed within a specific model''s spec helper file. Is there a >>> recommended file in which to put such a method? Maybe >>> spec/helpers/application_helper_spec.rb ? >> >> This is a very confusing question. Model''s don''t typically get >> individual spec helper files, so I''m not sure what you''re getting at. >> Can you give an example? > > I asked because I had begun to abstract my #describe_properties method away > from the Property model so that it can be used with any model. Now that the > method''s been converted from this: > http://pastie.org/261175 > to this: > http://pastie.org/261829 > I''d like to use it with multiple models. > > Cheers, > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
On Thu, Aug 28, 2008 at 12:27 PM, Zach Dennis <zach.dennis at gmail.com> wrote:> You can put it in a module and include it for model specs in spec_helper.rb > > Spec::Runner.configure do |config| > # ... > config.include DescribeModelAttributeSpecHelper, :type => :model > endWhat he said.> > Zach > > On Thu, Aug 28, 2008 at 12:41 PM, Nick Hoffman <nick at deadorange.com> wrote: >> On 2008-08-28, at 08:02, David Chelimsky wrote: >>> >>> On Wed, Aug 27, 2008 at 2:38 PM, Nick Hoffman <nick at deadorange.com> wrote: >>>> >>>> If a helper method can be used for multiple model specs, obviously it >>>> should >>>> not be placed within a specific model''s spec helper file. Is there a >>>> recommended file in which to put such a method? Maybe >>>> spec/helpers/application_helper_spec.rb ? >>> >>> This is a very confusing question. Model''s don''t typically get >>> individual spec helper files, so I''m not sure what you''re getting at. >>> Can you give an example? >> >> I asked because I had begun to abstract my #describe_properties method away >> from the Property model so that it can be used with any model. Now that the >> method''s been converted from this: >> http://pastie.org/261175 >> to this: >> http://pastie.org/261829 >> I''d like to use it with multiple models. >> >> Cheers, >> Nick >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 2008-08-28, at 13:57, David Chelimsky wrote:> On Thu, Aug 28, 2008 at 12:27 PM, Zach Dennis > <zach.dennis at gmail.com> wrote: >> You can put it in a module and include it for model specs in >> spec_helper.rb >> >> Spec::Runner.configure do |config| >> # ... >> config.include DescribeModelAttributeSpecHelper, :type => :model >> end > > What he said.Thanks guys!
On 2008-08-28, at 13:27, Zach Dennis wrote:> You can put it in a module and include it for model specs in > spec_helper.rb > > Spec::Runner.configure do |config| > # ... > config.include DescribeModelAttributeSpecHelper, :type => :model > end > > ZachHi Zach. I put the methods into the module "ModelSpeccer" in lib/ ModelSpeccer.rb and then added this to spec_helper.rb : config.include ModelSpeccer, :type => :model Unfortunately though, when I run my specs, Ruby isn''t finding the module: $ script/spec spec/models/property_spec.rb /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/ active_support/dependencies.rb:278:in `load_missing_constant'': uninitialized constant ModelSpeccer (NameError) Any suggestions for how to correct this? Thanks! Nick
On Aug 29, 2008, at 10:40 PM, Nick Hoffman wrote:> On 2008-08-28, at 13:27, Zach Dennis wrote: >> You can put it in a module and include it for model specs in >> spec_helper.rb >> >> Spec::Runner.configure do |config| >> # ... >> config.include DescribeModelAttributeSpecHelper, :type => :model >> end >> >> Zach > > Hi Zach. I put the methods into the module "ModelSpeccer" in lib/ > ModelSpeccer.rb and then added this to spec_helper.rb : > config.include ModelSpeccer, :type => :model > > Unfortunately though, when I run my specs, Ruby isn''t finding the > module:This isn''t ruby - if you want ruby to include it, you''ll need a require statement (or a load, or autoload). If you want rails const_missing stuff to load it automatically, I''m guessing you''ll need to name the file lib/model_speccer.rb, and the module to be named ModelSpeccer Scott
On Fri, Aug 29, 2008 at 11:05 PM, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> > On Aug 29, 2008, at 10:40 PM, Nick Hoffman wrote: > >> On 2008-08-28, at 13:27, Zach Dennis wrote: >>> >>> You can put it in a module and include it for model specs in >>> spec_helper.rb >>> >>> Spec::Runner.configure do |config| >>> # ... >>> config.include DescribeModelAttributeSpecHelper, :type => :model >>> end >>> >>> Zach >> >> Hi Zach. I put the methods into the module "ModelSpeccer" in >> lib/ModelSpeccer.rb and then added this to spec_helper.rb : >> config.include ModelSpeccer, :type => :model >> >> Unfortunately though, when I run my specs, Ruby isn''t finding the module: > > This isn''t ruby - if you want ruby to include it, you''ll need a require > statement (or a load, or autoload).I think Scott means to say "this isn''t rspec, you need to tell ruby to load the file using require". I would keep your spec helpers separate from application code (like app/ or lib/ directories). I typically put these files in spec/spec_helpers/ and then in your spec_helper.rb I require all ruby files like so: Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].each do |f| require f end Just a thought, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
On Sat, Aug 30, 2008 at 8:33 AM, Zach Dennis <zach.dennis at gmail.com> wrote:> On Fri, Aug 29, 2008 at 11:05 PM, Scott Taylor > > This isn''t ruby - if you want ruby to include it, you''ll need a require > > statement (or a load, or autoload). > > I think Scott means to say "this isn''t rspec, you need to tell ruby to > load the file using require". >I think Zach means to say "this isn''t Rails." :) ///ark -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080830/3618c48a/attachment.html>
On 2008-08-30, at 12:35, Mark Wilden wrote:> On Sat, Aug 30, 2008 at 8:33 AM, Zach Dennis <zach.dennis at gmail.com> > wrote: > On Fri, Aug 29, 2008 at 11:05 PM, Scott Taylor > > This isn''t ruby - if you want ruby to include it, you''ll need a > require > > statement (or a load, or autoload). > > I think Scott means to say "this isn''t rspec, you need to tell ruby to > load the file using require". > > I think Zach means to say "this isn''t Rails." :) > > ///arkThanks guys. My bad for not realising that this had to do with Rails rather than RSpec! -Nick