cucumber snippets

How to install cucumber, webrat, rspec, shoulda, factory_girl

Tagged cucumber, webrat, shoulda, factory_girl  Languages ruby

In config/environments/test.rb:

config.gem 'cucumber', :lib => false
config.gem 'webrat', :lib => false
config.gem 'rspec', :lib => false
config.gem 'rspec-rails', :lib => false
config.gem 'thoughtbot-shoulda',
           :lib    => false,
           :source => 'http://gems.github.com'
config.gem 'thoughtbot-factory_girl',
           :lib    => false,
           :source => "http://gems.github.com"

Then from the command line:

rake gems:install RAILS_ENV=test

Then put the following in features/env.rb:

require 'factory_girl'
require 'spec/factories' 
require 'shoulda'

How to pass a Hash as a parameter to a Cucumber/Capybara step/test

Tagged cucumber, capybara  Languages ruby

Helper:

Given(/^I receive a message from "(.*?)" with data$/) do |from, table|
  # Convert AST table into hash
  data = table.raw.transpose.to_h # ".with_indifferent_access" if needed
  # Do something with the data
end

Test:

And I receive a message from "jebus@hell.com" with data
  | first_name | last_name | status | price |
  | Jebus | Hell | broken | 4€ |

undefined method `+' for nil:NilClass (NoMethodError)

Tagged capybara, cucumber, minitest  Languages ruby

When Capybara/Cucumber tests fail:

undefined method `+' for nil:NilClass (NoMethodError)
.../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/minitest-5.10.1/lib/minitest/assertions.rb:135:in `assert'

Do this:

  1. Install test-unit
gem 'test-unit'
  1. Include assertions in env.rb
World Test::Unit::Assertions