Questions tagged [stubbing]

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

420 questions
13
votes
1 answer

stub_chain together with should_receive

I am trying to test if in a method calling chain one of the methods get a specific parameter. In the below code for example MyModel must receive the parameter 0 for the method offset. Unfortunately the code below does not work. It seems it is not…
medihack
  • 16,045
  • 21
  • 90
  • 134
13
votes
1 answer

Stubbing nested function calls in sinon

There are three seperate questions that are similar to this one but none of them resembles the case I have. So I basically have a function which takes a function as a parameter var myfunc ( func_outer ) { return func_outer().func_inner(); } In…
ralzaul
  • 4,280
  • 6
  • 32
  • 51
12
votes
6 answers

Stubbing out functions or classes

Can you explain the concept stubbing out functions or classes taken from this article? class Loaf: pass This class doesn't define any methods or attributes, but syntactically, there needs to be something in the definition, so you use pass.…
xralf
  • 3,312
  • 45
  • 129
  • 200
12
votes
1 answer

stub_request when request body is not predictable

I am stubbing an http request with stub_request. This http request is basically a slack notification, that contains some random string (e.g. a timestamp.) So, I can not just reuse the snippet, rspec spits out to me, because body differs on every…
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
12
votes
5 answers

Ruby stubbing with faraday, can't get it to work

Sorry for the title, I'm too frustrated to come up with anything better right now. I have a class, Judge, which has a method #stats. This stats method is supposed to send a GET request to an api and get some data as response. I'm trying to test this…
Majoren
  • 983
  • 5
  • 16
  • 36
10
votes
3 answers

Stubbing with Faraday and Rspec

I have a model that looks like this: class Gist def self.create(options) post_response = Faraday.post do |request| request.url 'https://api.github.com/gists' request.headers['Authorization'] = "Basic " +…
michael
  • 2,977
  • 3
  • 20
  • 26
10
votes
1 answer

RSpec: Stubbing SFTP

I'm attempting to stub out Net::SFTP from an object. Here's the model: class BatchTask require 'net/sftp' def get_file_stream(host, username, password, path_to_dir, filename) raise ArgumentError if host.nil? or username.nil? or…
Sly
  • 743
  • 13
  • 38
9
votes
1 answer

How do you stub ActiveRecord::Base methods without making assumptions about how it's used?

ActiveRecord::Base has a big ol' API with multiple methods for both finding and saving objects. For example, your AR::B objects might have been instantiated from a number of…
Gareth
  • 133,157
  • 36
  • 148
  • 157
9
votes
2 answers

Stub out address geocoding during RSpec unit test

I'm using the geocoder gem to add geocoding functionality to one of my Active Record model classes. This works great, but I don't actually want the geocoding to fire during unit tests. I've tried stubbing out the call to geocode by adding this to my…
Kevin Pang
  • 41,172
  • 38
  • 121
  • 173
9
votes
2 answers

Stub calls to third party services using WireMock

I tried to find a way to stub calls to external services via WireMock. WireMock easily mocks any relative URL, but what if we want to intercept a REST call, which was sent from our node to some 3rd party service and return predefined response? Is…
Alesto
  • 639
  • 4
  • 13
  • 29
9
votes
1 answer

What is ongoingstubbing in mockito and where we use it?

Can any one explain what is ongoing Stubbing in mockito and how it helps writing in Junit Testcase and mocking the methods.
Gowtham Murugesan
  • 407
  • 2
  • 6
  • 17
9
votes
5 answers

When to use stubs and mocks?

I've this confusion all the time. If I write a code which uses fake code to assert some operation, how do i trust my real implementation when it is started really using the real objects instead of fake ones. For example, I've this code -- …
asyncwait
  • 4,457
  • 4
  • 40
  • 53
8
votes
1 answer

How is 'provided' implemented in a fact in Midje?

I was reading Clojure in Action chapter 8 about TDD and experimented with the stubbing macro. It uses the dynamic binding mechanism to stub functions. Alas, in Clojure 1.3 it is not possible to use the binding mechanism for non-dynamic vars, so the…
Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149
8
votes
2 answers

Wiremock error - there are no stub mappings in this WireMock instance

I have implemented a basic WireMock with a sample REST/HTTP request simulation. The server code implemented as below. With this code, I get the following error when I issue the GET request from Postman (i.e. GET http://127.0.0.1:8089/some/thing).…
AnilJ
  • 1,951
  • 2
  • 33
  • 60
8
votes
1 answer

Mock a method with an object parameter with Mockito

In my unit test i want to mock the interaction with elasticsearch by doing the following when(cityDefinitionRepository.findCitiesNearby(geoPoint, SOURCE,…
Glenn Van Schil
  • 1,059
  • 3
  • 15
  • 33
1 2
3
27 28