abhi's logbook

Adventures in coding and coding for adventures.

Cucumber

Some helpful links to understanding Cucumber.

FactoryGirl

Referencing defined models

developer = model!(%|developer: "#{developer_name}"|)

Testing Subdomain

Given /^I visit subdomain (.+)$/ do |sub|
  host! "#{sub}.#{TEST_DOMAIN}" #TEST_DOMAIN is defined in test.rb. In my case TEST_DOMAIN = 'example.com'
end

Scenarios

Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers

Scenario Outline: Add two numbers
Given I have entered <input_1> into the calculator
And I have entered <input_2> into the calculator
When I press <button>
Then the result should be <output> on the screen

Examples:
| input_1 | input_2 | button | output |
|      20 |      30 | add    |     50 |
|       2 |       5 | add    |      7 |
|       0 |      40 | add    |     40 |

Tables

Row Tables

| id | error |
|  1 | yes   |
|  2 | yes   |
|  3 | no    |

Given /^I have a spirit with the following attributes:$/ do |table|
  table.hashes.each do |attributes|
    Spirit.create!(attributes)
  end
end

Hash Table

| id    |   1 |
| error | yes |

Given /^I have a spirit with the following attributes:$/ do |table|
  table.rows_hash['id'].should == 1
end