2
votes

What I mean by that is, which tools are for unit testing, which for BDD, is there even a clear divide?

I'm just learning Ruby from C#, and the tools I'm familiar with there are xUnit-style for pure unit testing/TDD, and Cucumber/SpecFlow for BDD/integration testing. Of course, you can use unit testing tools for integration testing if you want to.

The main testing tools I've come across for Ruby are Test::Unit, RSpec, and Cucumber (there are obviously plenty more but these seem to be the most popular, and hence probably a good bet to start off with).

I'm not looking for a long list of tools here - if there's a main contender I've missed then please tell me, but I'd rather keep it simple at this stage than start using 'Tool Z beta with the Library X extensions running on the MegaChode platform' or whatever. I'm only a poor confused .Net guy, after all!

It's clear that Test::Unit was designed for unit testing, and Cucumber is for BDD. But I'm not sure about RSpec - some people seem to use it as a low-level unit testing tool, and others for higher-level BDD. At the same time, some people seem to use Test::Unit (and similar) with additional libraries for BDD.

To give you an idea of where I'm coming from, the way I see it is that you can write more functional, testable specifications (which a business guy might understand) with your BDD tool and then do low-level, developer-focussed TDD with your unit testing tool as you implement the functionality required for your Cuke (or whatever).

Is there a generally accepted way of doing these things in Ruby, or do I need to forget about such a crazy notion and use whatever seems to do the job?

Cheers, Grant

2

2 Answers

4
votes

I think most Rubyists have standardized on RSpec rather than Test::Unit for testing. If you're doing Rails apps, there is RSpec-Rails and then Cucumber you can layer on top of it.

Grab a copy of The Rspec Book @ http://www.pragprog.com/titles/achbd/the-rspec-book

0
votes

MiniTest contains both an xUnit and spec style testing interface (with the ability to combine them both in the same file).

It is included as part of the standard gems since Ruby2.2.

Both can be included in the same file which makes it easy to convert between the styles or other testing tools like RSpec and Test::Unit

require 'minitest/autorun'

describe Math do
  describe 'addition' do
    it '1+1=2' do
      (1+1).must_equal 2
    end
  end
end

class MathTest < Minitest::Test
  def test_1_plus_1_equal_2
    assert_equal 2, 1+1
  end
end

MiniTest also includes a mocking framework (although I prefer rr)