Displaying 20 results from an estimated 1000 matches similar to: "Mocking system/`"
2006 Dec 21
4
Stubbing Kernel#open
Anyone know how to stub Kernel#open? I''m trying to mock/stub an
open-uri call, but it doesn''t seem to like it.
Here''s the test code, and the failures:
body = File.open(File.dirname(__FILE__) +
''/../fixtures/google_search_california.html'').read
2006 Oct 17
4
Mocking the rendering of a Rails template
Hello all,
I''m having difficulty setting up mocks such that I can verify that
Rails was going to render the right template file (for example
new.rhtml) and stop Rails from performing the actual rendering.
After peeking at Rails'' internals, I tried two techniques as illustrated here:
http://pastie.caboo.se/18197
Neither worked.
I think the first one failed because Rails
2007 Jun 19
4
Changing the value of $?
Hi :)
Does anyone know of a way to set the value of $? ?
I have a test which stubs ` ; the call works fine, but then the library
I am testing checks the value of $? to see if the process terminated
correctly.
It seems not to be possible to assign $? directly...
For now I do this before my test :
`ls > /dev/null`
Which ensure that $? is zero ; but this is not a very nice way of doing
it !
2006 Dec 19
9
Stubbing ActiveRecord Models gets very difficult with instance methods
I have seen some basic examples of using Mocha and Stubba with ActiveRecord Models; However, the ones I read were somewhat simplistic. That is they stubbed the find class method of the model, or the execute method of the connection object. While stubbing the find method had the desired effect for the author it did not help with a situation I was hacking away on. Which was writing a test case
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
2007 Apr 12
15
Preview of Latest Mocha Changes
I''ve finally managed to find some time to do some serious work on
Mocha. There are some code snippets on my blog
(http://blog.floehopper.org/articles/2007/04/12/preview-of-latest-mocha-changes)
showing the new functionality available in trunk (revision 128). I
don''t don''t know how many people out there are using trunk, but it
would be great to get some feedback on these
2007 Jan 17
8
Mocha Mock''s hanging on after test run?
Hi guys,
I''m running mocha (0.3.2) against Rails core and just found an issue
where the mock doesn''t go away after the test is run.
For example:
def test_reset_bang_doesn_reinstall_named_routes
ActionController::Routing::Routes.named_routes.expects(:install).never
@session.reset!
end
def test_zzz
puts ActionController::Routing::Routes.named_routes.inspect
2007 Mar 04
4
Rails functional testing and Mocha
I''ve always wanted to be able to do stuff like this in my functional
tests
c = customers(:customer_1)
c.expects(:great_customer_service)
post :service_customer, :id => c.id
This of course fails because inside the rails action a different
instance of customer is used. Some of the time setting your
expectation/stubbing on Customer.any_instance works, but it''s not
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:
2006 Sep 03
1
Slimmed down version for inclusion in Rails?
I''m pushing a major overhaul in testing the Rails codebase. Mocha and
stubba make my life easy so that''s what I''m using. The first major
patch using them is in RailTies
(http://dev.rubyonrails.org/ticket/5970) now. I spoke to DHH today
about using it in the other libraries and I think it''ll be ok, but
they really want to include as little code as needed. I
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 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
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 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
2006 Sep 03
1
Returning different values with stubs
Right now I''m working on adding tests to a method that looks like this:
def get_via_redirect(path, args={})
get path, args
follow_redirect! while redirect?
status
end
So, I want to confirm that get is called and that status is returned
but I also want to see that when the value of redirect? effects how
many times follow_redirect is called. Is there
2007 Jun 08
4
Mocha 0.5 released
* Hamcrest-style parameter matchers
* Values returned and exceptions raised on consecutive invocations
* Yields on consecutive invocations
* Multiple yields on single invocation
* Invocation dispatch fixed
* Deprecated returning result of a Proc
--
James.
http://blog.floehopper.org
2008 Jan 30
2
Testing a call to super
Did any further discussion ever come of this? I take it is officially
not supported currently? I just get an odd error when I try it (it
throws a "0 expected 1 received", no matter what stubbing/expectation
combo I use), so came looking around on google, and finally the
mailinglist.
Here''s my stripped down example: http://pastie.caboo.se/145603 (it
fails with expects too)
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 Jun 12
4
advice on new failures with 0.5.0
Hi all,
We just updated to the latest version of Mocha and now we''re seeing a
lot of odd test failures. If this isn''t the appropriate place for a
question like this, please let me know.
Say I have code like this in a controller:
DataMonitor.toggle_notification!
And I mock it like this:
DataMonitor.any_instance.stubs(:toggle_notification!)
This would work fine with Mocha
2007 Apr 03
5
small suggestion - once method on Expectation
I find that a lot of times I want to ensure a method gets called
exactly once, for example when testing caching or eager loading. What
does the list think of adding this little humane method to
Mocha::Expectation?
def once
times(1)
self
end
which means this:
def test_should_only_grab_post_once_from_the_cache
Post.expects(:get_cache).with(google_vs_yahoo.id).times(1)