Displaying 20 results from an estimated 500 matches similar to: "problem with using any_instance"
2006 Sep 25
3
Problem stubbing instances referred to by constants
Hi James,
An instance retains its mocha between tests if that instance is
pointed to by a constant. The simplest failing test is something like
(add as a new file in mocha/test)..
#--code--
require File.join(File.dirname(__FILE__), "test_helper")
require ''stubba''
class WemStubbaTest < Test::Unit::TestCase
Arr = [1, 2, 3]
def test_a
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 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
2008 Jun 04
6
any_instance
Hi folks.
I''m very interested in the status of a port of any_instance from Mocha to RSpec.
In particular I have a spec suite that I wrote using RSpec but with
Mocha that depends heavily on any_instance. This is because it stubs
out one or two methods from an underlying API. In attempting to
convert the suite to RSpec mocks (because that''s what we''re using for
the rest
2007 Feb 06
3
Using any_instance with Rails to make sure the right thing is saved?
I''d like to test that an object with the correct attributes is saved,
something like:
def test_create_without_existing_suite
this = self
w = Annotation.any_instance.expects(:save).with do |x|
this.assert_equal ''fnord'',
some_way_get_the_name_of_the_receiver_of_save
true
end
w.returns true
end
But the object is created inside the method
2007 Sep 06
5
Removing/overriding/unstubbing a stub?
We''re using Mocha stubs to stub out a slow-performing network request in
a Test::Unit class. But naturally, we don''t want to stub it out in the
few tests that actually verify the functionality of that network request.
Is there a way to do the stub in "setup", but override it for the few
tests that need the original functionality?
(I realize that in this case, the
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 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 =
2018 Nov 20
3
Samba not respecting directory acls inside a share
Hi,
we are running Samba 4.9.2 on Solaris 10 connected to AD as a member
with some share:
[refb]
path = /samba/refb
browseable = no
valid users = +"AM\refb_users"
writeable = yes
force user = AM\qui
force group = AM\refb_users
All the samba users and groups come from AD through nss_winbind.
Inside /samba/refb/ I created a sub directory test_a and set the owner
(in Solaris via chown)
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.
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)
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.",
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 Aug 10
6
Migrations suddenly broken: undefined method autoload_paths
I really need some help here because I am at a loss. I have been using
migrations just fine now for a while and I suddenly started getting a
very bizarre error when migrations are run:
undefined method `autoload_paths='' for Dependencies:Module
I have tried rolling back my application code, and rolling back the
rails edge revision I am running but neither seem to help.
I have
2006 Aug 14
14
A mock which extends rather than replaces a class?
While running tests, we would like to instrument some of the classes
under test. We still want the classes to do exactly what they currently
do, but we would like them to do more when running in the test
environment.
Clearly we can (and currently do) just extend the objects "on the fly"
where necessary, but this is a bit messy - we''d like some centralised
way to always
2006 Dec 15
5
Testing event driven Socket classes
Ok, here is the class, I want to Unit Test, its part of a large app
and is based on EventMachine library.
I want to mock the class TickServer ( i.e not stub it) . Since in
actual scenario, you can''t do this on this class:
@server = TickServer.new # will toss an exception at your face
you must initialize the server like this:
EventMachine.run {
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
2011 Aug 04
3
#create tests fail when I add FriendlyId to my model
I am doing controller testing, and I can''t seem to get the create
method test to pass when friendly_id is added to the mix. If I comment
it out of the model, the tests all pass perfectly. The moment I add it
back in, the error looks like this:
1) Error:
test_create_valid(BrandsControllerTest):
FriendlyId::BlankError: FriendlyId::BlankError
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 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