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. Thanks. --Jim 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> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130123/f51abf15/attachment.html>
I think I would put it with the test. My logic is, if it breaks (needs to change), the test will break. You will look there first to see what happened. On Jan 23, 2013, at 12:54 PM, Jim Coble 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. > Thanks. > --Jim > > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130123/66b2245a/attachment.html>
On Wed, Jan 23, 2013 at 2:54 PM, Jim Coble <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 :: http://blog.thecodewhisperer.com 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/20130123/9e3cc705/attachment-0001.html>
J.B. (and Perry)- Thanks for your responses. They are very helpful. --Jim 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 :: http://blog.thecodewhisperer.com 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>