Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Problems using Mocha plugin with Rails 3
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jack Zelig  
View profile  
 More options Oct 10 2011, 10:43 am
From: Jack Zelig <jack.ze...@googlemail.com>
Date: Mon, 10 Oct 2011 07:43:26 -0700 (PDT)
Local: Mon, Oct 10 2011 10:43 am
Subject: Problems using Mocha plugin with Rails 3
Hi,

I'm trying to use the Mocha plugin in conjunction with the Rails test
framework.

I understand that Mocha must be loaded after the test framework, but I
cannot seem to get this to happen.

I have ensured that the content of "vendor/plugins/mocha/init.rb" is
commented out and I then require Mocha in my test_helper.rb, thus:
...
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'mocha'
class ActiveSupport::TestCase
...

However, when I run my tests I get the error:
... active_support/test_case.rb:14: warning: already initialized
constant Mocha
rake aborted!

Upon further inspection, it seems that despite an empty "init.rb"
Rails is still loading Mocha before its own test framework, and this
is what is causing the error.

I believe that "vendor/plugins/mocha/lib/mocha.rb" is to blame, as
this path is also automatically loaded, too.

I've tried ensuring that Mocha isn't loaded by editing application.rb
to exclude the plugin (i.e. config.plugins =
[ :everything_except_mocha ]), but when I come to then require Mocha I
get a "No such file to load" error.

rails: 3.0.3
ruby: 1.9.2
mocha: 0.10.0

Can someone give me a clue as to how I can get the Mocha plugin
working with Rails 3?

Thanks very much in advance!

Jack

P.S. I tried installing the Mocha gem and that works great. The only
problem is that for this project the client has an aversion to gems or
anything else he must install on his machine (genuinely!!)
He still however wants to be able to run the tests himself.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Fernando Guillen  
View profile  
 More options Oct 10 2011, 1:12 pm
From: Fernando Guillen <fguillen.m...@gmail.com>
Date: Mon, 10 Oct 2011 19:12:11 +0200
Local: Mon, Oct 10 2011 1:12 pm
Subject: Re: Problems using Mocha plugin with Rails 3

On Mon, Oct 10, 2011 at 4:43 PM, Jack Zelig <jack.ze...@googlemail.com> wrote:
> However, when I run my tests I get the error:
> ... active_support/test_case.rb:14: warning: already initialized
> constant Mocha
> rake aborted!

How are you declaring the 'mocha' gem in the Gemfile?

Have you remembered to use ':require => false' ?

group :test do
  gem 'mocha', :require => false
end

f.

--
Fernando Guillén
Freelance Web Developer
http://www.fernandoguillen.info
http://spainrb.org/fernando-guillen


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jack Zelig  
View profile  
 More options Oct 10 2011, 2:47 pm
From: Jack Zelig <jack.ze...@googlemail.com>
Date: Mon, 10 Oct 2011 20:47:37 +0200
Local: Mon, Oct 10 2011 2:47 pm
Subject: Re: Problems using Mocha plugin with Rails 3
On 10.10.2011 19:12, Fernando Guillen wrote:
>> >  However, when I run my tests I get the error:
>> >  ... active_support/test_case.rb:14: warning: already initialized
>> >  constant Mocha
>> >  rake aborted!
> How are you declaring the 'mocha' gem in the Gemfile?

> Have you remembered to use ':require =>  false' ?

> group :test do
>    gem 'mocha', :require =>  false
> end

I'm trying to get Mocha to work as a plugin, without it being installed
on my machine as a gem.
Do I have to declare plugins in the gem file?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Mead  
View profile  
 More options Oct 10 2011, 3:57 pm
From: James Mead <floehop...@gmail.com>
Date: Mon, 10 Oct 2011 20:57:50 +0100
Local: Mon, Oct 10 2011 3:57 pm
Subject: Re: Problems using Mocha plugin with Rails 3
Hi Jack,

I haven't tried using Mocha as a plugin for ages.

Is there a particular reason you want to use it as a plugin rather than a gem?

I'll have a quick look into why it might not be working.

Cheers, James.
----
http://jamesmead.org/

On 10 Oct 2011, at 15:43, Jack Zelig wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jack Zelig  
View profile  
 More options Oct 11 2011, 3:56 am
From: Jack Zelig <jack.ze...@googlemail.com>
Date: Tue, 11 Oct 2011 09:56:48 +0200
Local: Tues, Oct 11 2011 3:56 am
Subject: Re: Problems using Mocha plugin with Rails 3
Hi James,

Thanks for the reply.
The bloke I am working for at the moment doesn't want me to use any gems
on the project.
He cites a reluctance to be dependent on 3rd party code as a reason.
He will however sanction the use of plugins as they are somewhat more
'contained', i.e. local to the project as opposed to being accessible
system-wide.
As you can imagine, this doesn't make my life easier, but c'est la vie!

Anyway, I would be really grateful if you could look into this for me.
As I wrote, it seems that Rails is loading
vendor/plugins/mocha/lib/mocha.rb before its own test framework.

Thanks very much for your help
Jack

On 10/10/11 21:57, James Mead wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Mead  
View profile  
 More options Oct 11 2011, 4:23 am
From: James Mead <floehop...@gmail.com>
Date: Tue, 11 Oct 2011 09:23:45 +0100
Local: Tues, Oct 11 2011 4:23 am
Subject: Re: Problems using Mocha plugin with Rails 3
Hi Jack,

