Friday, February 12, 2010

RSpec, should and Watir; what was the point again?

In the Watir group, I read this post about using RSpec with Watir and it still doesn't make sense to me why someone would want to use RSpec with Watir. The long and short of the thread was that someone was unclear on the syntax of RSpec
questionframe.radio(:id, "rlbYesNo_0").checked? should be_true
vs
questionframe.radio(:id, "rlbYesNo_0").checked?.should be_true

Later, others discussed the proper syntax of matchers in other veins as well, the idea of writing your own matchers, and someone brought up later that a fix had been added to RSpec because it and Watir were not playing together exactly right. http://groups.google.com/group/watir-general/browse_thread/thread/f7b72bf1742d8895

The confusion displayed, potential for incorrect syntax, time spent learning/discussing, and fact that you're introducing another layer of someone else's code to test for you which may itself contain bugs are good enough reasons for me not to use RSpec (keep reading).

I don't believe
x.should have_something

is that much clearer than
assert(x.has_something?)

I believe the more code between (the meat of) your testcase and the app under test, the more likely you are to introduce bugs (yours or someone else's) and the more time you have to spend testing your test code.

I almost wrote this post asking "why use RSpec at all?" but after looking at RSpec's homepage again I was reminded what it's real purpose is: BDD (no screwing around for reals BDD, a development tool). I think that's what doesn't jive with Watir. I don't think Watir would be a great tool for BDD in most cases. Watir is a GUI test tool and (if you're writing very specific, potentially lengthy tests) an end-to-end test tool. Also it's just slow. If you're doing serious BDD you need your tests to run fast and preferably test the minimal set of your code as possible. Watir is too slow and just does too much for that. 

The RSpec homepage even says "Take very small steps. Don’t rush ahead with more code. Instead, add another example and let it guide you to what you have to do next. And don’t forget to take time to refactor your code before it gets messy. You should keep your code clean at every step of the way."

RSpec is "pretty" in that it's almost painfully obvious (which I appreciate, I try to write obvious code), but I don't think that's the end it's trying to reach. It's real end is trying to facilitate BDD.

No comments:

Post a Comment

Email: How to Handle Unplanned Absences & Missing Deadlines

  Motivation Life happens, no one is perfect.  Someone on my team got Covid and had to miss work.  She prepared the best she could, looped i...