Stubbing a call path with Mocha

written December 23 2008 by
{ Kommen }
Comments 0

Stubbing named_scope calls can be a real nightmare. If you use Rails’ named scopes as often as I do, you probably know this.
Imagine this code in a controller:

1 user = @account.users.activated.find_by_email

Using off-the-shelf Mocha you would stub it with something like the following:

1 @account.stubs('users').returns(mock('users', :activated => mock('activated', :find_by_email => users(:kommen))))

This doesn’t fit my coding style though. So lets fix this.

With this little monkey patch extracted from freckle you can now do this:

1 @account.stub_path("users.activated.find_by_email").returns(users(:kommen))

Now we can talk.

Switching to Firefox Beta 5

written April 7 2008 by
{ Kommen }
Comments 4

I just switched my default browser to Firefox Beta 5 from WebKit nightly. I’ve already used the previous 2 betas and was pretty impressed by it’s speed, the new location bar and the new password saving mechanism. So I give it a try as my default browser.

My must-have plugins, which currently make FF3 win over Safari3 are:

Though there are some interface issues, none of them is currently a blocker for me.

You've reached the end of this page. Feel free to dig into the archives of this blog or subscribe to our newsfeed.