In Rails 3, I can't think of any advantage of using Mocha as a plugin rather than a gem. To avoid a dependency on system-wide gems (an understandable requirement), I think the best solution is to use Bundler and specify a path local to the project e.g. `bundle install --path vendor/bundle`. This will keep gems for the project installed separately from system-wide gems and subsequent calls to Bundler commands will remember the chosen path. See [1].

I hope this helps. I'll try to find some time to investigate whether Mocha can still work as a plugin, but I'm pretty busy at the moment and to be honest it's not going to be a high priority.

Regards, James.

[1] http://gembundler.com/bundle_install.html

On 11 Oct 2011, at 08:56, Jack Zelig wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jack Zelig  
View profile  
 More options Oct 11 2011, 4:53 am
From: Jack Zelig <jack.ze...@googlemail.com>
Date: Tue, 11 Oct 2011 10:53:34 +0200
Local: Tues, Oct 11 2011 4:53 am
Subject: Re: Problems using Mocha plugin with Rails 3
Hi James,
Thanks for the link. I have just been reading through it. However, it
seems to me that running

`bundle install --path vendor/bundle`

will install all of the projects gems to vendor/bundle.
I'll have to keep on reading/researching to see if there is a way to
install only one gem to the vendor folder, using bundler.

Thanks for your help so far.
I would still be grateful if you let me know if you manage to make Mocha
work as a plugin.

Cheers,
Jack

On 11/10/11 10:23, James Mead wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl Tanner  
View profile  
 More options Oct 11 2011, 12:38 pm
From: Carl Tanner <rocketeer.captpro...@gmail.com>
Date: Tue, 11 Oct 2011 09:38:55 -0700
Local: Tues, Oct 11 2011 12:38 pm
Subject: Re: Problems using Mocha plugin with Rails 3
If you use bundler and rvm, the gem will not be system wide, but they will just apply to the project. On the other hand, more difficulty mean more work, means , more money.

Carl
@captproton

On Oct 11, 2011, at 0:56, Jack Zelig <jack.ze...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Mead  
View profile  
 More options Oct 11 2011, 1:53 pm
From: James Mead <floehop...@gmail.com>
Date: Tue, 11 Oct 2011 18:53:20 +0100
Local: Tues, Oct 11 2011 1:53 pm
Subject: Re: Problems using Mocha plugin with Rails 3
On 11 Oct 2011, at 09:53, Jack Zelig wrote:

> Thanks for the link. I have just been reading through it. However, it seems to me that running

> `bundle install --path vendor/bundle`

> will install all of the projects gems to vendor/bundle.

You are correct. It will indeed install *all* of the project's gems to the specified directory, but since the bloke you are working for doesn't want to rely on "system-wide" gems, I thought it would be preferable to install all of them locally within the project. Since it sounds like you have other gems in the Gemfile, why is it  ok for them to be "system-wide"? What is so special about Mocha that is must not be "system-wide" when other gems can be?

I may be missing something, but it seems to me that the bloke you are working for is being a bit unreasonable.

> I'll have to keep on reading/researching to see if there is a way to install only one gem to the vendor folder, using bundler.

I don't think there is a way to do that - at least not in a way that would be at all simple.

> Thanks for your help so far.
> I would still be grateful if you let me know if you manage to make Mocha work as a plugin.

I'll try to find some time to look into this, but if it turns out it's difficult to make it work, I think I'm more likely to withdraw the ability to use Mocha as a plugin, since I don't see that there are any real advantages versus using it as a gem.

Cheers, James.
----
http://jamesmead.org/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Mead  
View profile  
 More options Oct 11 2011, 1:55 pm
From: James Mead <floehop...@gmail.com>
Date: Tue, 11 Oct 2011 18:55:08 +0100
Local: Tues, Oct 11 2011 1:55 pm
Subject: Re: Problems using Mocha plugin with Rails 3
On 11 Oct 2011, at 17:38, Carl Tanner wrote:

> If you use bundler and rvm, the gem will not be system wide, but they will just apply to the project. On the other hand, more difficulty mean more work, means , more money.

> Carl
> @captproton

I think using RVM is a red herring. You could use an RVM gemset, but to my mind using Bundler with a local path for gems is a simpler solution. Especially when you start to think about deploying the app.

Cheers, James.
----
http://jamesmead.org/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jack Zelig  
View profile  
 More options Oct 12 2011, 4:33 am
From: Jack Zelig <jack.ze...@googlemail.com>
Date: Wed, 12 Oct 2011 10:33:19 +0200
Local: Wed, Oct 12 2011 4:33 am
Subject: Re: Problems using Mocha plugin with Rails 3

> I may be missing something, but it seems to me that the bloke you are working for is being a bit unreasonable.

No, you're not missing anything. :-)

> I'll try to find some time to look into this, but if it turns out it's difficult to make it work, I think I'm more likely to withdraw the ability to use Mocha as a plugin, since I don't see that there are any real advantages versus using it as a gem.

I appreciate that. Even a "Sorry, it doesn't work as a plugin" would
help, as then I would have a case for being able to use it as a gem
after all.

Other than that, I have installed Mocha as a gem and am enjoying using it.
Thanks for a great tool!

Jack


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »