0
votes

After reading up on rspec 2 and capybara 2 I'm slightly confused regarding best practices as far as structural directory layout is concerned. There seems to be some overlap between the various specs (such as request specs and controller specs for instance), and I was wondering what is the "best practice" way of organising these files, and what should each spec test?

What I've gathered so far (which may be wrong) is the following:

spec/factories

Factories used by Factory Girl (if used)

spec/features

Capybara tests, which emulate the interaction between a user and your application.

spec/models

Tests for model validation

spec/controllers

Testing controller actions (#new, #edit, #create etc.)

spec/requests

Tests for integration between various controllers (one level 'higher' than controller specs)

spec/support

Files which define modules that could be useful to include in some of the specs.

spec/acceptance

Acceptance tests.

spec/views

Tests concerned with whether views were rendered correctly

I personally feel that for instance spec/views seems unnecessary in the sense that the capybara tests also are concerned with views (and how they look) and controller tests could easily also test whether or not a certain view is rendered.

What are your thoughts?

1

1 Answers

1
votes

from my point of view spec/acceptance and spec/features are the same.

spec/views is something completely different, as you can test specific views or partials in isolation. this is very helpful for complex views and you don't need to have any browser simulator.

in regards to capybara spec, i use a different approach that you can read about here: https://gist.github.com/phoet/6683280#file-readme-md