47
votes

Can someone explain the difference between these two platforms?

Are both part of BDD but why should I use one or other, or both together?

4

4 Answers

103
votes

Capybara is a tool that interacts with a website the way a human would (like visiting a url, clicking a link, typing text into a form and submitting it). It is used to emulate a user's flow through a website. With Capybara you can write something like this:

describe "the signup process", :type => :feature do
  before :each do
    User.make(:email => '[email protected]', :password => 'caplin')
  end

  it "signs me in" do
    visit '/sessions/new'
    within("#session") do
      fill_in 'Login', :with => '[email protected]'
      fill_in 'Password', :with => 'password'
    end
    click_link 'Sign in'
    page.should have_content 'Success'
  end
end

Cucumber is a tool to write human-readable tests that are mapped into code. With it, you can rewrite the above example like this:

Scenario: Signup process

Given a user exists with email "[email protected]" and password "caplin"
When I try to login with "[email protected]" and "caplin"
Then I should be logged in successfully

The almost plain-text interpretation is useful to pass around non-developers but also need some code mapped into it to actually work (the step definitions).

Usually you will use Capybara if you're testing a website and use Cucumber if you need to share those tests with non-developers. These two conditions are independent so you can use one without the other or both or none.

PS: in the code snippet there is some RSpec as well. This is needed because Cucumber or Capybara by themselves cannot test something. They rely on RSpec, Test::Unit or minitest to do the actual "Pass or Fail" work.

6
votes

cucumber is a BDD tool that expresses testing scenarios in a business-readable, domain-specific language.

capybara is an automated testing tool (often used) for ROR applications.

On the capybara github page, there's an example on using capybara with cucumber.

5
votes

Cucumber is a general-purpose BDD tool. It knows nothing about web apps. So Cucumber step definitions call Capybara in order to test web apps.

0
votes
|-------------------------------|-------------------------------|
|      Cucumber                 |     Capybara                  |
|-------------------------------|-------------------------------|
| Test cases are more readable  | Test cases are not readable;  |
| and written in plain english  | Capybara also wraps RSpec and |
| text as a DSL                 | you follow the same pattern to|
|                               | write test cases              |
|-------------------------------|-------------------------------|
| Easy to iterate data using    | Not easy to iterate data      |
| tables                        |                               |
|-------------------------------|-------------------------------|
| Cucumber has its own runner   | Uses RSpec runner to execute  |
|                               | tests                         |
|-------------------------------|-------------------------------|
| Default HTML reporter         | No default HTML reporter      |
|-------------------------------|-------------------------------|
| Need to learn cucumber regex  | No such concept               |
| pattern to write step-        |                               |
| definition which is the middle|                               |
| man for test case and script. |                               |
| Btw, the regex pattern is not |                               |
| essential for all cases.      |                               |
|-------------------------------|-------------------------------|
| You can use the native        | (Wrapper)/Built on top of     |
| selenium-webdriver methods    | selenium-webdriver ruby       |
| while using Cucumber; Cucumber| library when used with        |
| is just an additional         | selenium; it can also be used |
| framework to your generic     | with two other drivers.       |
| automation framework          |                               |
|-------------------------------|-------------------------------|
| Pure BDD framework (In theory | Traditional functional test   |
| BDD sounds great. In practice,| model for end-to-end testing  |
| product owners and developers |                               |
| rarely continue to use BDD)   |                               |
|-------------------------------|-------------------------------|