Gherkin feature file example

May 25, 2014, 8:07 p.m.

Feature: Todo

    In order to use the site
    As a user
    I want to be able to submit, view and delete to-do list items

    @javascript
    Scenario Outline: New item
        Given I am on the home page
        When I click on New Item
        And I fill in the item with <item>
        And I click the button Submit
        Then I should see the text <item>
    Examples:
        | item                         |   
        | Feed cat                   |   
        | Stop milk                 |   
        | Take over world       |

Objective-C example

May 25, 2014, 8:06 p.m.

#import "Cocoa1AppDelegate.h"

@implementation Cocoa1AppDelegate

@synthesize window,siteUrl,pageContents;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    model = [[Cocoa1Model alloc] init];
}

- (IBAction)getSiteContents:(id)sender {
    [model setPageUrl:[siteUrl stringValue]];
    NSString* reply = [model getUrlAsString];
    NSLog(@"pageSrc: %@", reply);
    [pageContents setString:reply];
    [[[pageContents textStorage] mutableString] appendString:reply];
}

@end

Perl example

May 25, 2014, 8:05 p.m.

use strict;
use warnings;

# Greet the planet
print "Hello world!";

JavaScript example

May 25, 2014, 8:04 p.m.

'use strict';

// Define a function
function hello() {
    return "Hello world!";
}
console.log(hello());

PHP example

May 25, 2014, 8:04 p.m.

<?php

// Greet the planet
echo "Hello world!";
?>