This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'minitest', '>= 5' | |
require 'minitest/autorun' | |
module Kernel | |
def private_def method_name, &block | |
define_method method_name, &block | |
private method_name | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Encoding: UTF-8 | |
require 'socket' | |
def listening? host, port | |
TCPSocket.open(host, port)#.close | |
true | |
rescue | |
false | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MiniStub | |
def initialize *args | |
unless args.first.is_a? Hash | |
@name = args.shift | |
end | |
@stubbed = args.first || {} | |
end | |
def inspect | |
"#<MiniStub(#{@name})>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
fail NoMethodError, "foo" | |
rescue StandardError => e | |
puts "NoMethodError is rescued by StandardError: #{e.inspect}" | |
rescue NoMethodError => e | |
puts "NoMethodError is not rescued by StandardError: #{e.inspect}" | |
p e | |
end | |
puts "NoMethodError is not a StandardError" unless NoMethodError.is_a? StandardError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note minitest 2 doesn't run out of assertions so that test case would fail | |
gem 'minitest', '~> 4' | |
require 'minitest/unit' | |
require 'minitest/mock' | |
require 'minitest/autorun' | |
def do_nothing_with object | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# testfor - gen test for class | |
# | |
# USAGE | |
# | |
# Generate a test skeleton for the Person class | |
# $ testfor Person | |
require 'active_support' | |
require 'active_support/core_ext/string/inflections' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# post-checkout - git post checkout hook script | |
# | |
# This script will update the contents of .git/CURRENT_BRANCH with the name of | |
# the current branch after a checkout. | |
# | |
# Use it with rerun to restart foreman on branch changes. | |
# Bonus feature: sanity checks your Gemfile using $ bundle check | |
# | |
# Start foreman like this to watch CURRENT_BRANCH: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cross values, n = 3 | |
Array.new(n, values).inject do |acc, i| | |
acc.product(i).map(&:flatten) | |
end | |
end | |
require 'set' | |
describe do | |
it "should cross itself" do |