开发者

How many use Rspec for controllers and views?

开发者 https://www.devze.com 2023-01-12 03:35 出处:网络
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 usi

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开发者_Python百科 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?


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:

  • A logged in user trying to access an admin page.
  • A logged out user trying to access protected content.
  • User A trying to delete User B's post.

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:

  • A user accessing his own preferences page.
  • An admin pulling up reports.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消