Rspec_scaffold and mocha

Hi all,

Sorry if this get’s posted several times but I got a message that my
previous post wasn’t allowed because I’m not a member. I think I am
now though.

The problem I have is fairly simple. I have some plugins who use rspec
and mocha and I want to make use of the rspec_scaffold generator.
Unfortunately this doesn’t work, the tests fail as soon as I set mocha
as my prefered mocking framework.

Is this by design or should it work out of the box.

If anybody knows about a generator that does work, please let me know

All the best!

On Thu, May 7, 2009 at 1:21 PM, jevado [email protected] wrote:

As far as I can tell, Nifty_Generators nifty_scaffold ( generates rspec +
mocha scaffolding. I wasn’t using Mocha so I didn’t look in detail.

e.g. here is a controller spec generated with nifty_scaffold for some
work I
was doing with the authlogic plugin:

describe UserSessionsController do
fixtures :all

it “new action should render new template” do
get :new
response.should render_template(:new)

it “create action should render new template when model is invalid” do
post :create
response.should render_template(:new)

it “create action should redirect when model is valid” do
post :create
response.should redirect_to(root_url)

it “destroy action should destroy model and redirect to index action”
user_session = UserSession.first
delete :destroy, :id => user_session
response.should redirect_to(root_url)
UserSession.exists?( be_false

Wow, thanks for all the replies …

The rspec scaffold generates more tests than the nifty_scaffold. I
didn’t look into it in detail yet cause some of the nifty tests where
failing too.

What I did to get it workin is map the missing methods (used by
respec) to methods in mocha. I also use the mislav-rspec-rails-mocha


module Mocha
class Expectation

def and_return(*values)


On May 11, 3:17 am, Nicholas Van W. [email protected]

post wasn’t finished yet …

I know that it’s not very clean but since it’s just for scaffolding
and I’ll probably rewrite most of the tests later on anyway it’s
acceptable for now.

Thanks again and I’ll monitor the GSOC project :slight_smile:

Kind regards,

On May 11, 3:17 am, Nicholas Van W. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs