-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
33 lines (22 loc) · 878 Bytes
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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?