[rspec-users] Specs for code stored in rails_app/lib/

Wincent Colaiuta win at wincent.com
Thu May 24 05:48:22 EDT 2007


El 24/5/2007, a las 10:35, David Chelimsky escribió:

> On 5/24/07, Wincent Colaiuta <win at wincent.com> wrote:
>> Where should the specs go for code in the "lib" directory of a Rails
>> app?
>>
>> I made a folder, "spec/lib/", for storing such specs, and RSpec
>> automatically picks them up when run using "rake spec".
>>
>> Before I go ahead and patch rspec_on_rails/lib/autotest/
>> rails_rspec.rb so that autotest can monitor these specs I'd like to
>> ask whether this is the "standard" location for such specs or not.
>
> Seems reasonable. Can you get me that patch this AM? I want to do a
> 1.0.3 release today to fix a couple of bugs.

Will paste one possible diff below; based on the convention that for  
file:

lib/my_module.rb

There will be a corresponding spec at:

spec/lib/my_module_spec.rb

This may be too simplistic given the possibility of nesting  
subfolders in lib, but as a first cut it might be ok.

> FYI - how did you even find that file? We released it, but autotest is
> not using it yet. It will be after the next ZenTest release, but not
> yet.

Just happened to notice it; after "script/plugin install" I did an  
"svn st" and "svn diff" to see what was new...

Cheers,
Wincent


Index: rails_rspec.rb
===================================================================
--- rails_rspec.rb      (revision 2014)
+++ rails_rspec.rb      (working copy)
@@ -33,7 +33,7 @@
        %r%^(test|spec)/fixtures/(.*).yml% => proc { |_, m|
          ["spec/models/#{m[2].singularize}_spec.rb"] + files_matching 
(%r%^spec\/views\/#{m[2]}/.*_spec\.rb$%)
        },
-      %r%^spec/(models|controllers|views|helpers)/.*rb$% => proc { | 
filename, _|
+      %r%^spec/(models|controllers|views|helpers|lib)/.*rb$% => proc  
{ |filename, _|
          filename
        },
        %r%^app/models/(.*)\.rb$% => proc { |_, m|
@@ -61,6 +61,9 @@
        %r%^app/controllers/(.*)\.rb$% => proc { |_, m|
          ["spec/controllers/#{m[1]}_spec.rb"]
        },
+      %r%^lib/(.*)\.rb$% => proc { |_, m|
+        ["spec/lib/#{m[1]}_spec.rb"]
+      },
        %r%^config/routes.rb$% => proc { # FIX:
          files_matching %r%^spec/(controllers|views|helpers)/.*_spec 
\.rb$%
        },
@@ -68,7 +71,7 @@
          files_matching %r%^spec/models/.*_spec\.rb$%
        },
        %r%^spec/spec_helper.rb|config/((boot|environment(s/ 
test)?).rb)% => proc {
-        files_matching %r%^spec/(models|controllers|views| 
helpers)/.*_spec\.rb$%
+        files_matching %r%^spec/(models|controllers|views|helpers| 
lib)/.*_spec\.rb$%
        },
      }
    end


More information about the rspec-users mailing list