[rspec-users] Trying to spec all models

Phillip Koebbe phillipkoebbe at gmail.com
Thu Feb 11 06:15:34 EST 2010


David Chelimsky wrote:
> On Thu, Feb 11, 2010 at 12:13 AM, Mike Sassak<msassak at gmail.com>  wrote:
>    
>> On Wed, Feb 10, 2010 at 10:17 PM, Phillip Koebbe
>> <phillipkoebbe at gmail.com>  wrote:
>>      
>>> When I do
>>>
>>> script/spec -c -f n  spec/models/**/*_spec.rb
>>>
>>> I get
>>>
>>> /Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:283:in
>>> `files_to_load': File or directory not found: spec/models/**/*_spec.rb
>>> (RuntimeError)
>>>
>>> Yet, if I go into irb and do
>>>
>>> Dir.glob('spec/models/**/*_spec.rb')
>>>
>>> I get
>>>
>>> ["spec/models/county_spec.rb", "spec/models/county_user_spec.rb",
>>> "spec/models/message_county_spec.rb", "spec/models/message_spec.rb",
>>> "spec/models/message_user_spec.rb", "spec/models/postman_spec.rb",
>>> "spec/models/user_spec.rb"]
>>>
>>> Does spec not glob? I'm working on a wrapper script and I'd like to be able
>>> to run all specs of a given type (controller, model, view) by passing a
>>> single switch (-c, -m, -v). It works when I have subdirectories (as I do
>>> with controllers), but it isn't working when I don't (as with models). The
>>> fact that glob picks up the files properly got me wondering, so I thought
>>> I'd ask.
>>>
>>>        
>> When running script/spec from the CLI the globbing rules will depend
>> on the shell. Try searching Google for "bash globbing" (or whatever
>> shell you're using). But if all you need is to run all the model
>> specs, you could use "rake spec:models". That works well for me.
>>      
>
> Or just "script/spec spec/models"
>
>    

Thanks for the replies. It's not as simple as I just want to spec all 
models. As I mentioned, I'm writing a wrapper script to automate some 
things that I repeatedly find myself doing or wanting to do. I am trying 
to do a very simple **/* pattern when I don't pass a pattern as an 
argument. I don't really want to have a conditional that says

rake spec:models unless pattern

when the rest of my code actually calls script/spec. David's suggestion 
might work though. Right now, I do

file = ARGV.at(0) if ARGV.size > 0
file = '**/*' unless file
<some logic to determine what type of spec to run, which defines 
filename_partial>
spec_path = "#{spec_path}/#{file}#{filename_partial}.rb"

file can be "user", "admin/message", "admin/*", "*/message", or whatever 
I need it to be. That's why I'm looking for the easiest way to run all 
of a given type. Eventually I'm going to add support for ~, like with 
Cucumber tags, except for specs. I did this in a wrapper for Cucumber 
features and it is working out well for me.

I'll keep kicking it around. I'm confident a reasonable solution is not 
far off.

Peace,
Phillip


More information about the rspec-users mailing list