Re: [Rails] Re: Mocha expectation is affecting (bleeding) from one test to another

2010-03-07 Thread James Mead
Are you sure no expectations are being set for the failing test e.g.
in a setup method?

What version of Ruby are you using? What version of Mocha are you
using. How and where are you requiring Mocha?

Can you send the test code and the code under test to the Mocha
mailing list [1] so we can try and reproduce the problem.

Thanks, James.

[1] http://groups.google.com/group/mocha-developer

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: spec testing controllers

2009-10-05 Thread James Mead

2009/10/4 Richard Schneeman :
>
> I just started using rspec and mocha to test all of my controllers.
> Before I was using factory girl to test do my testing, but all those
> database hits really take a long time. However i'm finding i'm spending
> way more time writing stubs and mocks to satisfy my controllers than I
> am actually writing tests.
>
> This is a two part general question
> 1) Am i doing something completely wrong in my controllers? I'm testing
> with integrate_views and the number of times something.stubs(:each)
> comes up way to often in my specs. Most of my controllers involve at
> least 2 normally 3 models.
>
> 2) Is there a way to auto generate stubs and mocks like factory-girl, so
> i don't have to worry about populating every last property of every last
> mock_model'd ? I can just call Mock_Factory.create(:website) and set up
> a list of defaults somewhere else?
>
>
> I feel like my stubs and mocks are supposed to help me, not confuse me:
>
> http://pastie.org/641647
>
> Your thoughts?

Hi Richard,

I haven't used it myself, but you might find this thread [1] of
interest. In particular, Murray Steele's fork [2] of factory_girl
sounds a bit like what you are looking for.

Alternatively, David Chelimsky's Stubble [3] might offer an
alternative approach, although I think that currently requires a small
patch to Mocha.

Regards, James.
http://blog.floehopper.org/

[1] http://rubyurl.com/23WA
[2] http://github.com/h-lame/factory_girl/tree/master
[3] http://github.com/dchelimsky/stubble

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: [Rspec] Using Mocha results in uninitialized constant, using a 'fix' breaks RSpec output

2009-10-02 Thread James Mead

2009/10/1 E. Litwin :
> It seems that having the test-unit gem installed causes this problem.
>
> On my Linux box, my rspec tests were all working fine for one project.
> I started testing another project that I had imported from a Windows
> development environment that referenced the test-unit gem.
>
> Installing that gem on my Linux box gave me an error when trying to
> run my rspec tests. After adding config.gem "test-unit" to test.rb,
> the tests didn't fail but didn't run anymore. The newer application
> also had the same issues.
>
> I uninstalled the test-unit gem from my Linux machine and removed the
> config.gem requirement from both the old and new applications and
> everything ran fine again.
> I also did this on my Windows machine and everything started running
> as expected.

I'm glad you've solved your problem.

However, it sounds like there might still be a problem with some
combination of Mocha, Test::Unit and RSpec (& RSpec on rails?).

It'd be great if you could create a ticket on Lighthouse [1] with
steps to reproduce the problem e.g. in a Rails app built from scratch.

Regards,

James Mead.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: [Rspec] Using Mocha results in uninitialized constant, using a 'fix' breaks RSpec output

2009-09-10 Thread James Mead

