Displaying 20 results from an estimated 2000 matches similar to: "how to ensure signature compliance while mocking in ruby"
2007 Feb 05
10
how does Mocha compare in terms of classical vs mock-based testing, and stubbing???
Hi guys,
I''ve just been reading Martin Fowler''s article re mock versus
stubbing<http://martinfowler.com/articles/mocksArentStubs.html>where
he compares traditional TDD testing techniques with mock based
testing. I''d be interested in comments from a ruby on rails perspective in
terms of this and Mocha? For example:
a) Do you see Mocha as a robust way to test Ruby
2007 Mar 06
15
mocking missing methods
Hi folks.
So I''m using mocha on a ruby project, and I really like it. One thing
I''ve noticed is that it can be a bit "surprising" when I''m mocking
methods that don''t exist on an object, and I think there''s an easyish fix.
At the moment, you use sheep = mock() to create a mock sheep. What I''d
like to do is something like sheep =
2006 Nov 21
5
stubbing in development environment
Hi guys.
Quite happy with mocha for testing. It''s been a bit of an eye opener
for me, and I expect to begin using it heavily.
One other thing I''d like to do is stub out particular class methods in
development. Is there a way I can do this with mocha?
Jason
2007 Jul 16
4
RSpec - concerns about mocking
I''m getting into RSpec more after getting the awesome Peepcode
screencast about it. So far I love it, but coming form Test::Unit with
Rails, I have some concerns about the recommendation to mock models and
database calls in controller and view specs.
Lets say you have a method on your User model called
User.find_activated, and you have models specs for it. Then in your
controller specs
2007 Mar 18
5
Automatically mocking ActiveRecord methods
Seems like I do a fair amount of mocking ActiveRecord''s automatically
generated routines when I''m testing controllers. Things like:
@portalspace = PortalSpace.new :public_readable => true,
:public_writable => true, :name => ''public''
@portalspace.stubs(:id).returns(203)
PortalSpace.stubs(:find).with(203).returns(@portalspace)
2007 Mar 12
10
using mocha with rspec
Hi folks.
I''ve just started using rspec and I have to say it''s very nice. The
thing is, I prefer mocha''s mocking dialect. So I thought a simple
require ''mocha'' would set me up.
Unfortunately, rspec does all its goodness using do/end blocks in
anonymous classes, so it wasn''t quite that obvious.
Anyway, here is the incantation I ended up
2006 Oct 25
5
Mocha, Stubba and RSpec
Hi,
I''ve been reading with interest the threads trying to integrate Mocha
and Stubba with RSpec. So far, I''ve made the two changes in
spec_helper.rb suggested, but discovered another one that neither of
the archives mentions:
If you use traditional mocking: object = mock or the stub shortcut
: object = stub(:method => :result), you run into namespace conflicts
with
2007 Aug 31
48
Deprecating the mocking framework?
I saw in one of Dave C.''s comments to a ticket that "our current plan
is to deprecate the mocking framework." I hadn''t heard anything about
that, but then again I haven''t paid super close attention to the list.
Are we planning on dumping the mock framework in favor of using Mocha
(or any other framework one might want to plug in?).
Pat
2007 Jun 15
0
Fwd: [ mocha-Patches-11583 ] Mocha 0.5.0 throwing unexpected warnings, one line patch included
Begin forwarded message:
> From: <noreply at rubyforge.org>
> Date: 15 June 2007 10:44:07 BDT
> To: noreply at rubyforge.org
> Subject: [ mocha-Patches-11583 ] Mocha 0.5.0 throwing unexpected
> warnings, one line patch included
>
> Patches item #11583, was opened at 2007-06-14 21:28
> You can respond by visiting:
> http://rubyforge.org/tracker/?
>
2007 Aug 21
7
mocking singletons
How can I safely mock a singleton without the mocked method living on
outside the scope of the test method?
I''ve run into this problem with mocking methods on globals (gasp!) in
the past by doing something like
def mock_my_global
original = $my_global
$my_global.expects(:foo).returns(''bar'')
yield
$my_global = original
end
Is there something similar I
2007 May 02
4
Terse Mocks
Hello,
I recently made a feature request with a patch for terser mocks.
http://rubyforge.org/tracker/index.php?func=detail&aid=10412&group_id=1917&atid=7480
Here are some examples with their current equivalents:
the_mock.expects.foo(1,2) {|a, b| :bar}
the_mock.expects.foo(1,2).returns(:bar)
the_mock.expects(:foo).with(1,2) {|a, b| :bar}
the_mock.expects(:foo).with(1,2).returns(:bar)
2008 May 10
1
Mocking protected/private methods
Hello all,
I have a question concerning mocha''s handling
of protected and private methods. When expecting
such a method, the method is public in the test.
I expected the method to keep its original visibilty.
Is this intended behaviour, or a bug?
Thanks for your help,
Tammo Freese
2007 Jun 11
12
Mocking system/`
This drives me insane on a regular basis. How does one mock
system(''blah'') or `blah` ?
Adding expectations on Kernel doesn''t do it. Adding expectations on
Object just makes me sad:
Object.any_instance.expects(:system).with(''ls'')
# => #<Mock:0x12b584e>.system(''ls'') - expected calls: 0, actual calls: 1
And this really
2007 Nov 04
3
Returning the mock associated with an expectation.
I was reading through the FlexMock docs and noticed the expectation
method .mock, which returns the original mock associated with an
expectation.
It looks really handy for writing nice all-in-one mocks like:
mock_user = mock(''User'').expects(:first_name).returns(''Jonah'').mock
So I started playing around with mocha and found I could actually
already do this!
2007 Sep 06
1
any reason we can''t use the concise stubs on Object
I like the concise version of stubs available on true mocks:
=> #<Mock:0x32f76d4>
>> foo.stubs(:one => ''hi'', :two => ''again'')
=> {:one=>"hi", :two=>"again"}
Why can''t we do it on ''real'' objects?
>> foo = Object.new
>> foo.stubs(:method1 => ''a'',
2006 Sep 11
4
Using rspec and mocha
I prefer to use rspec than test::unit for developing my apps. However
I''ve found its mocking library to be pretty inflexible compared to
Mocha. This isn''t really a surprise since rspec isn''t intended as a
mocking framework, whereas Mocha is. So I''d like to play to both of
their strengths and use rspec as my testing/specification framework
and Mocha do to
2006 Sep 11
4
Using rspec and mocha
I prefer to use rspec than test::unit for developing my apps. However
I''ve found its mocking library to be pretty inflexible compared to
Mocha. This isn''t really a surprise since rspec isn''t intended as a
mocking framework, whereas Mocha is. So I''d like to play to both of
their strengths and use rspec as my testing/specification framework
and Mocha do to
2006 Oct 06
8
Expecting calls with two different parameters
Hello,
I''ve just started using Mocha in the tests for my Rails app, and I''ve
run across an issue with mocking a method that should be called with
different parameters.
How would I setup a mock that expects that a method will be called
once with no paramaters, and a second time with a parameter? I''d be
tempted to shortcut and just do something like
2007 Sep 24
7
Parameter Matchers with optional params
Hi,
Are there any docs for combining parameter matchers, or some way to
define optional parameters? I''m trying to match something like:
.find( 42 ) || .find( 42, {:conditions=>nil,:includes=>nil} )
Or for that matter, 42 followed by nothing or anything... Halp? I''ve
tried different nested combos with any_of/all_of/anything, but
getting lost trying.
--Andrew
2006 Sep 03
2
Fwd: Dealing with exec?
---------- Forwarded message ----------
From: Kevin Clark <kevin.clark at gmail.com>
Date: 01-Sep-2006 20:31
Subject: Dealing with exec?
To: James Mead <jamesmead44 at gmail.com>
Hey James,
Sorry to bug you. I was curious how you''d handle a call to exec in a
method you were testing. Kernel.stubs(:exec)... doesn''t seem to work
but I''m not sure where else an