spy

How to use Jasmine spies on an object created inside another method?

早过忘川 提交于 2019-12-02 19:14:44
Given the following code snippet, how would you create a Jasmine spyOn test to confirm that doSomething gets called when you run MyFunction ? function MyFunction() { var foo = new MyCoolObject(); foo.doSomething(); }; Here's what my test looks like. Unfortunately, I get an error when the spyOn call is evaluated: describe("MyFunction", function () { it("calls doSomething", function () { spyOn(MyCoolObject, "doSomething"); MyFunction(); expect(MyCoolObject.doSomething).toHaveBeenCalled(); }); }); Jasmine doesn't appear to recognize the doSomething method at that point. Any suggestions? When you

CF633C Spy Syndrome 2 trie树

﹥>﹥吖頭↗ 提交于 2019-12-01 02:21:38
这个模型以前绝对见过,模拟赛的时候开始敲了一个AC自动机,纯属脑抽~ code: #include <bits/stdc++.h> #define N 5000006 #define NN 10005 #define M 100006 #define setIO(s) freopen(s".in","r",stdin) , freopen(s".out","w",stdout) using namespace std; queue<int>q; stack<int>ss; int n,m,cnt,tot; int st[M],ed[M],f[M],lst[M],length[M]; char S[M],str[M],total[N]; struct Node { int tag,f,len; map<int,int>ch; }t[N]; int main() { int i,j; // setIO("char"); scanf("%d",&n); scanf("%s",S+1); scanf("%d",&m); for(i=1;i<=m;++i) { scanf("%s",str+1); int len=strlen(str+1); int p=0; st[i]=cnt+1; ed[i]=st[i]+len-1; for(j=1;j<=len;++j) { int c; total

Mockito Spy - stub before calling the constructor

青春壹個敷衍的年華 提交于 2019-11-30 04:50:56
I'm trying to spy on an Object and I want to stub a method that is called by the constructor before the constructor calls it. My class looks like that: public class MyClass { public MyClass() { setup(); } public void setup() { } } The setup method mustn't be called. Well, how do I spy on this method (and stub setup so that it does nothing)? It works fine with mocking the method but I want to unit test MyClass and so I will need very other method. The reason why need to stub the setup method so that it does nothing: I'm programing a Lego robot (lejos) and I put some code in setup that the robot

Why are some items greyed out in Spy++'s Windows view?

ε祈祈猫儿з 提交于 2019-11-30 02:52:03
问题 To modify a window of another program, I need to find a specific SysTreeView32 in it using EnumChildWindows API call. When I inspect the window using Spy++, there are a number of SysTreeView32 's in it but all are greyed out except one, which is the one I'm looking for. The following picture is an example of grey items: Why are the shown items gray and what API call does Spy++ use to know whether it should grey out an item or not? 回答1: Those are just non-visible windows - ie HWNDs that don't

mockito : how to unmock a method?

两盒软妹~` 提交于 2019-11-29 15:56:22
问题 I have a JUnit class with different methods to perform different tests. I use Mockito to create a spy on real instance, and then override some method which is not relevant to the actual test I perform. Is there a way, just for the sake of cleaning up after me in case some other tests that run after my tests also use the same instances and might execute a mocked method they didn't ask to mock, to un-mock a method? say I have a spy object called 'wareHouseSpy' say I overriden the method

Mockito Spy - stub before calling the constructor

家住魔仙堡 提交于 2019-11-29 00:23:19
问题 I'm trying to spy on an Object and I want to stub a method that is called by the constructor before the constructor calls it. My class looks like that: public class MyClass { public MyClass() { setup(); } public void setup() { } } The setup method mustn't be called. Well, how do I spy on this method (and stub setup so that it does nothing)? It works fine with mocking the method but I want to unit test MyClass and so I will need very other method. The reason why need to stub the setup method

Spying on a constructor using Jasmine

不想你离开。 提交于 2019-11-28 11:52:13
I am using Jasmine to test if certain objects are created and methods are called on them. I have a jQuery widget that creates flipcounter objects and calls the setValue method on them. The code for flipcounter is here: https://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.js The flipcounters are created using: var myFlipCounter = new flipCounter("counter", {inc: 23, pace: 500}); I want to test that the flipcounters are created and the setValue method is called on them. My problem is that how do I spy on these objects even before they are created? Do I spy on

Tracking email with PHP and image

六眼飞鱼酱① 提交于 2019-11-27 17:24:36
I have seen the service like spypig.com placing a small image in the email and tracking when it is opened and from where. They track city, country, IP address etc. How is this done? How do we know when the mail is opened? And how is the image generated? How is the IP address detected and how is it possible to know location from it? Basically, in the HTML body of your email, there will be an <img> tag that would look like this : <img src="http://www.yoursite.com/tracker.php?id=123456" alt="" /> When someone reads his mail, with images enabled, the email-client will send a request to tracker.php

Jasmine - Spying on a method call within a constructor

眉间皱痕 提交于 2019-11-27 17:23:07
I want to test whether the following method is called with in my Javascript object constructor. From what I have seen in the Jasmine documentation, I can spy on a constructor method and I can spy on methods after an object has been instantiated, but I can't seem to be able to spy on a method before the object is constructed. The object: Klass = function() { this.called_method(); }; Klass.prototype.called_method = function() { //method to be called in the constructor. } I want to do something like this in the spec: it('should spy on a method call within the constructor', function() { spyOn

Difference between Mock / Stub / Spy in Spock test framework

試著忘記壹切 提交于 2019-11-27 17:01:04
I don't understand the difference between Mock, Stub, and Spy in Spock testing and the tutorials I have been looking at online don't explain them in detail. Attention: I am going to oversimplify and maybe even slightly falsify in the upcoming paragraphs. For more detailed info see Martin Fowler's website . A mock is a dummy class replacing a real one, returning something like null or 0 for each method call. You use a mock if you need a dummy instance of a complex class which would otherwise use external resources like network connections, files or databases or maybe use dozens of other objects