Using nodeunit is there an assert to check for false values? Other testing frameworks have something like assertFalse, should I use something like:
test.ok(!shouldBeFalse());
or
test.equals(shouldBeFalse(), false);
Or is there a project that adds a false assertion?
If you want to be sure only boolean false is matched than use strictEqual:
test.strictEqual(shouldBeFalse(), false)
Otherwise equal is ok too.
Related
In tickscript the norwal way to do if else is in the following:
if(condition, true expression, false expression)
However, for the false expression, I want my code to do nothing as in the following:
if(condition, true print("that is true"), false -do nothing- )
I already tried putting some blank and/or deleting false expression part but it did not work.
Is there a way to do that in tickscript?
Is there a way of doing something like this in Gatling:
scenario("Check UUID with regex")
.exec(http("Get UUID")
.get("http://myapp/api/v1/goal/a24e210c-0fc1-44a0-a5ca-9bd5d8d71916")
.check(jsonPath("$.id").is(regex("[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}")))
Basically I want to apply a regex comparison on something returned in a check JSONPath construct.
Peace out!
P.S. I know I can do:
.check(regex("\"id\": \"[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}\"").exists)
There's nothing quite like what you describe, but you can kind of fake it using a transform
.check(jsonPath("$.id")
.find
.transform(id => "[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}".r
.findFirstMatchIn(id) match {
case Some(value) => true
case None => false
}
).is(true)
but if the straight regex check works... I'd go with that
I'm trying to make a conditional statement based on whether a checkbox is checked or not. I've tried something like the following, but it always returns as true.
self.folderactive = QtGui.QCheckBox(self.folders)
self.folderactive.setGeometry(QtCore.QRect(50, 390, 71, 21))
self.folderactive.setObjectName(_fromUtf8("folderactive"))
if self.folderactive.isChecked:
folders.createDir('Desktop')
print "pass"
elif not self.folderactive.isChecked:
folders.deleteDir('Desktop')
print "nopass"
Is there a way to get a bool value of whether a checkbox is checked or not?
self.folderactive.isChecked isn't a boolean, it's a method - which, in a boolean context, will always evaluate to True. If you want the state of the checkbox, just invoke the method:
if self.folderactive.isChecked():
...
else:
...
x = self.folderactive.isChecked()
x will be True or Falseāa Boolean value.
(It's the brackets at the end that make the difference.)
I'm trying to validate an url without domain, just the path and params.
The regular expression that I'm using do most of the work, but It has some errors that I dont know how to prevent (I'm pretty noob with regexp):
/^(\/([\w#!:.?+=&%#!\-\/])+)$/i
The next example are correctly validated
/asd.jsp -> true
/asd/asd.jsp -> true
/asd/asd.jsp?bar=baz&inga=42&quux -> true
/asd/asd.jsp?bar=ba z&inga=42&quux -> false
But this ones arent correct ulrs and them gives me true too:
/asd/asd./jsp -> true :(
/asd/asd.jsp/ -> true :(
/asd./asd.jsp -> true :(
/asd///asd.jsp -> true :(
/asd/asd.jsp&bar=baz?inga=42?quux -> true :(
Do you recommend to use a function instead of a regex?
Very much thanks!
Try this:
^(\\/\\w+)+\\.\\w+(\\?(\\w+=[\\w\\d]+(&\\w+=[\\w\\d]+)+)+)*$
I already escaped special characters, so you can directly use it in java.
By the way, /asd/asd.jsp?bar=baz&inga=42&quux is not a valid URL.
Unescaped Regex:
^(\/\w+)+\.\w+(\?(\w+=[\w\d]+(&\w+=[\w\d]+)+)+)*$
^(\/\w+)+(\.)?\w+(\?(\w+=[\w\d]+(&\w+=[\w\d]+)*)+){0,1}$
VALID:
/test
/test/test
/test.jsp
/test.jsp?v=1
/test.jsp?v=1&v=2
/test/test.jsp?v=1&v=2
INVALID:
/test/test./jsp
/test/test.jsp/
/test./test.jsp
/test///test.jsp
I've got a service, which is using sendJMSMessage method which is provided by jms-grails plugin.
I want to write some unit tests, but I'm not sure how to "mock" this method, so it just does nothing at all.
Any tips?
You can metaClass the method to have it return whatever you want.
#Test
void pluginCode() {
def myService = new MyService()
def wasCalled = false
myService.metaClass.sendJMSMessage = {String message ->
//I like to have an assert in here to test what's being passed in so I can ensure wiring is correct
wasCalled = true
null //this is what the method will now return
}
def results = myService.myServiceMethodThatCallsPlugin()
assert wasCalled
}
I like to have a wasCalled flag when I'm returning null from a metaClassed method because I don't particularly like asserting that the response is null because it doesn't really assure that you're wired up correctly. If you're returning something kind of unique though you can do without the wasCalled flag.
In the above example I used 1 String parameter but you can metaClass out any number/type of parameters to match what actually happens.