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

Mocking computed fields with Jasmine and Knockout

I'm trying to write a test for a ko.computed field that is dependent on two other complex computeds (removed here for demonstration). function PositionsViewModel(options) { var self = this; self.computed1 = ko.computed(function() { return 1;…
iterion
  • 524
  • 4
  • 16
0
votes
1 answer

How to stub after_create callback collectively in a model?

I'm using Rails 3.2.11, Mac OS X Mountain Lion, Rspec Here's my problem: I have a model that when created, it sends the information to an api. It works all right but when I'm testing it in rspec, the test data also gets sent to the api database.…
Aldrin Dela Cruz
  • 205
  • 1
  • 4
  • 15
0
votes
2 answers

Rspec testing ordered retrieval from a scoped method of model using mocking and expectations

I'm a newb to rspec, mocking and stubbing. I'm slowly starting to appreciate and wrap my head around the concepts of isolated testing and mocking/stubbing in general. I have a basic question, which i think is easier explained through code: class…
KG -
  • 7,130
  • 12
  • 56
  • 72
0
votes
1 answer

How do I use Gently to stub a method of an object that is not immediately exposed by a module?

I'm using the AWS SDK for NodeJS. I've got a module (moduleFoo) set up like this: if (global.GENTLY) { require = GENTLY.hijack(require); } var aws = require("aws-sdk"), ec2; exports.initEC2Client = function () { ec2 = new…
Andrey
  • 671
  • 10
  • 23
0
votes
1 answer

Rspec testing instance method which require other methods return (stubbing?)

I want those already methods to be tested, but everything I try, doesn't seem to fit with best practices nor do it work. May be somebody can support me with this? CODE To be tested def any_subset_greater? divisors_sums.any?{|sum| sum >…
radosch
  • 603
  • 7
  • 19
0
votes
1 answer

Stubbing out save methodin rails with rspec

I have the following action in my controller: def create @user = current_user @vin = @user.vins.new(params[:vin]) if @vin.save # waiting for implementation logger.debug("here we are") else …
Agazoom
  • 618
  • 4
  • 19
0
votes
2 answers

Unit Test Assert against end result or verifying whether the parameters were called using Moq

Below is a class (Class1) that I want to test, but I'm not fully satisfied with my Unit Test. Please see below code samples. System Under Test public interface IRepository { string GetParameter(int id); } public class Repository { public…
Spock
  • 7,009
  • 1
  • 41
  • 60
0
votes
1 answer

Stub ssl_required so my RSpec will pass

I'm using bartt-ssl_requirement in a Rails 3.0.9 app. The ssl_required and ssl_allowed statements at the top of my controllers are breaking my rspec with their redirects. How do I fix that? From poking around, I can "stub" the ssl_required method in…
LikeMaBell
  • 1,529
  • 2
  • 13
  • 24
0
votes
2 answers

How do I stub out a current user's attributes in a view spec

I have a view spec where I'm testing conditional output. How do I get the spec to return the user I've mocked out? View file: .content - if @current_user.is_welcome == true Welcome to the site View spec: before(:each) do @user =…
Simpleton
  • 6,285
  • 11
  • 53
  • 87
0
votes
1 answer

Javascript Unit testing dependencies - How to make a test fail when a depended object changes

I have a controller which is depended on a model property. I wrote a test which test this controller and stubbed the model, How can I make my controller test fail whenever the model property name changes? Here is an example: Model: function…
Shai Reznik - HiRez.io
  • 8,748
  • 2
  • 33
  • 33
-1
votes
1 answer

Mockito - Unfinished Stubbing

I'm getting an UnfinishedStubbingException with the following code: Mockito.when(repository.findAll(Mockito.any(Pageable.class))) .thenReturn(BusinessEntityMockGenerator.createPageResponse(bd, null)); The strange thing is I was not getting this…
user3133300
  • 607
  • 4
  • 13
  • 23
-1
votes
1 answer

Is there a way to programmatically add stub ID's to Spring Cloud Contract Stub Runner?

I would like to stub contracts based on an ID in the url (this is for a Spring Application). Is there a way to add an ID to the Stub Runner during runtime or do all stubs have to be specifically defined in the @AutoConfigureStubRunner annotation?
Sam M.
  • 13
  • 5
-1
votes
2 answers

removing randomness from capybara feature test

I am making a simple game of Rock, paper, scissors using a Sinatra and testing with rspec-capybara. The game plays against a computer opponent that randomizes either rock, paper or scissor. I am writing a test for the web page result. I am stubbing…
-1
votes
1 answer

How can I stub FileSystems.getDefault() method using mockito?

Here is the problem statement. I want to confirm (in my Test method) that fileSystem.newWatchService() is invoked within my target method. I am getting the default FileSystem instance (using FileSystems.getDefault()) in my target method. Anyone know…
deepthought
  • 87
  • 11
-1
votes
1 answer

Setting up environment for testing in Python

I'm writing integration tests using plain unittest in Python (import unittest) and are creating stubs for some external services. Now I want to run the same tests with a real implementation; but also keep the stubs. That way I can run the tests with…
1 2 3
27
28