Skip to content

Instantly share code, notes, and snippets.

View wojtekmach's full-sized avatar

Wojtek Mach wojtekmach

View GitHub Profile
@wojtekmach
wojtekmach / trim.rb
Last active December 20, 2015 10:49
Removing whitespace from indented heredoc
require 'minitest/autorun'
class String
def trim
file, line_num = caller.first.split(":")
line = File.read(file).split("\n")[line_num.to_i - 1]
whitespace_num = line[/^[ ]+/].size + 2
self.gsub(/^ {#{whitespace_num}}/, '')
end
end
@wojtekmach
wojtekmach / gist:5980772
Last active December 19, 2015 15:59
crazy devops
# example.com
project "example"
role 'dev' do
package 'git'
package 'vim'
package 'tmux'
end
@wojtekmach
wojtekmach / gist:5719305
Last active December 18, 2015 03:38
DCI + "context accessor"
# DCI in Ruby
# 1. entities & values
# 2. contexts
# 3. tests
# 1. entities & values
require 'bigdecimal'
@wojtekmach
wojtekmach / gist:5719309
Last active December 18, 2015 03:38
DCI
# DCI in Ruby
# 1. entities & values
# 2. contexts
# 3. tests
# 1. entities & values
require 'bigdecimal'
@wojtekmach
wojtekmach / homepage_spec.rb
Created May 21, 2013 04:34
Transparent proxy in ruby with ProxyMachine
require 'spec_helper'
require 'capybara/rails'
Capybara.current_driver = :webkit
describe 'Homepage' do
it 'works' do
begin
pid = Process.spawn('ruby lib/proxy.rb')
@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
(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_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
require 'RMagick'
require 'capybara'
require 'launchy'
module Capybara::Recording
def start_recording
system "rm -f tmp/*"
end
def save_recording

gist.io

testing...