merb_cucumber as a bundled gem on Merb projects

So, after a long time I hadn’t pay any attention to merb_cucumber, when I came here, it was a little bit rough on the edges… so I helped to make it a little bit more clean.

The problem: I can’t make it work on my Merb project with bundled gems.

This are the steps to have a clean startup on a “merb-gen app” generated project:

1. Include dependencies

# On config/dependencies.rb
dependency "merb-gen", merb_gems_version
# if you want webrat to be on the project (highly recommended)
dependency "webrat" 
dependency "roman-merb_cucumber", :require_as => nil

We include the merb-gen gem on the dependencies to have access to the “bin/merb-gen” that has the cucumber generator. Besides we include the merb_cucumber dependency with a require_as equals to nil, because this will only be used as a development tool.

We then execute the thor task to have the gems bundled into the project.

$ thor merb:gem:install
$ rm -rf gems/gems/*
$ thor merb:gems:redeploy

The latter commands are there just to make sure every gem binary is on the bin folder.

After this, we execute the generator of cucumber

$ bin/merb-gen cucumber --session-type=webrat --orm=datamapper

We include the webrat session, and datamapper options here, but they are not mandatory.

Everything should work as expected when you execute the features task

$ bin/rake features
(in /Users/roman/Documents/mc_test2)
Loading init file from /Users/roman/Documents/mc_test2/config/init.rb
Loading /Users/roman/Documents/mc_test2/config/environments/development.rb
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I ...
Feature: Login
  To ensure the safety of the application
  A regular user of the system
  Must authenticate before using the app

  Scenario Outline: Failed Login               # features/authentication/login.feature:6
    Given I am not authenticated               # features/authentication/steps/login_steps.rb:1
    When I go to /login                        # features/steps/webrat_steps.rb:4
    And I fill in "login" with "<mail>"        # features/steps/webrat_steps.rb:16
    And I fill in "password" with "<password>" # features/steps/webrat_steps.rb:16
    And I press "Log In"                       # features/steps/webrat_steps.rb:8
    Then the login request should fail         # features/steps/result_steps.rb:13
    Then I should see an error message         # features/steps/result_steps.rb:9

    | mail           | password       |
    | not_an_address | nil            |
    | not@not        | 123455         |
    |    | wrong_paasword |

3 scenarios
21 passed steps

Everything should be in order now.