Another week, another Ruby testing library. The latest is Spinach from the developers at Codegram which aims to remove the Regex magic from Cucumber. In Spinach, steps are implemented as Ruby classes:

# from the docs at [http://rubydoc.info/github/codegram/spinach/master/file/README.markdown](http://rubydoc.info/github/codegram/spinach/master/file/README.markdown)
class TestHowSpinachWorks < Spinach::FeatureSteps
  Given 'I have an empty array' do
    @array = Array.new
  end

  And 'I append my first name and my last name to it' do
    @array += ["John", "Doe"]
  end

  When 'I pass it to my super-duper method' do
    @output = capture_output do
      Greeter.greet(@array)
    end
  end

  ...

end

At first glance, Cucumber users will wonder how those steps could match multiple features. That’s the whole point. Spinach features are Ruby classes. Each feature has its own steps, and Spinach steps are just Ruby methods. The intent is to remove the magic of Cucumber’s Regex-based steps and to make sharing explicit via mixins. This means you can even bundle your steps and share across projects via Ruby gems.

Spinach comes with a generator that will scaffold the steps in your class based on your feature, turning a feature such as:

## features/test_how_spinach_works.feature
Feature: Test how spinach works
  In order to know what the heck is spinach
  As a developer
  I want it to behave in an expected way

  Scenario: Formal greeting
    Given I have an empty array
    And I append my first name and my last name to it
    When I pass it to my super-duper method
    Then the output should contain a formal greeting

… into

## features/steps/test_how_spinach_works.rb

class TestHowSpinachWorks < Spinach::FeatureSteps
  Given 'I have an empty array' do
  end

  And 'I append my first name and my last name to it' do
  end

  When 'I pass it to my super-duper method' do
  end

  Then 'the output should contain a formal greeting' do
  end

end

Check out the website, docs, or introductory blog post for more. I’d be interested to see how Spinach compares to Cucumber in terms of test suite speed.


Have comments? Send a tweet to @TheChangelog on Twitter.

Subscribe to The Changelog Weekly – our weekly email covering everything that hits our open source radar.