[rspec-users] specs on private methods
pergesu at gmail.com
Thu Jan 10 15:36:16 EST 2008
On Jan 10, 2008 12:25 PM, Jarkko Laine <jarkko at jlaine.net> wrote:
> 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
Right, you could pull this into a MacAddress class, and use that:
describe MacAddress, " for 00-11-22-33-44-55" do
it "should normalize to 00:11:22:33:44:55" do
MacAddress.new("00-11-22-33-44-55").to_s.should == "00:11:22:33:44:55"
Then you can just do
@signup.mac_address = MacAddress.new "00-11-22-33-44-55"
and you don't really need to test that, of course, since it's just a setter.
More information about the rspec-users