Application-wide spec_helper method

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 H. [email protected]
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 C. wrote:

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

On Thu, Aug 28, 2008 at 12:27 PM, Zach D. [email protected]
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.

On 2008-08-28, at 13:57, David C. wrote:

What he said.
Thanks guys!

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 H. [email protected]
wrote:

This is a very confusing question. Model’s don’t typically get

Cheers,
Nick


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users


Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com

On 2008-08-28, at 13:27, Zach D. 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:

$ 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 H. wrote:

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 T.
[email protected] wrote:

config.include DescribeModelAttributeSpecHelper, :type => :model
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 D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com

On Sat, Aug 30, 2008 at 8:33 AM, Zach D. [email protected]
wrote:

On Fri, Aug 29, 2008 at 11:05 PM, Scott T.

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.” :slight_smile:

///ark

On 2008-08-30, at 12:35, Mark W. wrote:

I think Zach means to say “this isn’t Rails.” :slight_smile:

///ark

Thanks guys. My bad for not realising that this had to do with Rails
rather than RSpec!
-Nick

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs