Skip to content

Instantly share code, notes, and snippets.

View luislavena's full-sized avatar

Luis Lavena luislavena

View GitHub Profile
@ordinaryzelig
ordinaryzelig / minitest_spec_expectations.md
Last active June 4, 2025 17:59
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
diff --git a/Makefile.in b/Makefile.in
index a3040b6..e3c5d05 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -12,6 +12,7 @@ NULL = /dev/null
srcdir = @srcdir@
top_srcdir = $(srcdir)
hdrdir = $(srcdir)/include
+PLATFORM_DIR = win32
@shirosaki
shirosaki / file_access.patch
Created December 5, 2011 09:39
tma sample
diff --git a/samples/file_access.cpp b/samples/file_access.cpp
new file mode 100644
index 0000000..1ea02e3
--- /dev/null
+++ b/samples/file_access.cpp
@@ -0,0 +1,108 @@
+#include <ios>
+#include <iostream>
+#include <ostream>
+#include <iomanip>
ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]
rails 3.1.1
C:\>rails new empty-187 -d sqlite3
C:\empty-187>timer ruby script\rails runner "puts $LOADED_FEATURES.size"
705
real 4.538
system 2.667
user 1.794
require 'minitest/autorun'
class Subject < Struct.new(:lol)
def render_controls
lol.button_to 'Vote'
end
end
describe 'lolwot' do
it "should generate a button" do
require "benchmark"
TESTS = 10_000
puts "File.expand_path: #{TESTS} times."
Benchmark.bmbm do |results|
results.report("Ruby '':") { TESTS.times { File.expand_path('') } }
results.report("Ruby '.':") { TESTS.times { File.expand_path('.') } }
@foca
foca / value_object.rb
Created July 30, 2011 02:14
Extremely lightweight "Struct" that only defines attribute readers
module ValueObject
def self.new(*attrs)
klass = Class.new(Object)
klass.send(:attr_reader, *attrs)
klass.send(:define_method, :initialize) do |*args|
raise ArgumentError, "wrong number of arguments (#{args.size} for #{attrs.size})" unless args.size == attrs.size
attrs.each_with_index do |attr, idx|
instance_variable_set("@#{attr}", args[idx])
@stereobooster
stereobooster / test_env_path.rb
Created July 16, 2011 23:49
Information about environment path
executables = {}
total = 0
path_extensions = ENV["PATHEXT"].gsub(".", "").downcase.split(File::PATH_SEPARATOR)
path = ENV["Path"]
path.split(File::PATH_SEPARATOR).each do |value|
dir = Pathname.new(value)
if dir.exist? then
filter = File.join(dir.realpath, "*.{" + path_extensions.join(",") + "}")
Dir.glob(filter).each do |file|
@karmi
karmi / geo_distance_filter_in_tire.rb
Created June 28, 2011 14:13
Geo Distance Filter Support in Tire/ElasticSearch
require 'tire'
require 'active_support/core_ext/numeric'
require 'active_support/core_ext/time/zones'
# Tire.configure { logger STDERR, level: 'debug' }
class Time; DATE_FORMATS.update lucene: "%Y-%m-%dT%H:%M"; end
Tire.index 'venues' do
@kdonovan
kdonovan / apn_sender
Created June 17, 2011 01:04
Contents of the file apn_sender's generator puts in script/apn_sender (for those on Rails 3, where the generator isn't working yet)
#!/usr/bin/env ruby
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'apn'
require 'apn/sender_daemon'
APN::SenderDaemon.new(ARGV).daemonize