Skip to content

Instantly share code, notes, and snippets.

View JonathonMA's full-sized avatar

Jonathon M. Abbott JonathonMA

  • Brisbane, Australia
View GitHub Profile
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define C99
struct timeval tv;
time_t curtime;
class MiniStub
def initialize *args
unless args.first.is_a? Hash
@name = args.shift
end
@stubbed = args.first || {}
end
def inspect
"#<MiniStub(#{@name})>"
@JonathonMA
JonathonMA / sanity_check.rb
Last active December 25, 2015 20:19
Check for assumed infrastructure
#!/usr/bin/env ruby
# Encoding: UTF-8
require 'socket'
def listening? host, port
TCPSocket.open(host, port)#.close
true
rescue
false
end
@JonathonMA
JonathonMA / custom_plan.rb
Created October 22, 2013 23:32
Zeus fix for rails 4 minitest double test run issue
require 'zeus/rails'
class CustomPlan < Zeus::Rails
def test_environment
require 'minitest/unit'
MiniTest::Unit.class_variable_set('@@installed_at_exit', true)
super
end
end
@JonathonMA
JonathonMA / private_def.rb
Created October 24, 2013 03:09
Why wait for ruby 2.1?
gem 'minitest', '>= 5'
require 'minitest/autorun'
module Kernel
def private_def method_name, &block
define_method method_name, &block
private method_name
end
end
require 'unicode_utils'
baffle = 'baffle'
puts baffle # => baffle
puts baffle.upcase # => BAfflE
puts UnicodeUtils.upcase(baffle) # => BAFFLE
noel = 'noël'
@JonathonMA
JonathonMA / stubs_spec.rb
Created December 12, 2013 23:27
Demonstration of why checking your stub parameters is important if you value having.
class Collaborator
# not implemented yet because TDD!
end
class ThingThatDoesThings
def initialize name
@name = name
end
def do_thing with
source 'https://rubygems.org'
gem 'fruity', '~> 0.2.0'
gem 'rubyzip', '1.1.0'
gem 'zippo', '0.2.0'
@JonathonMA
JonathonMA / i18n_fallbacks.rb
Created January 21, 2014 23:39
Rails I18n fallback experiment
require "i18n/backend/fallbacks"
I18n::Backend::Simple.send :include, I18n::Backend::Fallbacks
I18n.backend.store_translations :en, test: {
no_translations: {
specific: "en specific",
generic: "en generic",
},
only_generic_translations: {
require 'test_helper'
class MiniTestDoesntWorkWithUnenumerableRangesTest < ActiveSupport::TestCase
test ":(" do
period = Time.current - 1.week .. Time.current
mock = MiniTest::Mock.new
mock.expect :foo, true, [period]
mock.foo period