[rspec-users] autotest giving error when having shared example in specs

David Chelimsky dchelimsky at gmail.com
Fri Jan 21 08:35:36 EST 2011


On Jan 21, 2011, at 4:57 AM, Rob Westgeest wrote:

> On Nov 22 2010, 9:42 pm, LesFreeman <lesliefreem... at gmail.com> wrote:
>> On Sep 28, 10:42 pm, Amiruddin Nagri <amir.na... at gmail.com> wrote:
>> 
>>> I am having asharedexample'allow authorized actions' for my Rails 3 RSpec
>>> 2.beta.20 application. Thesharedexamplelooks like
>> 
>>> share_examples_for 'allow authorized actions' do
>>>   ...
>>> end
>> 
>>> Thissharedexampleis in file
>>> spec/controllers/support/authorization_shared_example.rb, which I am
>>> requiring in spec_helper.rb. I am also using autotest to give me quick
>>> feedback. Autotest is generating following command to run rspec
>> 
>>> <path to
>>> ruby>/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/bin/rspec <path
>>> to rails root>/spec/controllers/support/authorization_shared_example.rb
>>> <other spec files>
>> 
>>> Since autotest is also including support file when running rspec, I am
>>> getting following errors with autotest
>> 
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/shared_example_group.rb:43:in
>>> `ensure_shared_example_group_name_not_taken':Sharedexamplegroup'allow
>>> authorized actions'alreadyexists(ArgumentError)
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/shared_example_group.rb:6:in
>>> `share_examples_for'
>>>     from
>>> /Users/arusarh/work/ece/carbonomist/spec/controllers/support/authorization_ shared_example.rb:1:in
>>> `<top (required)>'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in
>>> `load'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in
>>> `block in load'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:227:in
>>> `load_dependency'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_ support/dependencies.rb:235:in
>>> `load'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in
>>> `block in load_spec_files'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in
>>> `map'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/configuration.rb:302:in
>>> `load_spec_files'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/command_line.rb:18:in
>>> `run'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:46:in
>>> `run_in_process'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:37:in
>>> `run'
>>>     from
>>> /Users/arusarh/.rvm/gems/ruby-1.9.2-p0/gems/rspec-core-2.0.0.beta.20/lib/rs pec/core/runner.rb:10:in
>>> `block in autorun'
>> 
>>> Any ideas how to not make autotest includesharedexamplefiles loaded
>>> through command line, but only include files with pattern "*_spec.rb", or
>>> have anyone else facing same situation.

>> I too am having this error

> I am having the same problem.
> 
> Autotest with rspec seem to differ from rspecs rake task in which
> files to automatically require.
> 
> The rake task requires spec/**/*.spec

Close, but not quite. The default pattern is spec/**/*_spec.rb.

> Autotest rspec2 requires spec/**/*

Again, this incorrect. Autotest fires off shell commands that include a list of files to load based on a set of mappings: if file x changes, run a command with file(s) y.

In RSpec, those mappings are defined in Autotest::Rspec2, and they are set to include files that end with _spec.rb, with some additional constraints based on file naming conventions: a change to lib/foo/bar.rb tells RSpec to include spec/foo/bar_spec.rb.

> As I am sharing example groups in their own files names
> (shared_*_examples.rb), and require them from *spec.rb files, rake
> works nicely and autotest fails because of its 'lets require
> everything' attitude.

I'm not sure where that's coming from, but it's not default settings of rspec or autotest. What versions of rspec and autotest are you using? Is this a rails app?

> 
> I presume that there is a way to configure autotests require set, but
> i haven't found it yet.

Autotest has a mapping mechanism that you can access in its initialize hook. See http://blog.davidchelimsky.net/2008/01/15/rspec-1-1-2-and-zentest-3-8-0/ for more on this.

Cheers,
David


More information about the rspec-users mailing list