Patrick J. Collins
2011-Sep-22 02:35 UTC
[rspec-users] preferred place for methods used by both rspec and cucumber?
Hi, I have some helper methods such as: def mock_omniauth OmniAuth.config.test_mode = true OmniAuth.config.mock_auth[:facebook] = facebook_user end def facebook_user @facebook_user ||= HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/test/fixtures/fb_user.yml"))) end that I want to use in both cucumber step definitions and rspec. Is there a preferred place to store this code, or is it standard practice to just define them in a module in config/inititalizers and include that in both cucumber''s env.rb and rspec''s spec_helper.rb? Thanks. Patrick J. Collins http://collinatorstudios.com
David Chelimsky
2011-Sep-22 05:29 UTC
[rspec-users] preferred place for methods used by both rspec and cucumber?
On Sep 22, 2011, at 4:35 AM, Patrick J. Collins wrote:> Hi, > > I have some helper methods such as: > > def mock_omniauth > OmniAuth.config.test_mode = true > OmniAuth.config.mock_auth[:facebook] = facebook_user > end > > def facebook_user > @facebook_user ||= HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/test/fixtures/fb_user.yml"))) > end > > that I want to use in both cucumber step definitions and rspec. Is there a > preferred place to store this code,This doesn''t come up that often so there is no established convention. I''ve put such code in files in spec/support and included it from the features directory before. I''m sure the other way round would work just fine.> or is it standard practice to just define > them in a module in config/inititalizers and include that in both cucumber''s > env.rb and rspec''s spec_helper.rb?config/initializers is about application initialization IMO, so I wouldn''t put this material there. Anybody else? David
Phillip Koebbe
2011-Sep-22 13:30 UTC
[rspec-users] preferred place for methods used by both rspec and cucumber?
On 2011-09-21 9:35 PM, Patrick J. Collins wrote:> Hi, > > I have some helper methods such as: > > def mock_omniauth > OmniAuth.config.test_mode = true > OmniAuth.config.mock_auth[:facebook] = facebook_user > end > > def facebook_user > @facebook_user ||= HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/test/fixtures/fb_user.yml"))) > end > > that I want to use in both cucumber step definitions and rspec. Is there a > preferred place to store this code, or is it standard practice to just define > them in a module in config/inititalizers and include that in both cucumber''s > env.rb and rspec''s spec_helper.rb? > > Thanks. > > Patrick J. Collins > http://collinatorstudios.comI agree with David that config/initializers isn''t the right place as that would load test-related code into your application in production. I create a folder in Rails.root for shared code and then require it as necessary in RSpec and Cucumber. My current directory name is test_support, which I''m not terribly fond of, but doesn''t really matter so I haven''t wasted the brain energy to rename it. The benefit of keeping shared code in a folder external to both tools is I can totally remove one tool without the other breaking. If you keep the shared code inside one or the other, you have to be careful about changing whichever one hosts the shared code. Peace.
Pat Maddox
2011-Sep-23 16:42 UTC
[rspec-users] preferred place for methods used by both rspec and cucumber?
I use spec/support or Rails.root/bdd_support not a big deal really. just pick a place and require em On Sep 21, 2011, at 7:35 PM, Patrick J. Collins wrote:> Hi, > > I have some helper methods such as: > > def mock_omniauth > OmniAuth.config.test_mode = true > OmniAuth.config.mock_auth[:facebook] = facebook_user > end > > def facebook_user > @facebook_user ||= HashWithIndifferentAccess.new(YAML.load(File.read("#{Rails.root}/test/fixtures/fb_user.yml"))) > end > > that I want to use in both cucumber step definitions and rspec. Is there a > preferred place to store this code, or is it standard practice to just define > them in a module in config/inititalizers and include that in both cucumber''s > env.rb and rspec''s spec_helper.rb? > > Thanks. > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users