[rspec-users] Separating black sheep examples from the rest

Scott Taylor mailing_lists at railsnewbie.com
Tue Sep 23 22:01:46 EDT 2008

On Sep 23, 2008, at 11:49 AM, Pat Maddox wrote:

> Matt Wynne <matt at mattwynne.net> writes:
>> So we've got a pretty decent number of specs now, and despite my  
>> best efforts,
>> AR is just forcing us down the path of having to use database  
>> interaction for
>> some of the model specs.
>> It's starting to get tiring to run all the specs now, which is  
>> making me sad,
>> and making me worry about how things are going to be in a few  
>> months from now.
>> I'd like to somehow be able to systematically mark the slow example  
>> groups as
>> being 'impure' and thus be able to choose to mostly ignore them  
>> during my
>> regular TDD cycle, just running them every so often as a regression.
>> I'm thinking something like this:
>> describe "when there are ten users in the database", :slow => true do
>> What do you think? How are other people solving this problem? Any  
>> tips /
>> thoughts on how I could implement this?
> Why don't you put the specs in a different directory?  One layout that
> I've seen used (I think by the WePlay guys) is:
> spec/
>  integration/
>    controllers/
>    models/
>  unit/
>    controllers/
>    models/

Yeah - Bryan and I paired @ Eastmedia before he left for WePlay to  
develop the following monkey patch to support that:

module Spec
   module Example
     class ExampleGroupFactory
       # Used to support spec/unit and spec/integration
       def self.determine_superclass(opts)
         spec_path = opts[:spec_path].to_s.gsub("/spec/unit", "/spec")

         id = if opts[:type]
         elsif spec_path =~ /spec\/integration\/routing_spec/
         elsif spec_path =~ /spec\/integration/
         elsif spec_path =~ /spec(\\|\/)(#{@example_group_types.keys.join 
           $2 == '' ? nil : $2.to_sym

Hopefully someone will find this useful.


More information about the rspec-users mailing list