I reread Practical Object Oriented Programming in Ruby by using a chapter on special testing by Sandy Mets. It is also a very useful thing that I advise the Rubyists:
She says that test these cases:
-
Incoming Cuba Message:
-
Incoming command messages: Check directly the public side effect (I have a question about this) <
-
Outgoing query messages: they are not checked
-
Outgoing command messages: They are sent to test
< For # 2, he has given an example like this:
# square square gear attr_reader: cog def set_cog (cog) @ cog = cog end end # example spec "COD" Gear = Gear.New Gear.Set_Cog (1) Expectation (GearDog). AEC (1) end
Then it is simple because it is only the example variable so that the side effect is clear. But what if my method calls another order message? For example:
class gear attr_reader: cog ,: foo ,: bar def set_cog (cog) reset_other_attributes @cog = cog end def reset_opar_attoins @fu = nil @ bar = zero end end
How should I test this? I am thinking that it should behave like an outgoing command message, where you should say that the message has been sent and there is a separate examination for the reset_other_attributes
method.
This calls the "reset_other_attributes method" gear = gear. New gear Should_receive (: reset_other_attributes) gear.set_cog (1) end
Is that correct?
This method is difficult to test, its real reason is that it violates SRP theory It is more determined than the value of the cog.
However, in this case I will test that the expected changes will take effect, it does not seem appropriate to test that the "reset_other_attributes" method is called. From this snap, it seems that "reset_other_attributes" should not also be a part of the public API.
Comments
Post a Comment