[rspec-users] specs on private methods

Francois Wurmus francois.wurmus at infopark.de
Thu Jan 10 15:34:52 EST 2008


Even my suggestion wouldn't be a sufficient spec. What about completely 
wrong mac addresses? Empty addresses, too many characters, invalid 
characters?

It is not for nothing that the rspec test cases are called examples - 
you may define any number of example inputs and expected outputs that 
are required to describe the behavior of the object to be specified.



barsalou schrieb:
> It's interesting that this thread has started because I just ran into 
> this problem.
> 
> The error I got was:
> 
> NoMethodError in 'Signup she be a valid mac address'
> protected method `normalize_mac' called for #<Signup:0x408c0434>
> ./spec/models/signup_spec.rb:10:
> 
> 
> Here's the spec:
> 
> describe Signup do
>   before(:each) do
>     @signup = Signup.new
>   end
> 
>   it "she be a valid mac address" do
>      @signup.mac_address = "00-11-22-33-44-55-66"
>      normalized = @signup.normalize_mac(@signup.mac_address)
>      @signup.mac_address.should == normalized
>   end
> end
> 
> 
> I have a model that has mac_address attribute.  In the before 
> validation, I wanted to make the mac address have colons(:) instead of 
> whatever the user typed in which could have spaces between, dashes, 
> nothing at all.
> 
> My thought was to just remove all of those special characters validate 
> it against a regex then if it passed the regex check produce the mac 
> address with the colons included.
> 
> And, if I understand it properly, Pat's statement is saying that I 
> really shouldn't be protecting that method...which would fix my problem.
> 
> So my question is then, how do you know when to use protected and 
> private or do I just do what Rick suggested and use send?
> 
> I just realized this isn't really an rspec question...so I'll just move along.
> 
> Mike B.
> 
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> 
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
> 
> 


More information about the rspec-users mailing list