Using shoulda to refactor rspec tests on Rails models

前端 未结 5 2304
闹比i
闹比i 2021-02-14 00:57

After learning about shoulda-matchers by answering another StackOverflow question on attribute accessibility tests (and thinking they were pretty awesome), I decided to try refa

5条回答
  •  我寻月下人不归
    2021-02-14 01:46

    Your question touched on a few points, I would like to address two of them:

    The answer is subjective, so I will give you my personal take.

    1) Test ActiveRecord that way?
    My answer is yes. You could write complex tests with real data but if you basically trust ActiveRecord you can do it this way and if you get to doing tdd, with these tests first they can help in that process.

    2) Write the model tests at all?
    My answer is yes. What I do is focus controller and request specs on the happy path and then for cases where validations and the like are needed I write unit model tests for them. This has turned out to be a good division of responsibility to me.

提交回复
热议问题