[rspec-users] specs on private methods
jarkko at jlaine.net
Thu Jan 10 15:25:31 EST 2008
On 10.1.2008, at 22.21, Francois Wurmus wrote:
> Apart from private or public methods I see a problem in your test
> You don't make sure that your mac_address is returned in exactly the
> you want - you are merely saying it should look like the return
> value of
> some (protected) method you call (normalize_mac).
> Let's assume this method was implemented wrong and just returns nil.
> Let's further assume that @signup.mac_address calls a reader method
> returning nil, too. Such an implementation, though wrong, would
> your spec!
> A second problem is, that the parameter you are passing to the
> normalize-method will already have been transformed before your method
> gets its hands on it. You are not passing the init value but the value
> that is returned be a read operation on the mac_address field.
> What you really should specify is your concrete mac address format:
> it "should return a valid mac address" do
> @signup.mac_address = "00-11-22-33-44-55"
> @signup.mac_address.should == "00:11:22:33:44:55"
> Now you are not only implementation independent but your spec is also
> saying more.
Also, this line of code is a bit smelly:
>> normalized = @signup.normalize_mac(@signup.mac_address)
Since normalize_mac is an instance method in the Signup class, there's
no point passing the mac_address as a parameter; the method can simply
call the mac_address method directly. If you want to make it more
general-purpose, it doesn't sound like it should be an instance method
More information about the rspec-users