-
Notifications
You must be signed in to change notification settings - Fork 0
An Ruby method Object#after_sending
davidmccabe/after_sending
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A convenience method. In our Rails model tests, we often had: class ThingTest < ActiveSupport::TestCase def new_thing(attributes = {}) ... thing = Thing.new(attributes) thing.valid? # Allows us to use errors method on newly-created things. thing end def some_test assert_equal ["an error message"], new_thing(:bogus => "attributes").errors[:base] end ... end Well, this part is ugly: thing = Thing.new(attributes) thing.valid? # Allows us to use errors method on newly-created things. thing We would like instead to say: Thing.new(attributes).after_sending {valid?} This is similar to the standard method Object#tap, but has a better name and better syntax. We also support this syntax, but are not sure we like it: Thing.new(attributes).after_sending.valid?
About
An Ruby method Object#after_sending
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published