2009/9/9 Lb2007 :
> After installation of Mocha (0.9.7), running "script/spec spec"
> results in a "`const_missing': uninitialized constant
> Test::Unit::TestResult::TestResultFailureSupport (NameError)" error.
> (As shown here; http://codepad.org/mTqztjwt )
> I'm running Ruby 1.8.6 with Rails 2.3.4 on Windows, rspec (-rails)
> 1.2.8 (1.2.7.1), Test::Unit 2.0.3
>
> As suggested roughly on 
> http://stackoverflow.com/questions/1145318/getting-uninitialized-cons
> , I've added config.gem 'test-unit', :lib => 'test/unit'" to my
> environments/test.rb file at the very top. Doing so does resolve the
> trace being printed, however, no output is generated at all when
> running "script/spec spec" again. Removing the line brings back the
> trace, but logically does not resolve the issue. ( Relevant Test::Unit
> code is shown on http://codepad.org/bg7BlS7F )
>
> What other workarounds could I give a shot? Googling doesnt seem to
> bring up alternative solutions sadly.

I don't know anything about the RSpec side of things, but the thing
that changed in Mocha >= 0.9.6 was that previously Mocha had itself
loaded Test::Unit whereas now it expects you to load Test::Unit
yourself before you then load Mocha.

How are you loading Mocha? If you are loading it with a config.gem
statement after the 'test-unit' one, then this should be ok and I
would guess the problem may lie in the integration with RSpec.

Regards, James.

http://blog.floehopper.org/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Rails and Mocha problem

2009-09-06 Thread James Mead

2009/9/6 Christian Johansen 
>
> I recently set up an app on a new (old) computer, and I'm having
> problems running my tests. For some reason, mocha is not behaving at
> all. The first thing that happened was that all calls to stub
> (Mocha::API#stub) failed with a
>
> "undefined method `stub' for #".
>
> After some investigation in irb and script/console I tried to "import
> Mocha::API" in my test/test_helper.rb. That solved my initial problem,
> but brought on
>
> "/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:426:in
> `load_missing_constant': Expected
> /usr/lib/ruby/gems/1.8/gems/mocha-0.9.7/lib/mocha/integration/test_unit.rb
> to define Mocha::Integration::TestUnit (LoadError)"
>
> So, obviously something's amiss. I'm on Ubuntu. I installed Mocha
> through RubyGems 1.3.5 (manually installed, not the apt one).
>
> Any ideas on how to fix this?

Hi Christian,

I suspect this is a load order problem. After the release of 0.9.6
[1], Mocha no longer loads Test::Unit itself. Instead Mocha now needs
you to load Test::Unit *before* you load Mocha. Exactly how you solve
this depends on how you are currently loading Test::Unit and Mocha,
but usually it may simply be a matter of moving  a require 'mocha'
statement below a require 'test/unit' statement.

If you need any more help, please post to the Mocha mailing list [2].

Thanks, James.
http://blog.floehopper.org

[1] http://blog.floehopper.org/articles/2009/06/29/mocha-release-0-9-6
[2] http://groups.google.com/group/mocha-developer

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Point Me to Mocha 0.9.3

2008-11-25 Thread James Mead
I've decided to hold fire until I find out what jeremy was expecting in this
commit [1].
-- 
James.
http://blog.floehopper.org

[1]
http://github.com/rails/rails/commit/e931012287df0bca83cae04d95c2e0835ae08758

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Point Me to Mocha 0.9.3

2008-11-25 Thread James Mead
2008/11/25 http://josephholsten.com <[EMAIL PROTECTED]>

>
> I can't seem to find a copy of Mocha 0.9.3, gem or otherwise.
>
> A recent patch to ActiveSupport requires Mocha 0.9.3 support.[1] The
> Mocha home page advertises 0.9.2.[2] The current tree at github[3]
> builds into 0.9.2.[4] So–erm–where is this mysterious 0.9.3 release?
>
> I know I can make it work by building mocha head, changing the
> requirements in the tests to 0.9.2. But that defeats the point of
> automated tests, no?
>
> http://josephholsten.com
>
> [1]
> http://github.com/rails/rails/commit/e931012287df0bca83cae04d95c2e0835ae08758
> [2] http://mocha.rubyforge.org/
> [3]
> http://github.com/floehopper/mocha/tree/990a1622c962761b54152a4eea95434b47f29817
> [4]
> http://github.com/floehopper/mocha/tree/d53b6ca013d384fee70d6362e50c83200e4e46c7/Rakefile
>
>
Scary - ActiveSupport is so bleeding edge that it's relying on a "future"
release of Mocha!

I'll do a release now.

-- 
James.
http://blog.floehopper.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: rspec issues

2008-11-02 Thread James Mead
2008/11/2 [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>
> b) makes sense, though it is surprising:  I mean developer-defined
> errors are usually Exceptions, and should be caught too, no ?  I need
> to pick up my ruby book again.
>

It's a common developer mistake to derive new exception classes from
Exception, rather than StandardError. Such exception classes will not be
rescued by a default rescue clause.

-- 
James.
http://blog.floehopper.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: rspec issues

2008-10-31 Thread James Mead
Hi Elise,

2008/10/31 [EMAIL PROTECTED] <[EMAIL PROTECTED]>

> - mocking (ok, i'm using mocha, so maybe it isn't rspec):  i make a
> mailer raise an error like this:
> DummyMailer.stubs(:deliver_invitation).raises(Exception)
> and in my code, surround this with begin ... rescue, the exception is
> not caught !
>

a) Are you sure deliver_invitation is being called?
b) Are you using just a default rescue clause? This will only rescue
StandardError's and descendants of StandardError. Exception is not a
descendant of StandardError. I think Mocha raises a StandardError by
default, so if you change your stubbing as follows, a default rescue clause
will work...

  DummyMailer.stubs(:deliver_invitation).raises

If you are still seeing unexpected behaviour, come over to the Mocha mailing
list [1] and we'll see if we can help.

-- 
James.
http://blog.floehopper.org

[1] http://groups.google.com/group/mocha-developer

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---