No, I'm not testing my attr_* methods. They are an implementation detail at not an expression of behavior.bryanl - January 24, 2010 14:27
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 - January 24, 2010 14:33
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 - January 24, 2010 14:34
@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 - January 24, 2010 14:36
@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 - January 24, 2010 14:43
@rubiii you're welcome. The second comment was more geared towards bryanl. Though you *could* beef up attr_accessor by testing the following:
random_value = generate_some_random_value
x.foo = random_value
x.should be(random_value)apeiros - January 24, 2010 14:59
Argh, that should have been `x.foo.should be(random_value)`, of course :-(apeiros - January 24, 2010 14:59
No. Don't test those!Hubert Łępicki - January 25, 2010 19:15
Test them indirectly if you can, but make sure they are tested somehow!rubiii - February 04, 2010 23:11
Comments