Created
January 12, 2013 16:50
-
-
Save bnadlerjr/4519190 to your computer and use it in GitHub Desktop.
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
| 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 |
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
| 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 |
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
| 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