[rspec-users] To mock or not mock base classes

Pat Maddox pergesu at gmail.com
Tue Aug 14 23:36:54 EDT 2007


On 8/14/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:
>
> Just a general opinion question on idioms/common usage.  Is it better
> to mock Ruby's base classes, or to use real instances of those base
> classes?
>
> @string = mock String
> @string.stub!(:to_s).and_return "hello"
>
> # or:
>
> @string = "hello"
>
> I was wondering which is generally favored, and if so, for what
> reasons?  Or is it highly dependent on the type of spec which is
> being written?
>
> Regards,
>
> Scott
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>

I would say the second way is pretty clearly the favorite :)

However there might be usages where the first way could be
appropriate, but it's surely not that example.  Perhaps you could show
the actual spec you're trying to write?

Pat


More information about the rspec-users mailing list