Stubbing is modifying an instance method or property of an object at runtime to extend its functionality.
Questions tagged [stubbing]
420 questions
5
votes
1 answer
Changing WireMock __files directory
From the docs:
To read the body content from a file, place the file under the __files
directory. By default this is expected to be under src/test/resources
when running from the JUnit rule. When running standalone it will be
under the current…

IsaacLevon
- 2,260
- 4
- 41
- 83
5
votes
1 answer
Rhino Mocks: stubbing value used in assertion?
First my question, and then some details:
Q: Do I need to stub the value of a property when making sure its value is used in a subsequent assignment?
Details:
I'm using Rhino Mocks 3.5's AAA syntax in MSpec classes. I've trimmed the code below to…

lance
- 16,092
- 19
- 77
- 136
5
votes
7 answers
How would I go about unit testing this?
I need to develop a fairly simple algorithm, but am kindof confused as how to best write a test for it.
General description: User needs to be able to delete a Plan. Plan has Tasks associated with it, these need to be deleted as well (as long as…

Sam
- 1,514
- 2
- 14
- 22
5
votes
1 answer
capture parameters passes to stub in powermockito
How can I capture (for assertion purposes) the parmeters passed to a static stub method call?
The methodBeingStubbed looks like this...
public class SomeStaticClass{
protected static String methodBeingStubbed(Properties props){
...
I am stubbing…

Rob McFeely
- 2,823
- 8
- 33
- 50
5
votes
3 answers
How do I stub a path generating method in Rails?
I'm writing a view spec, and it renders a view that contains the line (in haml):
=link_to new_post_path
but the spec fails with:
ActionController::RoutingError: No route matches {:action=>"new", :controller=>"post"}
I'm trying to stub the…

jefflunt
- 33,527
- 7
- 88
- 126
5
votes
2 answers
Sinon.JS stub for window.location.search
I am trying to test a simple function that makes a call to window.location.search. I'm trying to understand how to stub this call so that I can return a url of my choosing.
function:
getParameterByName: (name) =>
name = name.replace(/[\[]/,…

Michael D Johnson
- 889
- 1
- 10
- 21
5
votes
2 answers
How do you stub all methods of a particular mock instance
I have a particular mock that is being handled by a third party. I just want to check that the same mock has been returned back.
However, the third party calls array methods and save methods that my test doesnt really care about. Is there a way to…

Karan
- 14,824
- 24
- 91
- 157
4
votes
2 answers
Stubbing Warden on Controller Tests
I'm having an issue with testing my controllers and using Warden.
All examples point at stubbing request.env['warden']. This causes issues in my controllers when I call env['warden'], which then returns nil.
For a crude example, using…

stuartc
- 2,244
- 2
- 24
- 31
4
votes
1 answer
How to stub a delete association to return false
I have dealer.cars where a dealer has many cars.
In my spec i want to stub dealer.cars.delete(car) to return false. However i cannot get this to work.
I have currently tried:
allow_any_instance_of(Car).to…

b.herring
- 563
- 2
- 18
4
votes
1 answer
Playwright intercept server side network request
Can't see to find any good docs on how to mock/stub the server Sider side requests with playwright.
An example would be to intercept the getServerSideProps in nextjs: hitting the routes makes the server do a request (db API etc). Then it can do some…

Norfeldt
- 8,272
- 23
- 96
- 152
4
votes
1 answer
stubbing helpers using mocha
it "should have edit button if user has permission to edit" do
EntitiesHelper.stubs(:permission_to_edit_entity?).returns(true)
get :index
@entities[0..3].each do |entity|
response.should have_selector("form",
:method => "get",
…

deruse
- 2,851
- 7
- 40
- 60
4
votes
1 answer
How to mock/stub methods in Elixir library Ecto/Repo?
Tell me please how to mock/stub methods of Repo module for my tests?
For ex.:
link = Repo.get_by(Link, short_url: url)
db_count = Repo.aggregate(Link, :count, :id)
I need that Repo.aggregate returns 10000000000 for my tests. The same with…

Oleksandr Bratashov
- 718
- 9
- 19
4
votes
1 answer
Stub controller action in Rspec controller test, but it's still executed
I would like to test if a controller action is actually called without a redirect happening in some before_filter. Since the controller action itself may do a redirect, I want to stub the action to raise a specific error (SuccessfulActionError or…

Manuel Meurer
- 3,238
- 6
- 35
- 50
4
votes
0 answers
How not rebuild react native app before running e2e tests?
I am using detox for testing my RN application
I have a stub for Facebook login in tests like this:
// js/actions/login.e2e.js
function fbAuth() {
console.log('stubbed auth with Facebook');
}
module.exports = { fbAuth };
When I build my app…

Hirurg103
- 4,783
- 2
- 34
- 50
4
votes
2 answers
Strategy for stubbing HTTP requests in Clojure tests
I'm wondering if there's a widely used pattern or solution for stubbing outbound HTTP requests to third-parties in Clojure integration tests (a la Ruby's webmock). I'd like to be able to stub requests at a high-level (for instance, in a setup…

pdoherty926
- 9,895
- 4
- 37
- 68