Balint Erdi
2009-Jul-31 08:57 UTC
[rspec-users] [rspec-rails] rspec-rails forcing test environment?
Hi, I realized that requiring rspec-rails somehow sets RAILS_ENV to ''test''. My experimental environment.rb file is the following: puts "XXX RAILS_ENV: #{RAILS_ENV}" Rails::Initializer.run do |config| (...) config.gem "rspec", :version => ">= 1.2.8", :lib => ''spec'' config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => ''spec/ rails'' # (1) (...) end puts "XXX RAILS_ENV: #{RAILS_ENV}" When I run the server (./script/server), I see: XXX RAILS_ENV: development XXX RAILS_ENV: test If I comment out the rspec-rails inclusion line (1), then the RAILS_ENV remains ''development'' after the config block. That''s causing me a problem because "in the real app" I set up a CouchDB database depending on RAILS_ENV after the block. One possible workaround is to put the rspec and rspec-rails lines into the environment file for the test env. (test.rb), but that seems to defeat the goal of having all dependencies in one place so that it is clear and gem-related rake tasks can be conveniently run. (I am using rails 2.3.2, rspec 1.2.8, rspec-rails 1.2.7.1) Do you know of a better workaround or a real solution for the problem? Thank you, Balint
David Chelimsky
2009-Jul-31 12:36 UTC
[rspec-users] [rspec-rails] rspec-rails forcing test environment?
On Fri, Jul 31, 2009 at 3:57 AM, Balint Erdi<balint.erdi at gmail.com> wrote:> Hi, > > I realized that requiring rspec-rails somehow sets RAILS_ENV to > ''test''. My experimental environment.rb file is the following: > > puts "XXX RAILS_ENV: #{RAILS_ENV}" > > Rails::Initializer.run do |config| > ?(...) > ?config.gem "rspec", :version => ">= 1.2.8", :lib => ''spec'' > ?config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => ''spec/Use lib => false to keep rails from automatically loading rspec and/or rspec-rails This should also be in config/environments/test.rb HTH, David> rails'' # (1) > ?(...) > end > > puts "XXX RAILS_ENV: #{RAILS_ENV}" > > When I run the server (./script/server), I see: > > XXX RAILS_ENV: development > XXX RAILS_ENV: test > > If I comment out the rspec-rails inclusion line (1), then the > RAILS_ENV remains ''development'' after the config block. That''s causing > me a problem because "in the real app" I set up a CouchDB database > depending on RAILS_ENV after the block. > > One possible workaround is to put the rspec and rspec-rails lines into > the environment file for the test env. (test.rb), but that seems to > defeat the goal of having all dependencies in one place so that it is > clear and gem-related rake tasks can be conveniently run. (I am using > rails 2.3.2, rspec 1.2.8, rspec-rails 1.2.7.1) > > Do you know of a better workaround or a real solution for the problem? > > Thank you, > Balint > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Balint Erdi
2009-Aug-10 08:39 UTC
[rspec-users] [rspec-rails] rspec-rails forcing test environment?
> > > Rails::Initializer.run do |config| > > ?(...) > > ?config.gem "rspec", :version => ">= 1.2.8", :lib => ''spec'' > > ?config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => ''spec/ > > Use lib => false to keep rails from automatically loading rspec and/or > rspec-rails > > This should also be in config/environments/test.rb > > HTH, > David >Ok, I now have the following lines in my environment.rb: config.gem "rspec", :version => ">= 1.2.6", :lib => false config.gem "rspec-rails", :version => ">= 1.2.6", :lib => false And these in my environments/test.rb: config.gem "rspec", :lib => ''spec'' config.gem "rspec-rails", :lib => ''spec/rails'' Indeed, that solves the original problem of forcing the test environment when running the server. I refrained from specifying the version in the test.rb file since that would be a violation of DRY. I am not 100% satisfied since I still have to define the gems in two places, but this is now a minor issue and I don''t see an easy way to fix it. Thank you for your help, David. B?lint
David Chelimsky
2009-Aug-10 12:16 UTC
[rspec-users] [rspec-rails] rspec-rails forcing test environment?
On Mon, Aug 10, 2009 at 4:39 AM, Balint Erdi<balint.erdi at gmail.com> wrote:> > > >> >> > Rails::Initializer.run do |config| >> > ?(...) >> > ?config.gem "rspec", :version => ">= 1.2.8", :lib => ''spec'' >> > ?config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => ''spec/ >> >> Use lib => false to keep rails from automatically loading rspec and/or >> rspec-rails >> >> This should also be in config/environments/test.rb >> >> HTH, >> David >> > > Ok, I now have the following lines in my environment.rb: > > ?config.gem "rspec", :version => ">= 1.2.6", :lib => false > ?config.gem "rspec-rails", :version => ">= 1.2.6", :lib => false > > And these in my environments/test.rb: > > ?config.gem "rspec", :lib => ''spec'' > ?config.gem "rspec-rails", :lib => ''spec/rails'' > > Indeed, that solves the original problem of forcing the test > environment when running the server. I refrained from specifying the > version in the test.rb file since that would be a violation of DRY. I > am not 100% satisfied since I still have to define the gems in two > places, but this is now a minor issue and I don''t see an easy way to > fix it.Why are you duplicating it in environment.rb? You shouldn''t have to have it in both places. In all of my rails apps I _only_ have it in environments/test.rb: config.gem "rspec", :version => ">= 1.2.8", :lib => false config.gem "rspec-rails", :version => ">= 1.2.7.1", :lib => false> > Thank you for your help, David. > B?lint
Stephen Eley
2009-Aug-10 14:11 UTC
[rspec-users] [rspec-rails] rspec-rails forcing test environment?
On Fri, Jul 31, 2009 at 4:57 AM, Balint Erdi<balint.erdi at gmail.com> wrote:> > One possible workaround is to put the rspec and rspec-rails lines into > the environment file for the test env. (test.rb), but that seems to > defeat the goal of having all dependencies in one place so that it is > clear and gem-related rake tasks can be conveniently run. (I am using > rails 2.3.2, rspec 1.2.8, rspec-rails 1.2.7.1)Actually, I think it''s pretty sensible. That''s where I have mine. This is an environment-specific dependency. If you''re never going to run in a test environment on a particular server, you don''t need RSpec and there''s no reason for the gem tasks to install it. (If you will, then the deployment is just a matter of setting the environment variable first: "RAILS_ENV=test rake gems:install") -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org