stub

How to stub process.env in node.js?

好久不见. 提交于 2019-12-09 04:27:37
问题 I want to stub process.env.FOO with bar . var sinon = require('sinon'); var stub = sinon.stub(process.env, 'FOO', 'bar'); I'm confused. I read document, but still I don't understand yet.sinonjs docs sinonjs is one example, not sinonjs is okay. 回答1: From my understanding of process.env , you can simply treat it like any other variable when setting its properties. Keep in mind, though, that every value in process.env must be a string. So, if you need a particular value in your test: it('does

Wiremock Stand alone - How to manipulate response with request data

半城伤御伤魂 提交于 2019-12-08 19:11:43
问题 I was trying to implement mocking of POST REST call using Wiremock Standalone server. I am faced with a challenge like this, suppose the post body contains an "name" field and its value, the same value should be returned in the response of that POST call. My json file looks like this: { "priority": 1, "request": { "method": "POST", "urlPath": "/primeSlots", "bodyPatterns" : [ { "matchesJsonPath" : "{ \"things\": [ { \"name\": \"794363\" }] }" } ] }, "response": { "status": 200, "body": "{{$

JAVA: RMI Callback -> object already exported

℡╲_俬逩灬. 提交于 2019-12-08 12:33:10
问题 this is my first question, so sorry if i'll make it incorrect and for my english. I have to do a distributed-hangman project in java, there are guests, players and masters (more matches). When a user(already registered) log himself or when a master open a match, the server must notifies to all guests (only guests) the event. In the client i had to create 2 stub, 1 for the server, the other one for the graphic interface (swing). The threadpool is for manage the matches, not used now. This is

J2ME Stub generates an unknown exception with JPA Entity types

只谈情不闲聊 提交于 2019-12-08 05:30:13
问题 I created a web service stub using NetBeans 7.0 and when I try using it, it throws an unknown Exception . I don't even know what part of my code to show here, all I know is that bolded line generates an unknown Exception: public Businesses[] findBusiness(String query) throws java.rmi.RemoteException { Object inputObject[] = new Object[]{ query }; Operation op = Operation.newInstance(_qname_operation_findBusiness, _type_findBusiness, _type_findBusinessResponse); _prepOperation(op); op

Why are some dll static-linking stub libs (import libraries) so big?

时光怂恿深爱的人放手 提交于 2019-12-07 08:10:46
问题 I noticed while linking to the pcl (point cloud library) that some of the dll stub libs have more than 10MB where the dll themselves have less than half of that size (these are release builds!). Shouldn't the stub lib only contain minimal information so that the dll information is accessible? How can it be larger than the dll files they refer to? The relevancy for me is that by linking to the big stub libs, my own executables are also greatly growing in size; something I wanted to prevent by

stub method with block of code as parameter with OCMock

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 06:04:43
问题 Is there a way to stub method, that takes block as it's parameter? For example mehod: - (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler; 回答1: Yes. The easiest way would be to accept anything: id mockGeocoder = [OCMockObject mockForClass:[CLGeocoder class]]; [[mockGeocoder stub] reverseGeocodeLocation:[OCMOCK_ANY] completionHandler:[OCMOCK_ANY]]; It gets a bit trickier if you want to verify a particular block is passed in. One

Mock fs.readdir for testing

穿精又带淫゛_ 提交于 2019-12-07 05:04:30
问题 I'm trying to mock the function fs.readdir for my tests. At first I've tried to use sinon because this is a very good framework for this, but is hasn't worked. stub(fs, 'readdir').yieldsTo('callback', { error: null, files: ['index.md', 'page1.md', 'page2.md'] }); My second attempt was to mock the function with a self-replaced function. But it also doesn't works. beforeEach(function () { original = fs.readdir; fs.readdir = function (path, callback) { callback(null, ['/content/index.md', '

laravel create model from custom stub when using php artisan

↘锁芯ラ 提交于 2019-12-07 01:32:45
问题 When I use php artisan make:model CustomNamespace\TestModel , I get a model based on default stub as this : namespace App\Models\CustomNamespace; use Illuminate\Database\Eloquent\Model; class TestModel extends Model { // } But what I want to create is a dynamic Model based on my own stub to get something like this: namespace App\Models\CustomNamespace; use App\Models\MyParent; /** * Put a dynamic doc here */ class MyModel extends MyParent { /*put custom methods here*/ } I've checked Laravel

Using Moq to Stub an interface method [duplicate]

会有一股神秘感。 提交于 2019-12-06 20:51:01
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: How to mock a method that returns an int with MOQ Here's my interface: public interface ICalenderService { DateTime Adjust(DateTime dateToAdjust, BusinessDayConvention convention, List<HolidayCity> holidayCities); } I've done some research and it seems you can mock this real easily, but I want to stub this out using Moq so that I can pass the stub into my other class constuctors and have the stub return

Codeception\Util\Stub methods ::exactly and ::once don't work

纵然是瞬间 提交于 2019-12-05 17:16:08
问题 I am using Codeception\Util\Stub to create unit tests. And I want to be sure that my method called several times. For this I am using method 'exactly'. Example: use \UnitTester; use \Codeception\Util\Stub as StubUtil; class someCest { public function testMyTest(UnitTester $I) { $stub = StubUtil::makeEmpty('myClass', [ 'myMethod' => StubUtil::exactly(2, function () { return 'returnValue'; }) ]); $stub->myMethod(); } } As you can see I called myMethod once. But test passed. The same problem