I'm trying to code up a call to a method whose second parameter appears to be a variant (so far as I can tell from the object browser, anyway).
It is customary in the application I am working on to call it like this:-
Call StrangeMethod ("Fred", Array (1, 2, 3, 4))
But when I try to call it like this:-
Dim myArray as Variant
myArray = Array(1, 2, 3, 4)
Call StrangeMethod("Fred", myArray)
the call fails with a Type Mismatch error. What am I doing wrong here and how do I correct it?
Edit
As requested in the comments, the method signature in the object browser is:-
Strangemethod(Path As String, Commands)
Related
I am doing tests and I want to assert that an object that goes to a dependency contains the values I am expecing. For this I have the next piece of code:
foo = Foo.new(1, 10, 0)
dependency = double
expect(dependency).to receive(:function).with(foo)
But this fails, obviously, as in the code I do a Foo.new ... so this object is not the same as the one in the logic. It makes sense, and I get an error like the next:
#<Double (anonymous)> received :function with unexpected arguments
expected: (#<Foo:0x00000000001 #value_1=1, #value_2=10, #value_3=0>)
got: (#<Foo:0x00000000002 #value_1=1, #value_2=10, #value_3=0>)
But the values on the object are the same.
Is there any way of validating only the values and not the object itself?
I can do the following, and it works, but this scenario has just three properties. On a bigger object, this will be a bit of a mess.
expect(dependency).to receive(:function).with(having_attributes(value_1: 1, value_2: 10, value_3: 0)
can this validation be done out of the box?
Thanks.
EDIT1: This is the code that I am trying to test
foo = Foo.new(value_1, value_2, value_3)
#dependency.function(foo)
I am trying to insert an animation into my code for the first time. Here is my code:
1 local player = game.Players.LocalPlayer
2 local char = player.Character or player.CharacterAdded:Wait()
3 local hum = char:WaitForChild("Humanoid")
4
5 local animaInstance = Instance.new("Animation")
6 animaInstance.AnimationId = "rbxassetid://4641537766"
7
8 local fireBallAnim = hum.LoadAnimation(animaInstance)
9 fireBallAnim:Play()
I am getting the error
The function LoadAnimation is not a member of Animation
I know the character has fully loaded, so I don't understand. Could I be getting this error if there is something wrong with the animation itself? What else am I missing out?
Thanks
local fireBallAnim = hum:LoadAnimation(animaInstance)
This is a very confusing message for the error. The only problem is that you've called a member function with a . as opposed to a :. Switching it to a colon will fix your error.
When you call a function on an object with a colon, it is automatically inserting the object as the first argument. A fun example of this can be seen with tables :
-- insert an object into the table 't'
local t = {}
table.insert(t, 1)
-- can also be written as...
t.insert(t, 1)
-- which is the same as...
t:insert(1)
All of these calls do the same thing. Calling the function with : is syntactic sugar for putting the t object as the first argument. So in your code, what's happening is you are calling LoadAnimation like this :
local fireBallAnim = hum.LoadAnimation(<a humanoid object needs to go here>, <animation>)
But since you are passing in the animation where the Humanoid is supposed to go, it is trying to find the LoadAnimation function on the animation object and failing.
I have a method that looks like this:
> rating
=> "speed"
Then I have a call that looks like this:
profile.ratings.find_by(user: current_user).speed
What I want to do is pass the value of rating to that call.
But when I do this:
profile.ratings.find_by(user: current_user).rating
It doesn't work, because there is no method called rating on each ratings object.
This is the error I get when I run the above:
Rating Load (4.5ms) SELECT "ratings".* FROM "ratings" WHERE "ratings"."profile_id" = $1 AND "ratings"."user_id" = 7 LIMIT $2 [["profile_id", 12], ["LIMIT", 1]]
NoMethodError: undefined method `rating' for #<Rating:0x007fca0c4fba90>
I would normally do string interpolation, except now I am working on a method call.
How might I do this?
If you're looking to access a property on an ActiveRecord model they provide a simple accessor:
profile.ratings.find_by(user: current_user)[rating]
This is safer than the send method since it's only going to fetch attributes. If you had a method called ban_and_charge_ten_bucks! some hostile user might be able your system into calling that if you call send without checking what you're calling.
You can use the send method
profile.ratings.find_by(user: current_user).send(rating)
good day.
im testing to see function got all her args.
i know what value two of her args must have,
but for the third arg, i just want to test if it exists.
expect(myFunction).toHaveBeenCalledWithMatcher({
a: 1,
b: 2,
c: dont know its val but want it to exist
});
thanks in advance
You can also use jasmine.any. In case you expect a number it could be:
expect(myFunction).toHaveBeenCalledWith({
a: 1,
b: 2,
c: jasmine.any(Number)
});
It is also possible jasmine.any(Function) and so on. From Jasmine doc:
jasmine.any takes a constructor or “class” name as an expected value. It returns true if the constructor matches the constructor of the actual value.
Try
expect(myFunction.mostRecentCall.args[2]).toBeDefined();
and leave out the argument in the toHaveBeenCalledWith test.
My question involves the use of QTP / VBScript.
Goal: From the qtp main starting file, initialize an array of classes, and pass that array as a parameter to a re-usable action via a parameter.
Problem: I am not able to pass an array of classes to my re-usable action.
Details:
I have two files: “application_main” and “personal_action”.
application_main is the entry point into qtp/vbscript.
personal_action is a re-usable action
Inside application_main, we have a call to InvokeApplication, proceeded by a few other declarations.
I am able to initialize an array and proceed to pass it as a parameter from my application_main to my personal_action:
From application_main:
Dim myArray
myArray = new Array(object1, object2, object3)
RunAction “personal_action”, oneIteration, myInteger, myBoolean, myArray
On the personal_action page, I edit the parameter properties via:
Edit->Action->ActionProperties. I select the Parameters tab.
In it, I have the option to define the amount of incoming parameters and each individual type. These available types seem to be restricted to:
String, Boolean, Date, Number, Password, Any
I set my 1st parameter as: Number
I set my 2nd parameter as: Boolean
I set my 3rd parameter as: Any
Upon running, I am prompted with this:
The type you specified for the ‘myArray’ parameter in your RunAction
statement does not match the type defined in the action.
Question: I am able to pass the Number and Boolean fine, but when an array is involved, qtp/vbscript doesn't seem to handle it well. Why am I not able to pass an array to an action via parameters from the main startup file? This seems like a common and simple task. Could I be so wrong?
Any help is appreciated. Thank you.
As per my knowledge, QTP will NOT allow this. There is no parameter type that can be used to represent an Array. This might be a limitation of QuickTest Professional.
Rather than passing array you can pass the Array elements as a string separated with delimiters.
Example:
"Item1^Item2^............" where "^" is the delimiter
then you can use split function of vb script, to get your array back.
Again doing the same thing with object,we have to give try for this
use lib file in your action ...
Create array public in lib
but in end for any case test or interation vararray=null
rodrigonw.
Sugestion... use function for include your lib in your actions (lib path)
Lib soluction
''######################################LIB"
'lib Passsagem de valores entre array
Dim arrayyy()
Sub setArrayyy(strvalores,redimencionaArray)
On error resume next
tamanho=UBound(arrayyy,1)
If Err.Number=9 then
ReDim arrayyy(0)
redimencionaArray=false
end if
err.Clear
On error goto 0
If redimencionaArray Then
tamanho=tamanho+1
ReDim preserve arrayyy(tamanho)
end if
arrayyy(tamanho)=strvalores
'arrayyy=arrayyy
End Sub
function getArrayyy() getArrayyy=arrayyy End function
''######################################"'Action X
call setArrayyy("X",false)
call setArrayyy("A",true)
call setArrayyy("D",true)
call setArrayyy("B",true)
''######################################'Action y
x=getArrayyy()
for countx=0 to ubound(x)
msgbox x(countx)
next