Displaying 20 results from an estimated 9000 matches similar to: "Expect with "real world" returns?"
2007 Jul 26
5
Test errors without verification
I''m not sure if this is by design, but I''ve stumbled across this a
few times trying to debug my own tests. If an assertion fails the
test, and a mock expectation was to blame, the test''s failure / error
messages don''t give enough info. I''ve had to resort to
def teardown
mocha_verify
end
which just gets tedious.
I''ve created a patch
2008 Jan 02
2
Proxies
I really like the idea of Mock Proxies as explained in Brian Takita''s post here:
http://pivots.pivotallabs.com/users/brian/blog/articles/352-introducing-rr
I posted to this list eariler with an incomplete implementation of
.stops_mocking in the thread "Mocking Time, delegating to original
object." The Mock Proxy pattern would make this simpler.
2007 Sep 05
4
Mocking to spec a sort_by method
Hello,
I have a question regarding the use of Mocha with rSpec to spec one of
my methods.
My spec contains the following
vehical1 = mock()
vehical2 = mock()
vehical1.stubs(:mph).returns(150)
vehical2.stubs(:mph).returns(250)
comparer.add_vehical([@vehical1, @vehical2])
comparer.sort_by(:mph)
The comparer is an object that has a basic "stack like" functionality,
add_vehical is the
2006 Oct 13
6
If I stub do I have to mock as well?
Hi, I''m new to mocha and stubba but eager to learn. I have a rails
functional test in which I would like to stub an instance method of
particular class to always return true. I tried the following:
def test_post_checkout
Order.any_instance.stubs(:successful?).returns(true)
post :checkout
assert_response :redirect
assert_equal "Checkout was successful.",
2007 Jun 12
2
replacement for returning Proc
Can somebody help me understand the new syntax for replacing a return
statement that returns a Proc? I''m having difficulty understanding
what is meant by:
"Use explicit multiple return values and/or multiple expectations
instead." source: http://mocha.rubyforge.org/classes/Mocha/
Expectation.html#M000024
Here is a simple example of what I am doing: http://
2007 Mar 30
7
problem with using any_instance
Hey all,
I have a question with using mocha in my tests.
In the same test file, I have two tests,
<code>
def test_a
klass.any_instance.stubs(:method_name).returns("something")
klass.new.method_name
...
end
def test_b
...
klass.new.method_name
...
end
</code>
where klass is some class
when the tests run, test _a passes, but test_b had an error like this:
2007 Oct 20
14
Problems with form_for and partials
i''m having problem with a form_for situation where i''m trying to DRY
out the repeated parts of my forms and put them in common/form and
render the form elements via another partial in controller_name/_form.
Here''s the first form
# app/views/common/form
<% form_for ... do |f| -%>
<%= render :partial => "params[:controller]/form", :object => f
2006 Sep 22
2
foo.expects(:blah).returns(10).then(11) syntax
I recently needed the behavior of my object to change on subsequent
method calls so I added the syntax above.
Here''s the diff of changes I made:
Index: test/mocha/expectation_test.rb
===================================================================
--- test/mocha/expectation_test.rb (revision 854)
+++ test/mocha/expectation_test.rb (working copy)
@@ -95,6 +95,12 @@
2006 Dec 02
3
Scoping expectations and more ...
Hello!
I''m new to Mocha and through experimentation I found out something
that is not explicitly stated in the documentation: If you need to
mock the same function call with different parameters and results, you
can set the scope of expectations with a begin ... end block.
I also made up an example on how to expect more than one function call
with different parameters and return values.
2006 Aug 15
7
Trying to Overide Class Object Methdos For Testing
Hi,
I thought I had a handle on the whole singleton class thing but now I''m
not too sure.
I have a class definition:
class ValidationMaster
def validate(params)
# complex and time consuming validation
# returns true on success, raises Exception
# on failure
end
end
Okay, so when I''m running my functional tests within rails, I want to be
able to control how
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 Jul 30
4
Stubbing Observers in rails?
In most of my tests I''d like to be able to stub out the observers for my
models, but I''m not sure the best way to do this. I doesn''t look like there
is a way to stub all instance methods, and I don''t seem to be able to stub
early enough to stub out the observer as it''s instantiated. I can think of
several hackish ways to get around it, but I was
2007 Sep 21
5
Stubbing yielding methods
I''ve just been tying my brain in knots looking at bug #8687 (
http://rubyforge.org/tracker/index.php?func=detail&aid=8687&group_id=1917&atid=7477
).
I''ve been (1) trying to work out whether there is anything logically wrong
with Mocha''s existing behaviour and (2) whether Mocha should support the
requested functionality.
It all centres around the use of the
2007 Jan 02
4
allow stubbing of previously defined methods such as "id"
On my current project I needed to create a stub that responded
correctly to the id message. Here''s the change I put into my copy of
head.
Index: lib/mocha/mock_methods.rb
===================================================================
--- lib/mocha/mock_methods.rb (revision 1114)
+++ lib/mocha/mock_methods.rb (working copy)
@@ -68,6 +68,7 @@
method_names =
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 =
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
2006 Sep 29
1
yielding consecutive values
I''m not sure if someone has already addressed this issue, but if not,
here goes.
I need the following behavior:
def test_generate(documentation = ''/test_documentation/'',
destination = ''/destination/'')
yield_results = [''/'', ''filename.yaml'', ''blah.xml'']
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
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
2009 Mar 15
7
How to use different mocking frameworks?
Hi,
I''m pretty new to Rspec, so hope someone can help me out with this.
I''m leveraging a couple pre-existing applications in my current
project, both have fairly robust test suites in Rspec already.
However, one is using Rspec''s builit in mocking, and the other is
using mocha.
If I set config.mock_with mocha in spec_helper.rb, then all of the
rspec mocks fail. If I