[rspec-users] Stub that returns hash values

Pat Maddox pat.maddox at gmail.com
Wed Oct 21 03:41:54 EDT 2009


wait why do you want to do this??  Just use a regular hash and do
state-based assertions on it.  Or determine the role that this
hash-like thing is doing, and use a mock to define a proper interface.
 Ashley's solution works but I am very skeptical that the approach is
a good one.  Can you post some code?

Pat

On Tue, Oct 20, 2009 at 9:36 AM, Carl Graff <carl.graff at cox.net> wrote:
> Is it possible to create a stub that returns hash values.
>
> For example I would like to convert this:
>  @siteItem = stub('plmSiteItem', :one => "uno")
>
> To something like this:
>  @siteItem = stub('plmSiteItem', {'one' => 'uno', 'two' => 'dos'} )
>
> So that I can do this:
>   @siteItem['one'] should == 'uno'
>   @siteItem['two'] should == 'dos'
>
>
> Actually I first tried to use method double instead of stub - even though I
> still don't know when each is preferred - but double raised a missing method
> error for some reason.
>
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list