Skip to content

Instantly share code, notes, and snippets.

View wojtekmach's full-sized avatar

Wojtek Mach wojtekmach

View GitHub Profile
class Game
XN = 100
YN = 100
def initialize
@cells = {}
end
def add(x, y)
@cells["#{x}-#{y}"] = 1
class Context
def initialize(*listeners)
@listeners = listeners
end
def signal(method, *args)
@listeners.each do |listener|
listener.send method, *args
end
end
describe 'Notifier' do
before do
SMS.stub(:deliver)
Expense.stub(:create)
@user = double 'user', mobile_number: '1234'
@message = 'hello'
Notifier.notify(@user, @message)
end
# the point is to run the costly operation just once yet still be able to use
# convenient "should change by" syntax.
def transform
# sleep 2
$x = 11
$y = 22
$z = 33
end
require 'meatloaf'
require 'steps'
Feature "Eat candies" do
Scenario "Eat a candy from a jar full of them" do
Given "I have a jar with candies", candies: 10
When "I eat one candy"
Then "the jar won't be empty"
end

gist.io

testing...

require 'RMagick'
require 'capybara'
require 'launchy'
module Capybara::Recording
def start_recording
system "rm -f tmp/*"
end
def save_recording
@wojtekmach
wojtekmach / minitest_contracts.rb
Created March 17, 2013 02:04
POC "inline" contract tests with MiniTest
# POC "Inline" contract tests with MiniTest
#
# The idea is to run a contract test immediately after a mock object is created.
#
# Example:
#
# Say a `Registration` uses `Payment` (which uses `PaymentGateway`)
#
# def test_successfull_payment
# payment = double
(set -e;
git rev-list --reverse origin/master..master |
while read rev; do
echo "Checking out: $(git log --oneline -1 $rev)";
git checkout -q $rev;
python runtests.py;
done)
@wojtekmach
wojtekmach / minitest_shared.rb
Last active December 17, 2015 08:59
minitest/spec + shared examples
require 'minitest/autorun'
class MiniTest::Spec
def self.include_tests(tests)
tests.each do |args, block|
it(*args, &block)
end
end
end