[rspec-users] stub! and null_object
dchelimsky at gmail.com
Tue Nov 4 00:24:02 EST 2008
On Mon, Nov 3, 2008 at 5:36 AM, Matt Wynne <matt at mattwynne.net> wrote:
> I have some code I want to stub out as it's not part of what I'm testing.
> It's got a bit of DSL going on, so there are method calls chained together.
> The call I want to stub out looks like this:
> user.record_action(:uploaded_a_photo => concert).with_result(photo)
> So ideally, I'd just do @user.stub!(:record_action) and that would return a
> null object that didn't care what we did to it.
stub! returns self (@user in this case), that's how it's able to chain
methods like and_return
> However, possibly due to my own ignorance, I'm having to do something a lot
> more ugly, like this:
> @user.stub!(:record_action).and_return(mock('blah',:null_object => true))
> Can anyone beautify this a bit more?
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users