[rspec-users] Test configuration information

Jim Coble jim.coble at duke.edu
Thu Jan 24 15:04:23 UTC 2013

J.B. (and Perry)-
Thanks for your responses.  They are very helpful.

Jim Coble
Information Technology Services
Perkins Library, Duke University
Box 90196, Durham, NC 27708
919-660-5974 (voice); 919-668-2578 (fax)
Jim.coble at duke.edu<mailto:Jim.coble at duke.edu>

From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of J. B. Rainsberger
Sent: Wednesday, January 23, 2013 5:27 PM
To: rspec-users
Subject: Re: [rspec-users] Test configuration information

On Wed, Jan 23, 2013 at 2:54 PM, Jim Coble <jim.coble at duke.edu<mailto:jim.coble at duke.edu>> wrote:
One of my tests needs to be provided with a particular directory path.  While I can code this path as a literal directly in the test spec, it seems to me it might be better to have it in a configuration file somewhere so that I have one place to maintain it and look for it.  Would spec_helper.rb be a reasonable place to define it?  Is there a more customary place?  Note that I am not trying to configure RSpec per se or even how RSpec runs the test.  Rather, I'm trying to provide some information (a character string) that the test needs in order to run.

Step 1: hardcode the path directly into your spec
Step 2: extract the path so that it's a (local) parameter to your spec
Step 3: when you want to use it in multiple specs, move it to a `let` statement within the context that the specs have in common
Step 4: when you want to use it in multiple unrelated specs, well, is that a coincidence? Maybe you don't need to use the same *value* in both places
Step 5: when you're sure that you want to use the same value in multiple unrelated specs, move it into a class defined in a spec_helper-ish thing

Underlying principles:

* Don't duplicate the hardcoded path, but
* Keep the scope of the path as narrow as possible at all times
J. B. (Joe) Rainsberger :: http://www.myagiletutor.com :: http://www.jbrains.ca ::
Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130124/3cae1da8/attachment.html>

More information about the rspec-users mailing list