Skip to content

Instantly share code, notes, and snippets.

@bnadlerjr
Created January 12, 2013 16:50
Show Gist options
  • Select an option

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

Select an option

Save bnadlerjr/4519190 to your computer and use it in GitHub Desktop.
class EmployeeTest < Test::Unit::TestCase
let(:email) { Employee.new('[email protected]') }
def employee_has_an_email_test
assert_equal('[email protected]', employee.email)
end
end
class EmployeeTest < Test::Unit::TestCase
def employee_has_an_email_test
assert_equal('[email protected]', employee.email)
end
private
def employee
@employee ||= Employee.new('[email protected]')
end
end
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