Skip to content

Instantly share code, notes, and snippets.

@bnadlerjr
Created February 16, 2013 14:38
Show Gist options
  • Select an option

  • Save bnadlerjr/4967170 to your computer and use it in GitHub Desktop.

Select an option

Save bnadlerjr/4967170 to your computer and use it in GitHub Desktop.
Basic test helper for Ruby
ENV['RACK_ENV'] = 'test'
require 'bundler/setup'
require 'simplecov'
SimpleCov.start do
add_filter "/test/"
end
require 'test/unit'
require 'contest'
require 'mocha/setup'
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
class Test::Unit::TestCase
# Syntactic sugar for defining a memoized helper method.
def self.let(name, &block)
ivar = "@#{name}"
self.class_eval do
define_method(name) do
if instance_variable_defined?(ivar)
instance_variable_get(ivar)
else
value = self.instance_eval(&block)
instance_variable_set(ivar, value)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment