Gerrit Kaiser
2008-Feb-08 05:41 UTC
[rspec-users] Shared Examples + “initialized constant” warnings
Hi List, I''m using rspec''s shared example groups in a rails project (rails 2.02, rspec(on_rails) 1.1.3) and I''m getting lots of errors of the following kind when(before) running the specs: (RAILS_ROOT)/vendor/plugins/rspec/lib/spec/extensions/main.rb:78: warning: already initialized constant ContentExamples (RAILS_ROOT)/vendor/plugins/rspec/lib/spec/extensions/main.rb:78: warning: already initialized constant EditViewExamples The shared example groups are defined in files like spec/shared/ foo_examples.rb and declared as share_as :FooExamples do?end (and then included in other example groups with "include FooExamples") They''re loaded in spec_helper.rb with the following: Dir.glob(File.join(File.dirname(__FILE__), ''shared'', ''*.rb'')).each do | shared_example| require shared_example end I''m guessing that''s what needs to change. Has anyone else seen these warnings? I find them quite annoying and would like to get rid of them. Any pointers would be much appreciated. Thanks, Gerrit
David Chelimsky
2008-Feb-08 16:43 UTC
[rspec-users] Shared Examples + “initialized constant” warnings
On Feb 7, 2008 11:41 PM, Gerrit Kaiser <gerrit+rspec-devel at gerritkaiser.de> wrote:> Hi List, > I''m using rspec''s shared example groups in a rails project (rails > 2.02, rspec(on_rails) 1.1.3) and I''m getting lots of errors of the > following kind when(before) running the specs: > > (RAILS_ROOT)/vendor/plugins/rspec/lib/spec/extensions/main.rb:78: > warning: already initialized constant ContentExamples > (RAILS_ROOT)/vendor/plugins/rspec/lib/spec/extensions/main.rb:78: > warning: already initialized constant EditViewExamples > > The shared example groups are defined in files like spec/shared/ > foo_examples.rb > and declared as > share_as :FooExamples do?end > (and then included in other example groups with "include FooExamples") > They''re loaded in spec_helper.rb with the following: > Dir.glob(File.join(File.dirname(__FILE__), ''shared'', ''*.rb'')).each do | > shared_example| > require shared_example > end > > > I''m guessing that''s what needs to change. Has anyone else seen these > warnings? I find them quite annoying and would like to get rid of > them. Any pointers would be much appreciated.Hey Gerritt. The likely culprit is in ExampleGroupRunner, which uses the load command (not require) and therefore reloads anything that might be in the spec path. That is necessary to support drb, and unlikely to change, so it is up to you to ensure that shared example groups don''t get reloaded. How you do that depends on how you are running your specs and what other config changes you''ve made. So ... how are you running your specs? Have you made any additional config changes in terms of what files get loaded? David> Thanks, > Gerrit > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Gerrit Kaiser
2008-Feb-09 03:14 UTC
[rspec-users] Shared Examples + “initialized constant” warnings
David, thanks for your prompt reply. On 09/02/2008, at 3:43 AM, David Chelimsky wrote:> so it is up to you to ensure that shared example groups don''t > get reloaded. How you do that depends on how you are running your > specs and what other config changes you''ve made. > > So ... how are you running your specs? Have you made any additional > config changes in terms of what files get loaded?No changes in terms of loaded files. I''m normally running them via autotest, but invoking "script/spec spec/**/*_spec.rb" directly gives the same warnings (which is what I find weird, considering the shared example groups don''t live in *_spec.rb files. Here''s my spec.opts: --colour --format progress --format profile:doc/spec/slowest_examples --format html:doc/spec/report.html --loadby mtime --reverse Thanks for you help, Gerrit