18

I am starting on BDD. Was wondering which would be better to start with Cucumber or Spinach. My impression is that Spinach is new off the block. Look here

Which one should I start with. The criteria would be -

  1. Support across the board.
  2. Flexibility of use
  3. Third party tool and APIs integration.

Again it might be ignorant question of the newbie: Where does capybara fit into the picture.

1
  • Is there anything which Cucumber can do, but Spinach will not be able to do, currently.
    – Sam Wilder
    Nov 4, 2011 at 2:59

4 Answers 4

20

For some context, I've been a long time user of Cucumber, but always wished it was Spinach since day one. I'm switching all my projects to Spinach despite its shortcomings because it uses the new, hot-off-the-block PORO technique (Plain Old Ruby Objects ;). Now I can expand my steps however I want, because it's just Ruby.

To answer your question, as of this writing:

  1. Support across the board.

Cucumber

Spinach is still developing some features, including 'Background' blocks, and I'm currently trying to get it to recognize tables.

  1. Flexibility of use

Spinach

Cucumber encourages bad step design from the start, IMO. If you create feature-specific steps, you'll trip over them later, and if you create reusable global steps, your feature definitions will be long, generic, and boring to read. I've heard people claim they can walk a balance successfully and be just specific enough but still have reusable steps; I consider myself well versed enough that if I can't do it reliably, it's too hard.

  1. Third party tool and APIs integration

Cucumber, assuming the bullet point could be interpreted as community.

If it's really "third party tools and API integration" you're after, Spinach supports capybara and rspec, which is most of what you're after. Cucumber has 3rd party reusable step libraries, but as noted in my earlier point, I think this is bad. In regard to 3rd party & integrations, even if it's not there yet, your really can't get any better than plain old ruby objects.

Where does capybara fit into the picture

Capybara is your test interface to your site, aka a testing mouse & keyboard. You could start it up in a console and drive your app, but that'd get repetitive. Cucumber/Spinach (or rspec/test-unit/minitest) all could use capybara to automate testing your app. People prefer Cucumber/Spinach because they help you step out of the code for a bit to think like a user.


Overall, you'd probably be best off getting an rspec/cucumber book and doing what it says. Just be aware that testing takes a while to get good at, so don't stop there. Maybe check out Spinach somewhere in the process; if you like Cucumber, you might find you'll really like Spinach.

2
  • I'm only a few features in to a new project, and I already feel that the global step definition space is going to cause me problems for the exact reasons mentioned here. I've tried out spinach, and the only reason we went with Cucumber for now was tools (Rubymine) integration. Mar 9, 2012 at 5:44
  • FWIW, spinach made some deal-breaker choices for me, so I never leaned in with it and have instead been using plain capybara+rspec for years, to great success
    – Woahdae
    Mar 2, 2016 at 21:38
16

DISCLAIMER: I'm a Spinach mantainer.

If you're starting with BDD I'd highly recommend two books:

I think it's important to learn all the BDD and TDD process (outside-in etc..) and then choose the tool you feel more comfortable with.

Having said that, Cucumber has a huge community, but a lot of things are also aplicable to Spinach, since what they have in common is Gherkin.

As for flexibility of use I would say both are really flexible, but I (obviously) prefer Spinach as every feature it's just a Ruby class, where you can include modules, inherit from other classes and so on (this also applies to APIs integration).

I you want, you can take a look at the spinach-rails-demo and see how everything works.

1
  • Thanks for providing your viewpoint. I will take a look at the resource you have mentioned.
    – Sam Wilder
    Nov 6, 2011 at 14:53
2

If you're stuck with Cucumber and you don't want global steps, you can work around the problem by tagging the steps with some sort of scenario ID:

# features/1_greetings.feature
Scenario: Formal greeting
  Given I have an empty array [#1]
  And I append my first name and my last name to it [#1]
  When I pass it to my super-duper method [#1]
  Then the output should contain a formal greeting [#1]

The #1 scenario id can be any value. I like to use ticket numbers for future reference.

You can then place all the steps in one step definition file. It's close enough to the look of Spinach::FeatureSteps. No regex arguments too!

# features/step_definitions/1_greetings.rb
Given 'I have an empty array [#1]' do
  #...
end

And 'I append my first name and my last name to it [#1]' do
  #...
end

When 'I pass it to my super-duper method [#1]' do
  #...
end

Then 'the output should contain a formal greeting [#1]' do
  #...
end

I posted more about the workaround at github.

1

I can't really speak for Spinach, as I've never used it, but Cucumber definitely has a huge community support with loads of external libraries.

Capybara allows you to easily test web applications

When I fill in "username" with "foo"
And I click on "login"
Then I should see "enter your password"
3
  • 1
    Looking at the brief presentation here, would you say it has something more to offer than Cucumber.
    – Sam Wilder
    Nov 4, 2011 at 2:58
  • 1
    Imo, if you're writing cukes like that, you're doing something a bit wrong. Capture the domain, not the web.
    – SpaceGhost
    Aug 16, 2012 at 22:45
  • If you are testing the Login screen itself, such steps are fine, but the so called web steps in general are considered a bad idea which is responsible partly for the bad reputation of Cucumber. Read more about it from Aslak, one of the authors himself: aslakhellesoy.com/post/11055981222/the-training-wheels-came-off
    – onetom
    Oct 6, 2013 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.