Skip to content

Instantly share code, notes, and snippets.

View mattwynne's full-sized avatar

Matt Wynne mattwynne

View GitHub Profile
#create_club.feature
Scenario: Admin adds a club with valid information
Given I am signed in as an admin with the email "[email protected]"
And the city "Barcelona" already exists
And I go to the new club page
When I fill in the following:
| Nombre | Ribelinos |
| Calle | Avda. Diagonal |
| Número | 661 |
@mattwynne
mattwynne / user_helper.rb
Created December 8, 2010 19:31
Cucumber support module for helping with authentication of users.
module UserHelper
attr_accessor :current_user
class Credentials < Struct.new(:email, :password)
def self.parse(arg)
return arg if arg.is_a?(Credentials)
new(arg)
end
def initialize(credentials)
@mattwynne
mattwynne / be_same_file_as.rb
Last active May 21, 2022 13:27
RSpec matcher to compare two file, using their MD5 hashes
RSpec::Matchers.define(:be_same_file_as) do |exected_file_path|
match do |actual_file_path|
expect(md5_hash(actual_file_path)).to eq(md5_hash(expected_file_path))
end
def md5_hash(file_path)
Digest::MD5.hexdigest(File.read(file_path))
end
end
[bar, dog, foo, { c => [rat, cat, dog] }, a, b]
- bar
- dog
- foo
- c:
- rat
- cat
- dog
- a
# this would be in a helper somewhere
def stub_find(entity)
result = mock_model(entity)
entity.stub(:find).with(result.id).and_return(result)
result
end
let(:params) do
{:these => 'params'}
end
class Fruit
attr_reader :colour
def initialize(colour)
@colour = colour
end
def ripe?
false
end
module ImageSpec
require 'open3'
class Comparison
def initialize(expected, actual, max_acceptable_score = 0.01)
@expected, @actual = expected, actual
@max_acceptable_score = max_acceptable_score
end
def look_similar?
@mattwynne
mattwynne / gist:825967
Created February 14, 2011 14:48
invoice.feature
Scenario: Create an invoice
Given I am an authenticated user with an admin role
And a client "test client" exists with name: "test client", initials: "TTC"
And a project "test project" exists with name: "test project", client: client "test client"
And a ticket "test ticket" exists with project: project "test project", name: "test ticket"
And a work_unit "test work unit" exists with ticket: ticket "test ticket", scheduled_at: "2010-01-01", hours: "1"
And I am on the admin invoices page
Then I should see "test client"
And I follow "test client"
And I fill in "global_invoiced" with "123"
git log --all -M -C --name-only | grep -E '^(app|lib|spec|features)/' | uniq | sort | uniq -c | sort
# A Ruby meta-programming puzzle for polite programmers.
# The challenge is: you have a class Foo which you want to monkey-patch, but politely.
require 'test/unit/assertions'
include Test::Unit::Assertions
# Here's the default behaviour of Foo
class Foo
def bar