[rspec-users] Shared Examples + “initialized constant” warnings

David Chelimsky dchelimsky at gmail.com
Fri Feb 8 11:43:06 EST 2008

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?


> Thanks,
> Gerrit
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list