fooyeahcode

Link

Spinach - Like Cucumber but with more Ruby, less Regex

thechangelog:

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.

via thechangelog
Posted on Monday, October 24 2011.
22
Notes
  1. best-bridge-camera-2012 reblogged this from thechangelog
  2. aston-j liked this
  3. melanieshebel liked this
  4. melanieshebel reblogged this from thechangelog
  5. haru012 reblogged this from thechangelog
  6. simplyexpressingmyself liked this
  7. nerdybiker liked this
  8. fooyeahcode reblogged this from thechangelog
  9. seoway liked this
  10. thechangelog posted this
fooyeahcode

When I am programming, I am at a nexus. My thoughts become concrete. My ideas transform illusion into reality. The structure of existence is remade before my very eyes. I become a vessel for the creative force of the universe. I am carried aloft as if on the wings of dragons. Why should I care if nobody knows my name?

The Hacker Ethic
Ask me anything Submit
Previous Next