简体   繁体   English

如何使用RSpec进行测试设计?

[英]How-to test devise with RSpec?

I just wondering, how to test devise's controller with rspec? 我只是想知道,如何用rspec测试devise的控制器?

With devise, we hand off most of users controller's action to devise, and maybe only a show action for users, and I write the user#show spec in spec/controllers/users_controller_spec.rb , but what about the other actions supplied by devise, how to test them? 通过devise,我们将大部分用户的控制器动作(可能只是针对用户的show动作)交给了我,我将用户spec/controllers/users_controller_spec.rb规范写在spec/controllers/users_controller_spec.rb ,但是spec/controllers/users_controller_spec.rb提供的其他动作呢?如何测试它们?

or, I just don't need to test the devise controller, 'cause it is been tested while develop the gem? 或者,我只是不需要测试devise控制器,因为它是在开发gem时经过测试的?

Personally I would not test devise itself. 就个人而言,我不会自行测试设计。 That's the responsibility of the author of that gem. 那是该宝石的作者的责任。 What I would focus on is the behavior of your application instead. 我要重点关注的是您的应用程序的行为。 Isolate the devise code by mock/stub where necessary and only test your side of the points where your code intersects with the devise code. 必要时通过模拟/存根隔离设计代码,并仅测试代码与设计代码相交的那一侧。

That's not to say you can't write a few quick tests on critical behavior--log in for example. 这并不是说您无法针对关键行为编写一些快速测试,例如登录。

You might consider reading The Rspec Book . 您可以考虑阅读The Rspec Book I found it invaluable to getting my head into the BDD & Rspec mindset. 我发现投入BDD和Rspec思维定势非常宝贵。

如果您想要一些示例,请使用Devise和RSpec和Cucumber查看Rails 3.1中的源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM