Can't put shared example group in its own file

Any ideas? All I’d like to do is have two specs in different files use
the same shared example group. I saw a similar thread about autotest,
but I am not using that. [Sorry for the double post on Google G.;
didn’t realize at the time it was a read-only group.]

$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
$ rails -v
Rails 3.0.5
$ rails new shared
$ cd shared/
$ echo “gem ‘rspec-rails’, ‘~> 2.5’” >> Gemfile
$ bundle --without production
$ rails generate rspec:install
$ rails generate scaffold foo
$ rake db:migrate
$ mkdir spec/support
$ nano spec/support/stuff_spec.rb

– spec/support/stuff_spec.rb
shared_examples_for “bar” do
end

$ rake spec
(in /tmp/shared)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S
bundle exec rspec ./spec/controllers/foos_controller_spec.rb
./spec/helpers/foos_helper_spec.rb ./spec/models/foo_spec.rb
./spec/requests/foos_spec.rb ./spec/routing/foos_routing_spec.rb
./spec/support/stuff_spec.rb ./spec/views/foos/edit.html.erb_spec.rb
./spec/views/foos/index.html.erb_spec.rb
./spec/views/foos/new.html.erb_spec.rb
./spec/views/foos/show.html.erb_spec.rb
/Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:45:in
ensure_shared_example_group_name_not_taken': Shared example group 'bar' already exists (ArgumentError) from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/shared_example_group.rb:6:inshared_examples_for’
from /private/tmp/shared/spec/support/stuff_spec.rb:1
from
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in
load' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:inload’
from
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:227:in
load_dependency' from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:inload’
from
/Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in
load_spec_files' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:inmap’
from
/Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in
load_spec_files' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:inrun’
from
/Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in
run_in_process' from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:inrun’
from
/Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in
`autorun’
from /Library/Ruby/Gems/1.8/bin/rspec:19
rake aborted!

On Mar 28, 2011, at 9:29 PM, Mike Tsao wrote:

$ cd shared/
$ echo “gem ‘rspec-rails’, ‘~> 2.5’” >> Gemfile
$ bundle --without production
$ rails generate rspec:install
$ rails generate scaffold foo
$ rake db:migrate
$ mkdir spec/support
$ nano spec/support/stuff_spec.rb

Don’t name this file ^^ ending with _spec.rb - that is the default
pattern that RSpec looks for specs in, so it’s getting loaded as a spec.
Name it something like shared_examples_for_stuff.rb.

HTH,
David

On 28 Mar 2011, at 04:04, Mike T wrote:

$ echo “gem ‘rspec-rails’, ‘~> 2.5’” >> Gemfile
$ bundle --without production
$ rails generate rspec:install
$ rails generate scaffold foo
$ rake db:migrate
$ mkdir spec/support
$ nano spec/support/stuff_spec.rb

– spec/support/stuff_spec.rb
shared_examples_for “bar” do
end

I’m sure David already replied about this - don’t name your shared
examples group *_spec.rb otherwise RSpec will load it and try to run it
as a spec file.

from
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:235:in
`load’
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

cheers,
Matt

[email protected]
07974 430184