2 ms·
Nope, forget about it. I myself would prefer something that's obvious at a glance like: assert a == b assert(a == b, "description") Or if for some rea
by quectophoton 3y ago
Nope, forget about it. I myself would prefer something that's obvious at a glance like:
assert a == b
assert(a == b, "description")
Or if for some reason there's a need to pretty-print the values, then I could accept something like:
# Patching `==` to be able to pretty-print the values of both ends.
assert { a == b }
Instead we have a weird attempt at "natural" language. You'd think it would be something like:
# Simple method that does one obvious thing.
# Easily greppable. Easily searchable on internet.
expect(a).to_equal(b)
# We're already wrapping `a` with `expect`, so what's wrong with using
# the obvious operators like `==` that already exist in Ruby?
expect(a) == b
... but nope, instead there's a redundant `.to` added just for the sake of trying to be fancy and creative and showing off composition:
expect(a).to equal(b)
And then if you even want negation (the equivalent of some `a != b`), then which of these are correct and which are wrong?
expect(a).not.to be(b)
expect(a).to not_be(b)
expect(a).to.not be(b)
expect(a).to not.be(b)
expect(a).to_not be(b)
expect(a).not_to be(b)
Trying to shoehorn English into a DSL like this is a leaky abstraction at best. And not only does it look out of place, but it also makes you wonder if your correctly-written English is actually not the correct combination of keywords and is just checking something different than what you intended.
- titusjohnson 3y ago> And then if you even want negation (the equivalent of some `a != b`), then which of these are correct and which are wrong? This whole argument just seems incredibly... pedantic. You don't need to wonder which is right and wrong, if you're familiar with the DSL you'll _know_, because you write Ruby, if you're not then the first time you run the spec you'll get a nice error, and then you'll _know_. RSpec is goddamn gold. You read far, far more code than you write. Tests (and well written Ruby) reading like English is such a velocity boost I wouldn't trade it for the world.