No, I’m not testing my attr_* methods. They are an implementation detail at not an expression of behavior.
bryanl —
I don’t know enough rspec to convert it myself, but model.instance_methods.should include(field.to_s) is slow code. You should use method_defined? instead of instance_methods.include? (I’d assume: model.should method_defined(field))
apeiros —
And on another note: while I do test my attr_* methods, I don’t particularly care that those methods have been defined as attr_*, they’re just methods. So I don’t treat them differently.
apeiros —
@bryanl attr_*, by creating methods, creates behavior in your class. and if you don’t test them, then someone may be able to delete them from your code, breaking your app, yet still causing your tests to pass.
moonmaster9000 —
@apeiros thanks for pointing our method_defined?. as for your comment about attr_* methods not being different from any other method. you’re right. but if i need to test those methods and they don’t do anything “special” like caching or validating the input, i really don’t see the point of writing the same specs over and over.
rubiii —
@rubiii you’re welcome. The second comment was more geared towards bryanl. Though you could beef up attr_accessor by testing the following:
Comments
No, I’m not testing my attr_* methods. They are an implementation detail at not an expression of behavior.
I don’t know enough rspec to convert it myself, but
model.instance_methods.should include(field.to_s)
is slow code. You should use method_defined? instead of instance_methods.include? (I’d assume:model.should method_defined(field)
)And on another note: while I do test my attr_* methods, I don’t particularly care that those methods have been defined as attr_*, they’re just methods. So I don’t treat them differently.
@bryanl attr_*, by creating methods, creates behavior in your class. and if you don’t test them, then someone may be able to delete them from your code, breaking your app, yet still causing your tests to pass.
@apeiros thanks for pointing our method_defined?. as for your comment about attr_* methods not being different from any other method. you’re right. but if i need to test those methods and they don’t do anything “special” like caching or validating the input, i really don’t see the point of writing the same specs over and over.
@rubiii you’re welcome. The second comment was more geared towards bryanl. Though you could beef up attr_accessor by testing the following:
Argh, that should have been
x.foo.should be(random_value)
, of course :-(No. Don’t test those!
Test them indirectly if you can, but make sure they are tested somehow!
Post a comment