Questions tagged [stubbing]

Stubbing is modifying an instance method or property of an object at runtime to extend its functionality.

420 questions
0
votes
1 answer

How to stub all condition methods in ruby's state_machine for testing?

I am using state_machine with rails to handle state on some active record models and testing them with rspec and factory girl. I also have a serialized array property called state_path that keeps track of the state history. class Project <…
ianstarz
  • 417
  • 4
  • 12
0
votes
3 answers

Understanding mocking/stubbing - mockito

I have a very basic understanding in mocking/stubbing. When you create a stub in test code like: test h = mock(test); when(h.hello()).thenReturn(10); and in source logic I have code like this: test src = new test(); src.hello(); Now will stub…
0
votes
2 answers

Mocking / stubbing "third party" services during integrated development

The application I am currently working with is being worked on by 3 separate teams, each working away on different functional areas that come together at the end of the day. The difficulty is keeping the 3 teams always in sync and not having one…
user2533384
  • 107
  • 1
  • 10
0
votes
2 answers

Returning Collections on stubbed objects

I've often faced with something like this public void methodToTest() { Set names = dependencyDao.getNamesFromExternalDataSource(); for (String name : names) { externalService.doSomethingWithName(name); //.... …
onigunn
  • 4,730
  • 10
  • 58
  • 89
0
votes
1 answer

RhinoMock Stub Linq Where clause for DbContext

I was trying to unit test my repository. I need to mock the Where Clause with some values. I have tried the following var parentClass = new ParentClass {id = 1}; var subClass = new SubClass { id=2, ParentClassId = parentClass.id, …
Saanch
  • 1,814
  • 1
  • 24
  • 38
0
votes
2 answers

Mock / stub with integration testing in Java

I'm using rest-assured for integration testing on my endpoints. One of the endpoints has a dependency to another resource (it calls another API conditionally). Is there a way for me to stub out the API call so I can write a test for that case?
etang
  • 730
  • 8
  • 23
0
votes
1 answer

How to avoid duplicate definitions between stub and real code

I am trying to write unit tests for some legacy code written in C. The problem I encounter is that I regularly have to redefine structs used in the real code, in order to use them in the stub code. For example, let's say this is the header file with…
Chilon
  • 31
  • 4
0
votes
1 answer

stubbing out static method calls

So I was writing my tests for PHPUnit when a test started exploding all over the place. Its main reason was that Config::get() was throwing - undefined get() for class Core.class.php This class is called in the test as such: class CoreTest extends…
LogicLooking
  • 916
  • 1
  • 16
  • 32
0
votes
1 answer

Asyncjs Waterfall and SinonJS stub

How can I stub @ra.do_post so that it goes into "Step 2" Right now when I run my spec inside Async.Waterfall after Step1 it goes to Step 5 What I think is in my spec I am not returning the callback properly for it to go into step2 scroll to end…
Rockyboy_ruby
  • 233
  • 1
  • 4
  • 15
0
votes
1 answer

How to implement chained stub in javascript with Jasmine and AngularJs?

I'm not sure if I'm writing the title correct, but here's what I want to do. I have this code var callback = function(result) { if(result.count < 5) { msg_id = result.msg_id; MovieService.getMovies(msg_id,…
toy
  • 11,711
  • 24
  • 93
  • 176
0
votes
1 answer

Did I TDD this method well or is there a better way?

Note: I'm used to using Dependency Injection with C# code, but from what I understand, dynamic languages like Ruby and Python are like play-doh not LEGOs, and thus don't need to follow use IoC containers, though there is some debate on if IoC…
Matt
  • 14,353
  • 5
  • 53
  • 65
0
votes
1 answer

How can I get my Rspec unit test to pretend that the output of another method is XYZ

Using Rspec, I am writing unit tests for @survey.description: class Survey < ActiveRecord::Base def description if self.question.try(:description).present? && self.selected_input.present? return…
steven_noble
  • 4,133
  • 10
  • 44
  • 77
0
votes
1 answer

Mocks and Stubs. I don't get the basics

I am in the process of freeing myself from FactoryGirl (at least in the lib folder). So, I start writing strange stuff like "mock" and "stub". Can somebody help a novice out? I have this module module LogWorker extend self def…
Andreas Lyngstad
  • 4,887
  • 2
  • 36
  • 69
0
votes
2 answers

Testing class method using OCMock release 2.1.1

I am trying to check if a class method is getting invoked using OCMock. I have gathered from OCMock website and other answers on SO that the new OCMock release (2.1) adds support for stubbing class methods. I am trying to do the…
Warrior
  • 39,156
  • 44
  • 139
  • 214
0
votes
1 answer

Stubbing calls to exteranl API in gmaps4rails in cucumber scenarios

I have cucumber(with capybara) scenarios, which use gmaps4rails gem, thus some steps call gmaps external API during test's execution. I wanna stub out these calls. What is the best way to achieve that? Thanks in advance!
1 2 3
27
28