[rspec-users] Recognising RSpec files in the Textmate bundle

Phillip Koebbe phillipkoebbe at gmail.com
Sun Aug 8 16:53:05 EDT 2010

  On 2010-08-08 6:11 AM, Ashley Moran wrote:
> On Aug 08, 2010, at 2:17 am, Phillip Koebbe wrote:
>> I have developed a system in which I require model_helper.rb in model specs, controller_helper.rb in controllers, and (you guessed it!) view_helper.rb in view specs. Each of those then require spec_helper.rb. I did this because I wanted fine-grained control over what gets loaded when, which started when I decided I wanted to use Remarkable for model specs only and didn't want it available during other specs. Plus, I keep customizations out of spec_helper.rb, which is a very good thing.
> I think the way I worded by question may have made it sound like I was expecting everyone using TextMate to use put "require 'spec_helper'" at the top of the file... I didn't mean that!  I was just suggesting that if a file starts with that require, then TextMate should see it as an RSpec file.  As you've pointed out, this won't get all files, like your custom helpers.  But I imagine it'd get a fairly high proportion.

Yes, I think I misunderstood what you were getting at. I would agree 
that the majority of RSpec users probably leave the "require 
'spec_helper'" line at the beginning of their specs and therefore the 
vast majority of cases would be covered. Sadly (I guess...), I am, once 
again, an outlier. I can't think of a single example file that requires 

>> This is probably like trying to swat a fly with Mack truck, but what if all files under spec/ were considered RSpec files? Or possibly some variation of that?
> I just double checked, and spec_helper.rb isn't considered an RSpec file - and actually, I don't think it should be.

I guess I also misunderstood what you meant by "RSpec file". I assumed 
it to mean any file belonging to RSpec, but I guess what it really means 
is a file with examples in it?

>    Also, I have a spec/support folder in most projects, with matchers etc.  They aren't RSpec files either.  So this route would probably give a lot of false positives.
> It might work better if this was the default folder structure:
>    spec/
>      examples/
>      spec_helper.rb
>      support/
> Then you could glob everything under "examples".  I actually do this with Cucumber, where my folder structure is:
>    features/
>      descriptions/
>      step_definitions/
>      support/
> But apparently I'm alone in the world not wanting to mix .feature files in with the support folder!

I don't think you are alone in your quest to achieve greater 
organization. I am guessing that in your suggested RSpec folder 
structure, the current folders of controllers|helpers|models|views would 
all live under examples? I might go for that. I think some (many?) might 
say that it's an unnecessary level, but I think I'd prefer that. I might 
even look into doing that anyway :) After all, my Cucumber folder 
structure is


And I use subfolders under features and steps just like I do in RSpec.

> Either way, I'm not convinced using the folder structure is the best solution.  It forces TextMate users to structure there project a certain way.  If you wanted a rails app like this:
>    acceptance/
>    app/
>    integration/
>    spec/
> (or whatever) then path matching wouldn't work.

Right. I wouldn't want a particular structure to be forced upon me, so 
I'd rather not see that happen to anyone.

> On Aug 07, 2010, at 11:44 pm, David Chelimsky wrote:
>> I think it's good to do things that help end users, but we'd need a more reliable convention to base this on. Anybody (including Ashley) got any other suggestions?
> Actually, I'm stuck :-/  I didn't think it'd be hard to identify RSpec example group files!  I'm not much of a TextMate developer though.  Anyone else got ideas?
> Cheers
> Ash

Here's another idea that's not so great, but maybe it will spur some 
thinking in someone else. What about a custom generator (or a flag on 
the official one) that added something like a shebang line at the 
beginning of example files. A short comment that identifies the file, 
like "# RSpec". Then a TM bundle could pick up on that and be happy. I 
don't know about vim or any other editor, though.


More information about the rspec-users mailing list