$ rspec ~/insane-magic.spec
F
Failures:
1) Rspec should not allow you to make shit up
Failure/Error: [1, 2, 3].should have(4).potatoes
expected 4 potatoes, got 3
# /Users/graham/insane-magic.spec:5
Finished in 0.00042 seconds
1 example, 1 failure
Do you see the potatoes
method call? Why isn't Ruby complaining that
it doesn't exist? Where the hell did it come from? Is it part of rspec?
It must be, surely. That's the only library I've required!
[Goes off to grep the rspec gems for "potatoes"... doesn't find it]
What's happening here? RSpec is purposefully ignoring .potatoes
, which
is a method call on the object returned by #have
. And what is that
object, exactly?
So RSpec (and this "BDD" business) is good for people new to testing you say? Really?
The "call any method you like and we'll silently ignore it" behaviour is not syntactic sugar, it's pain and confusion for people who are new to programming. It's a bloody daft idea to put it forward as good practice in a widely popular library.
Some bad ideas catch on just as easily as good ideas, and this approach is its own special breed of footgun.
To be clear, I like describe
and it
. But you can stop there; I feel
RSpec's features have a negative impact on productivity from there on
in.
And for comparison, the Contest gem adds support for these blocks to test/unit in 100 lines of code.
Now that a newbie Ruby programmer has got over the fact that grep has failed them, could they start to wonder how some objects seem to have a
should
method defined on them? Andhave
, where did that spring up from? They're not mentioned in their Ruby book. Perhaps they conclude that their Ruby book covers 1.8.7 and they're using 1.9; perhapsshould
is a new method on Array in Ruby 1.9? Yeah that's probably it...This kind of thought process goes on all the time when somebody is learning a new language. This "DSL" (there's another frigging annoying fashion based Ruby meme) drives my sympathetic side nuts.