Skip to content

Instantly share code, notes, and snippets.

@kornypoet
Created January 27, 2012 16:31
Show Gist options
  • Save kornypoet/1689638 to your computer and use it in GitHub Desktop.
Save kornypoet/1689638 to your computer and use it in GitHub Desktop.
Rspec #initialize behavior
# Arbitrary class illustrating desired implementation of init options for a class
# How do I spec this behavior? especially if there are many attrs and conditions?
class Foo
attr_accessor :bar
def initialize(bar)
# call an exiting method unless some condition is met by the variable passed in. Foo is an outward-facing class
log_and_fail unless bar
@bar = bar
end
def log_and_fail
Log.fatal "fail" ; exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment