Rails: Testing named scopes with RSpec

后端 未结 4 1226
滥情空心
滥情空心 2020-12-24 05:40

I am new to testing Rails web applications and RSpec. I work with legacy code and need to add tests. So what is the best way to test finders and named scopes with RSpec?

4条回答
  •  梦谈多话
    2020-12-24 06:27

    The creator of RSpec has recently blogged he thinks Validations are behavior, associations are structure. In other words he finds that associations (and scopes) should not nessesarily be tested directly. Tests for these will follow from the behavior you want.

    In other words, current wisdom is that there is no need to test each scope directly, since you will cover these associations by testing the behavior of your application.

提交回复
热议问题