有多少人使用 Rspec 作为控制器和视图?
对于控制器和视图也使用 Rspec 是否有充分的理由?
我的视图严重依赖于 Javascript,据我所知,Rspec 不处理视图上的 javascript/ajax。我还使用 Cucumber + Selenium 来实现这一点。
我应该将它用于控制器吗?
仅使用 Cucumber + Selenium 来实现应用程序行为还不够吗?因为如果黄瓜测试通过了,那么它就通过了,为什么我要为 Rspec 视图和控制器测试烦恼呢?
有人可以启发我这个话题吗?
Are there strong reasons for using Rspec for controllers and views too?
My views are heavily dependent on Javascript, and as far as I know, Rspec doesn't handle javascript/ajax on views. Also im using Cucumber + Selenium for that.
And should I use it for controllers?
Isn't it enough to just use Cucumber + Selenium for the application behavior? Cause if a cucumber test passes, then it passes, why should I bother with Rspec view and controller tests?
Could someone enlighten me on this topic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 Cucumber + Shoulda 的组合,但我要告诉您的内容仍然适用于您的设置。
在测试控制器时,我在功能测试中使用 Shoulda 来应对所有“负面身份验证”情况。例如:
我使用 Shoulda 来做到这一点,因为我通常寻找的是我被踢到登录页面,并且任何试图被恶意访问的模型实际上都没有改变。我可以使用 Cucumber 来实现此目的,但我发现使用一些 Shoulda 宏和一些功能测试更容易、更省事。应该上下文非常适合这里。
然后,对于“良好的身份验证”情况,我使用 Cucumber。例如:
这些类型的测试要求我检查一些实际的页面内容,而不仅仅是一遍又一遍地检查“访问被拒绝”。我发现 Cucumber 的描述性在这里非常匹配。
I use a combination of Cucumber + Shoulda, but what I'm about to tell you still applies to the setup you have.
When testing a controller I use Shoulda in a functional test to hit all of my "negative auth" situations. For example:
I use Shoulda for this, because what I'm generally looking for is that I was kicked to the login page, and that whatever model was trying to be accessed maliciously wasn't actually changed. I could use Cucumber for this, but I find it easier and less cumbersome to do with a handful of Shoulda macros and some functional tests. Shoulda contexts are a great fit here.
Then for the "good auth" situations, I use Cucumber. Things like:
These types of tests require that I check some actual page content, and not just check for "access denied" over and over again. I find the descriptiveness of Cucumber to be a great match here.
如果您构建了足够完整的测试集,则可以使用 selenium,但如果您想与应用程序的其余部分分开测试 javascript 的行为,则可以考虑使用 javascript 测试框架,例如 QUnit。
If you build a full enough set of tests, you can just use selenium, but if you want to test the behaviour of your javascript seperate from the rest of the app, you might consider using a javascript test framework, like QUnit.