Recently I got some wonderful help from the list to create my
NamedAddress
module/macro which tests NamedAddresses for a number of different
resources.
The question I have is where should I put this module? At the moment
I’ve
got it in spec_helper, but this feels a bit messy
Many thanks
Andrew
On Mon, Jun 22, 2009 at 11:28 AM, Andrew P.[email protected]
wrote:
Recently I got some wonderful help from the list to create my NamedAddress
module/macro which tests NamedAddresses for a number of different resources.
The question I have is where should I put this module? At the moment I’ve
got it in spec_helper, but this feels a bit messy
Many thanks
Andrew
The convention that I see emerging is to keep macros, helpers, and any
other spec supporting material in spec/support/macros,
spec/support/matchers, etc. Then you do this in spec/spec_helper.rb:
Dir[File.dirname(FILE) + “/support/**/*.rb”].each {|f| require f}
What would folks think if that was included in the generated
spec_helper in spec-rails?
Cheers,
David
On Jun 22, 2009, at 10:28 AM, Andrew P. wrote:
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users
Hey Andrew,
I don’t think there is a known convention for this. If I only use the
macro for a single set of examples then I leave the macro code inline
with the actual examples. Once I need it in multiple files then I
will move it to my root spec dir. I suppose you could create a spec/
macros dir if you want (this would make it easier to require all of
the ones you have). I generally don’t have a whole lot so I just put
my macros and matchers under spec/ and let spec_helper require them.
Then in your spec helper if you want all of your examples to have
access to these macros you can say:
Spec::Runner.configure do |config|
config.extend(MyMacro, MyOtherMacro)
end
HTH,
Ben
On Jun 22, 2009, at 10:37 AM, David C. wrote:
Andrew
The convention that I see emerging is to keep macros, helpers, and any
other spec supporting material in spec/support/macros,
spec/support/matchers, etc. Then you do this in spec/spec_helper.rb:
Dir[File.dirname(FILE) + “/support/**/*.rb”].each {|f| require f}
What would folks think if that was included in the generated
spec_helper in spec-rails?
Just as I said there was no written convention…
I like it. +1
-Ben
On Mon, Jun 22, 2009 at 7:37 PM, David C.
[email protected]wrote:
On Mon, Jun 22, 2009 at 11:28 AM, Andrew P.[email protected]
wrote:What would folks think if that was included in the generated
spec_helper in spec-rails?
I, while not a regular patron in this mailing list, +1 this too.
It would be very nice if the autogenerated Rails files specify a
conventional place to put macros/matchers. I would have a lot lower
psychological barrier to adding few of those in my Rails applications.
On Mon, Jun 22, 2009 at 12:37 PM, David C.[email protected]
wrote:
The convention that I see emerging is to keep macros, helpers, and any
other spec supporting material in spec/support/macros,
spec/support/matchers, etc.
+1 from me too. I’ve been calling my directory spec/helpers, but I’ve
been working on non-Rails projects lately and it only just now
occurred to me that it would cause a name collision. >8->
Dir[File.dirname(FILE) + “/support/**/*.rb”].each {|f| require f}
On a total non sequitur: has anyone ever come up with a clean, general
syntactic sugar for cleaning up all of these ubiquitous File/Dir class
methods and FILE constants and other ugly filesystem machinery on
requires?
If no one knows of such a convenience, I might have to take a day or
so and write something. Most of the rest of Ruby is so elegant and
pretty that seeing this stuff at the top of every file hurts my eyes a
bit. It’s like getting a small static shock each time you settle into
your comfortable luxury car.
–
Have Fun,
Steve E. ([email protected])
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org