Hi guys. I''m writing a plugin for use in the test environment. However, when I run ``rake test'''' or ``rake spec'''', RAILS_ENV is set to "development" when my plugin''s init.rb is run. How do you configure a plugin to load require a file in the test environment? Thanks, Nick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Oct 2008, at 23:17, Nick wrote:> > Hi guys. I''m writing a plugin for use in the test environment. > However, when I run ``rake test'''' or ``rake spec'''', RAILS_ENV is set > to "development" when my plugin''s init.rb is run. > > How do you configure a plugin to load require a file in the test > environment?Are you getting hoodwinked by the fact that the development environment is loaded once in order to dump its database (and then the test environment loads) ? Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 9, 4:10 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Are you getting hoodwinked by the fact that the development environmentis loaded once in order to dump its database (and then the testenvironmentloads) ? > > FredI think something strange was going on, as the test environment wasn''t running at all. I''ve sorted it out now though. Thanks, mate! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 9, 4:10 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Are you getting hoodwinked by the fact that the development environmentis loaded once in order to dump its database (and then the testenvironmentloads) ? > > FredHi Fred. I seem to have run into this problem again. I''ll outline my exact steps for you: 1) Create a new Rails app. $ rails test_plugin_env $ cd test_plugin_env 2) Create a new plugin. $ script/generate plugin Foobar 3) Add the following to vendor/plugins/foobar/init.rb if defined? RAILS_ENV puts "foobar > init.rb > RAILS_ENV = [#{RAILS_ENV}]" puts "foobar > init.rb > test environment!" if RAILS_ENV == ''test'' end If you then run whatever tests exists in an empty Rails app, you''ll see that RAILS_ENV is never set to "test". For example: $ rake test (in /Users/nick/src/test_plugin_env) foobar > init.rb > RAILS_ENV = [development] /opt/local/bin/ruby -Ilib:test "/opt/local/lib/ruby/gems/1.8/gems/ rake-0.8.1/lib/rake/rake_test_loader.rb" /opt/local/bin/ruby -Ilib:test "/opt/local/lib/ruby/gems/1.8/gems/ rake-0.8.1/lib/rake/rake_test_loader.rb" /opt/local/bin/ruby -Ilib:test "/opt/local/lib/ruby/gems/1.8/gems/ rake-0.8.1/lib/rake/rake_test_loader.rb" $ Why is RAILS_ENV never set to "test"? Thanks again, Fred! -Nick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 14 Oct 2008, at 19:03, Nick wrote:> > On Oct 9, 4:10 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> Are you getting hoodwinked by the fact that the development >> environmentis loaded once in order to dump its database (and then >> the testenvironmentloads) ? >> >> Fred > > Hi Fred. I seem to have run into this problem again. I''ll outline my > exact steps for you:Create at least one test in that app and it should be fine. Fred> > > 1) Create a new Rails app. > $ rails test_plugin_env > $ cd test_plugin_env > > 2) Create a new plugin. > $ script/generate plugin Foobar > > 3) Add the following to vendor/plugins/foobar/init.rb > if defined? RAILS_ENV > puts "foobar > init.rb > RAILS_ENV = [#{RAILS_ENV}]" > puts "foobar > init.rb > test environment!" if RAILS_ENV == ''test'' > end > > If you then run whatever tests exists in an empty Rails app, you''ll > see that RAILS_ENV is never set to "test". For example: > > $ rake test > (in /Users/nick/src/test_plugin_env) > foobar > init.rb > RAILS_ENV = [development] > /opt/local/bin/ruby -Ilib:test "/opt/local/lib/ruby/gems/1.8/gems/ > rake-0.8.1/lib/rake/rake_test_loader.rb" > /opt/local/bin/ruby -Ilib:test "/opt/local/lib/ruby/gems/1.8/gems/ > rake-0.8.1/lib/rake/rake_test_loader.rb" > /opt/local/bin/ruby -Ilib:test "/opt/local/lib/ruby/gems/1.8/gems/ > rake-0.8.1/lib/rake/rake_test_loader.rb" > $ > > Why is RAILS_ENV never set to "test"? > > Thanks again, Fred! > -Nick > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 14, 2:14 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Create at least one test in that app and it should be fine. > > FredI created a basic unit test: $ cat test/unit/foobar_test.rb require File.dirname(__FILE__) + ''/../test_helper'' class FoobarTest < Test::Unit::TestCase def test_true assert true, true end end But when I ran the test, the development environment was loaded before the test environment: ---START OUTPUT--- $ rake test:units (in /Users/nick/src/test_plugin_env) foobar > init.rb > RAILS_ENV = [development] /opt/local/bin/ruby -Ilib:test "/opt/local/lib/ruby/gems/1.8/gems/ rake-0.8.1/lib/rake/rake_test_loader.rb" "test/unit/foobar_test.rb" foobar > init.rb > RAILS_ENV = [test] foobar > init.rb > test environment! Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/ rake_test_loader Started . Finished in 0.216451 seconds. 1 tests, 1 assertions, 0 failures, 0 errors ---END OUTPUT--- Why is the development environment loaded before the test environment? Thanks, Nick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 14, 7:22 pm, Nick <n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org> wrote:> On Oct 14, 2:14 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Why is the development environment loaded before the test environment? >Because the first thing that rake test does is clone the development database. Were you to run just one test (ie ruby test/unit/ foo_test.rb) you wouldn''t see the dev environment loaded. Fred> Thanks, > Nick--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 14, 2:34 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Oct 14, 7:22 pm, Nick <n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org> wrote:> On Oct 14, 2:14 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > Why is the development environment loaded before the test environment? > > Because the first thing that rake test does is clone the development > database. Were you to run just one test (ie ruby test/unit/ > foo_test.rb) you wouldn''t see the dev environment loaded. > > FredI see. That explains things a bit now. With that in mind, how would you configure a plugin to be loaded only in the development environment, and not in the test environment? Since running a suite of tests first jumps into the development environment, I''m not sure how to go about this. Cheers, Nick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 14, 7:49 pm, Nick <n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org> wrote:> On Oct 14, 2:34 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Oct 14, 7:22 pm, Nick <n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org> wrote:> On Oct 14, 2:14 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > Why is the development environment loaded before the test environment? > > > Because the first thing that rake test does is clone the development > > database. Were you to run just one test (ie ruby test/unit/ > > foo_test.rb) you wouldn''t see the dev environment loaded. > > > Fred > > I see. That explains things a bit now. > > With that in mind, how would you configure a plugin to be loaded only > in the development environment, and not in the test environment? Since > running a suite of tests first jumps into the development environment, > I''m not sure how to go about this. >you could certainly bracket the body of your init.rb with "if RAILS_ENV ==" and do nothing if not (except perhaps remove your plugin''s lib directory from the load path) Fred> Cheers, > Nick--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> On Oct 14, 7:49 pm, Nick <n...-qGbiljoI0DQkmLvzuZlaBw@public.gmane.org> wrote: > > With that in mind, how would you configure a plugin to be loaded only > > in the development environment, and not in the test environment? Since > > running a suite of tests first jumps into the development environment, > > I''m not sure how to go about this.On Oct 14, 3:32 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> you could certainly bracket the body of your init.rb with "if > RAILS_ENV ==" and do nothing if not (except perhaps remove your > plugin''s lib directory from the load path) > > FredHi Fred. I''m afraid I don''t follow. If I put this in a plugin''s init.rb : require ''foobar'' if RAILS_ENV == ''development'' Then ''foobar'' will be loaded whenever any test suite, such as ``rake test'''' or ``rake spec'''', is run, because rake initially loads the development environment. -Nick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---