[rspec-users] Specing protected methods

Pat Maddox pergesu at gmail.com
Thu Oct 23 09:50:30 EDT 2008


Bastien <bastien.vaucher at gmail.com> writes:

> I totally agree with the ''listening to your specs" concepts and
> always divide my code into small methods easier to spec.
> Now let me get you right, here's my code :
>
> class Survey < ActiveRecord::Base
>   has_many :participants
>   ...
>   def generate_reports
>     ...
>     sub_total = sub_total(participants.reports)
>     ...
>   end
>
> protected
>
>  def sub_total(reports)
>     sub_total = 0
>     reports.collect do |report|
>       sub_total = sub_total + report.score
>     end
>    return sub_total
>  end
>
> end
>
> I m already specing the "generate_reports" methods with a mock on
> "sub_total"

Why are you mocking #sub_total?

Pat


More information about the rspec-users mailing list