Displaying 20 results from an estimated 9000 matches similar to: "How to mock a model method for unit tests?"
2006 Jun 14
9
Controller testing and mocks...
So far I''ve been doing my controller testing against "real" (testing)
objects; however, I''ve been beginning to wonder if I should "default" to
using mocks in most cases -- both for performence and to enforce a
looser coupling.
In part this is driven by my viewpoint that rail''s "functional" tests
are still "unit" tests, so they
2007 Dec 06
6
mock libraries, Object#send, and Object#__send__
What is the appropriate way to stub out (and put an expectation on
Object#__send__), without getting warnings from the Rspec mock library?
Scott
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 Aug 22
1
mock framework ethics question
Hi James, Jim, and everyone else who''s listening.
I''ve been investigating an interesting bug related to mocks and rails
AssociationProxies. See
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=12547&group_id=797
for details.
The crux is that if you do this (rspec mock syntax):
obj.should_receive(:msg).with(mock_of_a_model)
and the implementation does
2007 May 07
6
mock frameworks
Just curious - now that rspec (as of 0.9) let''s you choose your mock
framework, how many of you are actually using (or planning to use)
mocha or flexmock?
Anybody planning to use any other mock framework besides rspec, mocha
or flexmock?
Thanks,
David
2006 Jul 24
2
Creating a ''default'' mock
Am I correct in thinking that it''s not currently possible to have a
method that creates a ''standard'' mock (i.e. a mock that has defaults
useful in all contexts)?
I''ve tried with the mock method and also by manually creating new Mock
instances. I get failures when setting up expectations (undefined
method ''receive'' for proc).
Chris
2007 Aug 15
3
unit testing active resource - mock or connect?
Hi all - there''s a patch I need to apply from a ticket:
http://dev.rubyonrails.org/ticket/8798
The ticket appears to be stalled on the lack of a test case. I figured
I''d just whip one up, but because it''s an Active Resource thing, and
the test case would need to do ModelName.find(:all), I''d need to
either mock the network connection or set one up.
In this
2006 Oct 23
6
overriding mock expectations
There is one annoyance I''m encountering with the Mock API in rSpec.
Overall it works well, as far as dynamic mocks go ;)... but there''s
this one thing... It doesn''t allow overriding of expectations.
example:
m = mock("blah")
m.should_receive(:one).any_number_of_times().and_return(1)
m.should_receive(:one).and_return(1)
The second call to should_receive
2007 Oct 21
10
Preferred mock framework
Hi
In light of the fact that RSpec mocks are going into maintenance mode
in the near future, I was wondering what everyone was switching to.
I liked the look of FlexMock most, so gave that a shot. However,
there''s a few things that don''t work well with RSpec due to the
traditional differences in the way Test::Unit cases are written vs
RSpec specs. (One spec per
2007 Feb 08
1
flex mock?
Hi guys,
Would you mind if I ask how Flex Mock and Mocha sit together? They compete
directly?
I read that Flex Mock was built into Rails 1.2. Is there a reason to use
Mocha instead of Flex Mock?
Tks
Greg
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)
2007 Dec 13
1
RSpec and Mock Tutorial/Cheatsheet
I wrote a simple summary of Mocks with RSpec as an answer to a
discussion on our local Ruby users group. I was wondering if people
here could review it, adding comments for any corrections or other
important ideas regarding mocks and RSpec. You can find the article
here: http://blog.showcase60.com/2007/12/13/rspec-mocks
Thanks
2008 May 18
2
Using Hash to mock classes that respond to :
Hi
I''ve been doing this a while now. If I have a class that responds to :
[], and all I''m interested in stubbing is that method, then instead of
using a mock I just create a hash. (Similarly, you could create an
array when you are testing an Enumerable object.)
Example from code I just worked on, where uses MigrationGraph#[] looks
up graph vertices by name:
2007 May 30
4
Using mocks
I''ve just started doing TDD/BDD and like the idea of mocks. So I set
out to use them. The doc pages seem great, I setup the mock and then
it just works. Here is what I am trying to do:
Myuser is a non-rails model of user attributes. We are going to be
mocking the connection to the ldap server. The user class has a login
method that connects to the ldap server and if successful,
2008 Jul 25
21
Problems with mock assigned to a constant
Hi all,
Initially I thought this was a bug in the built-in mocking framework(and it
still may be), but I better hash it out on the mailing list before I
file/reopen the ticket:
http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6
I thought my example illustrated my problem, but obviously I was passing the
wrong arguments to the mock. I revised my example to
2007 Dec 09
2
Mocks and Manual Tests
Is it possible for me to use Mock objects in manual testing?
They work great for functional testing, but now I need to load the pages and play around with some stuff, but of course I cant load them because there are a number of classes without implementations, which I want to just mock out.
Any ideas?
-----------------------------------------------------------------
Find the home of your dreams
2007 Mar 05
4
When to stub/when to mock (was Rails functional testing and Mocha)
Hi James,
> From: James Mead <jamesmead44 at gmail.com>
> Date: Mar 5, 2007 5:15 AM
> Subject: Re: [mocha-developer] Rails functional testing and Mocha
> To: mocha-developer at rubyforge.org
> "I''d probably stub the call to find not expect it, because its a query not a command"
I have a different perspective on when to use stubs and when to use
mocks and
2008 Mar 05
7
mocking successive return values
I''m having a problems mocking successive return values. I don''t know
if I''m doing something wrong or if this is a limitation of rspec
mocks. Any ideas of what I may be doing wrong?
I''m trying to test the generate_quote_number method. It generates a
quote number, looks to see if it is in the db already. If it is, it
calls itself to try again. I want
2010 May 15
3
ActiveResource Mock Objects
Some of my tests use ActiveResource HttpMock requests and some of them
do not. Does anyone know if there is a way to disable the HttpMocks
after they have already been loaded? The method
ActiveResource::HttpMock.reset! only removes all the objects, but
ActiveResource still thinks it should look for mock requests rather
than actually making requests. I hope this makes sense!
Thanks,
Tom
--
2007 Mar 13
1
Opening the singleton class of mocked objects
I wrote a plugin [1] a while ago that lets me do validations on a
single AR instance. Instead of defining validations in an AR class, I
can define them on a AR instance''s singleton class:
class << @video
validates_presence_of :title
end
One of my specs mocks Video.find, and the above code is run on the
mock object. When I run the spec, I get the expected
undefined method