# Rspec file organization

**URL:** <https://www.ruby-forum.com/t/rspec-file-organization/156717>\
**Category:** Ruby\
**Created:** [January 1, 2009, 9:46pm UTC](https://www.ruby-forum.com/t/rspec-file-organization/156717 "2009-01-01T21:46:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotjuneshen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f19dbf/32.png) [@hotjuneshen](https://www.ruby-forum.com/u/hotjuneshen)\
**Post date:** [January 1, 2009, 9:46pm UTC](https://www.ruby-forum.com/t/rspec-file-organization/156717/1 "2009-01-01T21:46:25Z")

</div>

Hi,

How should i best organise my custom matcher files, should stay in  
spec/matchers? And how should they be namespaced? Also where should i  
but custom example groups?

module ProjectName  
module Spec  
module Matchers  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![hotjuneshen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f19dbf/32.png) [@hotjuneshen](https://www.ruby-forum.com/u/hotjuneshen)\
**Post date:** [January 2, 2009, 8:05pm UTC](https://www.ruby-forum.com/t/rspec-file-organization/156717/2 "2009-01-02T20:05:08Z")

</div>

On Thu, Jan 1, 2009 at 2:45 PM, Jon S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> How should i best organise my custom matcher files, should stay in  
> spec/matchers? And how should they be namespaced? Also where should i  
> but custom example groups?

I keep them in spec/support/matchers. As for namespacing, I don’t  
write them into the Spec::Matchers module, but rather in their own  
module (like you have below), which then gets included via the  
configuration in spec/spec\_helper.rb:

Spec::Runner.configure do |config|  
config.include(ProjectName::Spec::Matchers)  
end

I actually haven’t written any custom example groups aside from those  
in the rspec-rails library, so I don’t have a convention for this, but  
I imagine I’d put them in spec/support/example\_groups.

HTH,  
David

ps - you may want to check out the rspec users group as well:  
[http://groups.google.com/group/rspec](http://groups.google.com/group/rspec)

---

<div class="post-metadata">

**Author:** ![hotjuneshen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f19dbf/32.png) [@hotjuneshen](https://www.ruby-forum.com/u/hotjuneshen)\
**Post date:** [January 2, 2009, 8:40pm UTC](https://www.ruby-forum.com/t/rspec-file-organization/156717/3 "2009-01-02T20:40:06Z")

</div>

Thanks for you suggestion, i will go for the support folder. I’m not  
sure if I use the example group as i should. I have done a special one  
for acceptences test with watir.

class AcceptanceExampleGroup \< Spec::Rails::Example::RailsExampleGroup  
self.use\_transactional\_fixtures = false  
attr\_reader :browser

before(:all) do  
@browser = Watir::Safari.new  
end

before(:each) do  
load(File.join(Rails.root, ‘db’, ‘schema.rb’))  
end

after(:all) do  
# @browser.close  
end

Spec::Example::ExampleGroupFactory.register(:acceptance, self)  
end

I maybe should use cucumber here, but as we don’t use it yet i feels  
better to don’t add more frameworks.

Thanks  
Jon

David C. wrote:

> On Thu, Jan 1, 2009 at 2:45 PM, Jon S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi,
> > 
> > How should i best organise my custom matcher files, should stay in  
> > spec/matchers? And how should they be namespaced? Also where should i  
> > but custom example groups?
> 
> I keep them in spec/support/matchers. As for namespacing, I don’t  
> write them into the Spec::Matchers module, but rather in their own  
> module (like you have below), which then gets included via the  
> configuration in spec/spec\_helper.rb:
> 
> Spec::Runner.configure do |config|  
> config.include(ProjectName::Spec::Matchers)  
> end
> 
> I actually haven’t written any custom example groups aside from those  
> in the rspec-rails library, so I don’t have a convention for this, but  
> I imagine I’d put them in spec/support/example\_groups.
> 
> HTH,  
> David
> 
> ps - you may want to check out the rspec users group as well:  
> [http://groups.google.com/group/rspec](http://groups.google.com/group/rspec)
