On Jul 28, 2011, at 10:22 AM, Piter Fcbk wrote:
> I was trying out RSpec framework in a project and got stopped doing the unit
> test of a model. In particular, doing the test for the associations and the
> ActiveRecord validations.
> I started writing the validations but my tests didn't look DRY at all. Before
> refactoring the tests checked out and look for other people solutions.
> I found out shoulda-matchers and Shoulda (which if I didn't get it wrong is
> another testing framework). Actually I found another one, remarkable, but it
> look it doesn't work with Rails 3.
>
> Does anyone have any advice, comments, suggestion on this matter?
>
> Right now I continue on using RSpec and shoulda-matchers. The last one mainly
> for testing the validations and associations of the models.
> Any advice and/or help will be appreciated.
>
> Thanks in advance.
rspec + shoulda matchers is a fairly common pairing these days, so you're not
alone.
Personally, I use them for validations (which are behavior), but not for
associations (which are structure). Rather than specifying, for example, that a
team has many players, I just use the players collection in an example that
uses them:
describe Team do
it "does not have any open spots if there are 30 players" do
team = Factory(:team)
30.times { team.players << Factory(:player) }
team.should_not have_opening
end
end
HTH,
David
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users