I don't like specs, should I change my point of view?


#1

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 ?

Thanks


#2

On 2008.11.18., at 10:56, Zouplaz wrote:

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.

Cheers,
Peter


http://www.rubyrailways.com
http://scrubyt.org


#3

On Nov 18, 2008, at 3:56 AM, Zouplaz wrote:

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 ?

I think this is a great read:

http://pragdave.blogs.pragprog.com/pragdave/2008/03/the-language-in.html

James Edward G. II


#4

James G. wrote:

On Nov 18, 2008, at 3:56 AM, Zouplaz wrote:

Do you have any link to articles that advocates for or
against specs ?

I think this is a great read:

http://pragdave.blogs.pragprog.com/pragdave/2008/03/the-language-in.html

Thanks for the link, James.

Best regards,
Bill


#5

Peter S. wrote:

Not really… but you could check out shoulda
(http://www.thoughtbot.com/projects/shoulda/
)

+1 for Shoulda.

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.


#6

On Nov 18, 4:56 am, Zouplaz removed_email_address@domain.invalid wrote:

Thanks

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.


#7

On Nov 18, 9:14 am, Brian C. removed_email_address@domain.invalid wrote:

I also find it much clearer to write

assert_equal "foo", @bar    # required value, actual value

rather than whatever_the.rspec.equivalent_is?

@bar.should == “foo”

Which I find tons clearer because you’re operating on the actual value
and comparing it to the expected.


#8

On Tue, Nov 18, 2008 at 11:29 AM, Yossef M. removed_email_address@domain.invalid
wrote:

On Nov 18, 9:14 am, Brian C. removed_email_address@domain.invalid wrote:

I also find it much clearer to write

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.


#9

On Tue, Nov 18, 2008 at 8:44 PM, Brian C. removed_email_address@domain.invalid
wrote:

Peter S. wrote:

Not really… but you could check out shoulda
(http://www.thoughtbot.com/projects/shoulda/
)

+1 for Shoulda.

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 have been using test/spec for same thing. What advantages shoulda
have over test/spec ?

Posted via http://www.ruby-forum.com/.


Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org


#10

On Tue, 18 Nov 2008 08:49:51 -0500, James G. wrote:

I think this is a great read:

http://pragdave.blogs.pragprog.com/pragdave/2008/03/the-language-in.html

James Edward G. II

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.

–Ken


#11

On Nov 18, 2008, at 10:14 AM, Brian C. wrote:

Peter S. wrote:

Not really… but you could check out shoulda
(http://www.thoughtbot.com/projects/shoulda/
)

+1 for Shoulda.

…and yet Dan C. of Thoughtbot just recently wrote up a rather
refreshing (and mildly scathing) look at Shoulda:

http://giantrobots.thoughtbot.com/2008/11/7/a-critical-look-at-the-current-state-of-ruby-testing

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!

-Josh


#12

On Nov 18, 2008, at 8:06 PM, Ken B. wrote:

beeing

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

James Edward G. II


#13

Joshua B. wrote:

…and yet Dan C. of Thoughtbot just recently wrote up a rather
refreshing (and mildly scathing) look at Shoulda:

http://giantrobots.thoughtbot.com/2008/11/7/a-critical-look-at-the-current-state-of-ruby-testing

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.

-Erik


#14

On Nov 19, 2008, at 5:00 AM, Erik H. wrote:

Unless you want the BDD stuff, use it.

Doesn’t miniunit come with minispec? Besides, even the RSpec team has
admitted you can do BDD with test/unit, right?

I’m not understanding what you are saying, clearly.

James Edward G. II


#15

There are 1360 tests in zena. I have a post about why we do not use
rspec: http://zenadmin.org/261.

What we do use a lot is yaml testing:

nodes_in_site:
src: “<r:nodes in=‘site’ limit=‘3’><r:each join=’, ’ do=‘show’
attr=‘name’/></r:nodes>”
res: “anonymous, ant, art”

Gaspard


#16

James G. wrote:

On Nov 19, 2008, at 5:00 AM, Erik H. wrote:

Unless you want the BDD stuff, use it.

Doesn’t miniunit come with minispec? Besides, even the RSpec team has
admitted you can do BDD with test/unit, right?

I’m not understanding what you are saying, clearly.

Correct, I forgot about that, as personally I never use it.

-Erik


#17

On Tue, Nov 18, 2008 at 9:06 PM, Ken B. removed_email_address@domain.invalid wrote:

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.

There’s information about the “why” here:
http://behaviour-driven.org/BehaviourDrivenDevelopment

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.


#18

On Wed, Nov 19, 2008 at 7:44 PM, Avdi G. removed_email_address@domain.invalid wrote:

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