On Wed, Jan 23, 2013 at 2:54 PM, Jim Coble <jim.co...@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 :: http://blog.thecodewhisperer.com Free Your Mind to Do Great Work :: http://www.freeyourmind-dogreatwork.com
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users