similar to: If I stub do I have to mock as well?

Displaying 20 results from an estimated 800 matches similar to: "If I stub do I have to mock as well?"

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 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 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)
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 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
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 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
2008 May 28
3
Mocking objects to test Rails Controllers
Hi all, I''m currently considering the use of Mocha to aid in writing my Rails unit/functional tests. I currently have a Rails model which mixes in a series of methods to allow it to talk to an external service. The code is roughly of this form: class Person < ActiveRecord::Base include SMSNotifier def send_notification(message) send_sms(number,message) #
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
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 Jul 30
6
Object.stubs doesn''t seem to work.
Hi I''m using Mocha 0.5.3 and I want to stub out a call to Time.now, just like the example in the post http://blog.floehopper.org/articles/2007/06/08/mocha-0-5-released However, trying it in irb gets me the following error: >> require ''mocha'' => true >> Time.stubs(:now).returns(Time.parse(''Thu Feb 01 00:00:00 UTC 2007'')) NoMethodError:
2007 Mar 27
3
Stubbing out method for all instances
I am using the acts_as_state_machine plugin to control state of an object in my app, however when testing this I need to be able to stub out the guard conditions so that state will change when I fire off an event without depending on other models. Guard conditions simply return true or false so I have an instance method: def encoded? <check state of other objects> return true
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
2007 Aug 14
4
Stubbing all methods
Mocha''s mock/stub framework has the ability to stub all methods on a mock given. Does RSpec''s mocking framework have this ability? And if not, is there some reason it shouldn''t be implemeneted? Regards, Scott
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 !
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
2008 Aug 26
9
stub_model() and ActiveRecord Associations
Hi all, I have what I thought was quite a simple requirement but something to do with the way ActiveRecord''s associations work is making it quite puzzling. I guess I can sum it up with this failing test: before(:each) do @source_comment = @source.comments.create(:user_id => 1) @target_comment = @target.comments.create(:user_id => 1) end