Created
February 16, 2013 14:38
-
-
Save bnadlerjr/4967170 to your computer and use it in GitHub Desktop.
Basic test helper for Ruby
This file contains hidden or 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
| 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