Hello, I’m not trolling. I don’t like specs (RSpec) : everytime I had a
look to specs I felt it was only syntaxic sugar driven by a big
machinery and I continued to write classic unit tests.
But I’ve seen more and more projects using rspec - So I consider beeing
wrong about this software.
Do you have any link to articles that advocates for or against specs ?
Or do you have any argument in favor of specs compared with plain old
test suites ?
Hello, I’m not trolling. I don’t like specs (RSpec) : everytime I
had a look to specs I felt it was only syntaxic sugar driven by a
big machinery and I continued to write classic unit tests.
But I’ve seen more and more projects using rspec - So I consider
beeing wrong about this software.
Do you have any link to articles that advocates for or against
specs ? Or do you have any argument in favor of specs compared with
plain old test suites ?
Not really… but you could check out shoulda
(http://www.thoughtbot.com/projects/shoulda/
) - it’s closer to Test::Unit (basically a set of macros on top of
Test::Unit), but server a similar purpose as rSpec. You have to solve
the mock question (if you want to use mocks at all) - I’d recommend to
check out Mocha.
Hello, I’m not trolling. I don’t like specs (RSpec) : everytime I
had a look to specs I felt it was only syntaxic sugar driven by a
big machinery and I continued to write classic unit tests.
But I’ve seen more and more projects using rspec - So I consider
beeing wrong about this software.
Do you have any link to articles that advocates for or against specs ?
You can keep using all the existing assert_xxx macros of Test::Unit, but
wrap up groups of tests in a logical and hierarchical way.
I also find it much clearer to write
assert_equal "foo", @bar # required value, actual value
rather than whatever_the.rspec.equivalent_is?
FWIW, I use Shoulda with mocha. I previously used flexmock, but I found
its error messages when expectations are not met to be very unhelpful in
locating the problem.
I wasn’t crazy about what I had read about rspec, but then the
management side of agile, scrums etc hasn’t appealed to me either and
I can’t say I’ve had much of any positive experiences with it thus
far.
assert_equal "foo", @bar # required value, actual value
I’ve never found that syntax clear or natural, despite doing it for
years. I always have to look up the exact wording of any assertion
other than assert_equal, and I can never seem to remember which side
the “expected value” is conventionally placed on. Using RSpec has
been like finally being able to write expectations the way my fingers
have been wanting to write them all these years.
I’ve read that before. Can anyone defend rspec against that attack? What
does rspec do better? I want to get a better idea of why they invented
this quasi-English framework.
If you haven’t yet, look at MiniTest. It claims to be a foundation for
building other test suites, but I rather like it on it’s own. Small,
simple, fast…and I really like their Mock strategy. Very clean…
like Ruby!
I’ve read that before. Can anyone defend rspec against that attack?
What
does rspec do better? I want to get a better idea of why they invented
this quasi-English framework.
I think RSpec does some things well.
I love the normal strings used for test naming as opposed to wearing
out your underscore key with test/unit
I have found contexts to be generally an improvement, despite the
negative break down from the shoulda author
Despite the jokes about how they just changed a T to a B, I do think
BDD has improved awareness of key testing concepts
If you haven’t yet, look at MiniTest. It claims to be a foundation for
building other test suites, but I rather like it on it’s own. Small,
simple, fast…and I really like their Mock strategy. Very clean…
like Ruby!
It’s kind of misleading. Many of the assertions he uses in the
Test::Unit example are rails-specific, and don’t work with the standard
library (1.8 test/unit or miniunit/minitest/bfts compat layer) like he
claims.
I’ve dealt with this struggle a bit recently… I think I can safely
comment on Test::Unit and Miniunit.
Miniunit is good for simple situations. Most situations are simple.
There’s nothing wrong with that. Unless you want the BDD stuff, use it.
If you need to do anything unorthodox, you will not find (or be capable
of doing without extensive monkeypatching) that support in miniunit. One
of the nice things in particular about Test::Unit is that it takes a
very OOP nature to testing; Miniunit is very top-down and the parts are
harder to deal with individually than with Test::Unit, and miniunit is
small and light as a result.
QA and Testing is one thing Perl really excels at. I think it would be
wise to look at how they’re doing it and consider adapting ruby’s
environment to deal with it in a similar way. TAP and Test::Harness mean
that you can write the test suite with print statements if you really
want to, that’s a powerful abstraction I don’t think is transferring
well between language communities due to perl’s pariah status here.
I’ve read that before. Can anyone defend rspec against that attack? What
does rspec do better? I want to get a better idea of why they invented
this quasi-English framework.
BDD is, as you’ve identified, just testing with a slightly different
vocabulary. But vocabulary is important: it influences how you think
about the problem.
I’ve seen a lot of TDD code fall into the rut of “let’s test method A,
now let’s test method B, now let’s test method C”. BDD encourages a
different focus and a different organization: “let’s talk about how
this object should behave in situation A. Now let’s talk about how
the object should behave in situation B.” The granularity is based on
contextual behavior, rather than on methods.
The very best TDD unit tests I’ve seen have provided a well-organized
breakdown of the expected inputs and outputs of each method in a
class, and were usable as documentation by a programmer.
Documentation, not a document. By contrast, the very best BDD specs
I’ve seen have read almost like a prose document describing the
system’s behavior, one you could read aloud to a client and have them
understand and either agree or disagree.
about the problem.
class, and were usable as documentation by a programmer.
Documentation, not a document. By contrast, the very best BDD specs
I’ve seen have read almost like a prose document describing the
system’s behavior, one you could read aloud to a client and have them
understand and either agree or disagree.
–
Avdi
Depending on what I am doing, I start by writing the end-user
documentation (prose, phrases, examples, drawings, pictures)
explaining the behaviour of an object, with the different possible
approaches, etc. This document is refined until everything seems to
fall naturally in place. Then I divide the problem into small
objectives by writing unit tests. And finally I write the code. I
think this approach is very close to BDD with one simple but important
difference: I can write nice, searchable, illustrated documentation
with real, sometimes funny, phrases.
I find RSpec to be a poor middle man: not good enough for literature,
too verbose/intrusive for simple tests.
gaspard
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.