Skip to content

Commit

Permalink
adds callfunc once method (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgejecook authored Mar 31, 2022
1 parent 3b1054d commit 5e42076
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 15 deletions.
26 changes: 26 additions & 0 deletions framework/src/source/BaseTestSuite.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,32 @@ namespace rooibos
return fake
end function

' /**
' * @memberof module:BaseTestSuite
' * @name expectOnce
' * @function
' * @instance
' * @description Creates a stub to replace a real method with, which the framework will track. If it was invoked the wrong number of times, or with wrong arguments, it will result in test failure
' * @param {Dynamic} target - object on which the method to be stubbed is found
' * @param {Dynamic} methodName - name of method to stub
' * @param {Dynamic} [expectedArgs=invalid] - array containing the arguments we expect the method to be invoked with
' * @param {Dynamic} [returnValue=invalid] - value that the stub method will return when invoked
' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking
' * @returns {Object} - mock that was wired into the real method
' */
function expectCallFuncOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object
try
args = [methodName]
args.append(expectedArgs)
return m.mock(target, "callFunc", 1, expectedArgs, returnValue, allowNonExistingMethods)
catch error
'bs:disable-next-line
m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber)
return false
end try
return false
end function

' /**
' * @memberof module:BaseTestSuite
' * @name expectOnce
Expand Down
5 changes: 5 additions & 0 deletions framework/src/source/TestRunner.bs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace rooibos
failedText = ""
i = 0
numSuites = suiteNames.count()
testSuite = invalid
for each name in suiteNames
i++
'bs:disable-next-line
Expand Down Expand Up @@ -90,6 +91,10 @@ namespace rooibos
testSuite.scene.statusColor = "#238636"
end if

if testSuite = invalid
m.nodeContext.global.testsScene.failedText = "No tests were found"
end if

m.stats.time = timer.totalMilliseconds()

m.testReporter.reportResults(m.stats)
Expand Down
3 changes: 2 additions & 1 deletion tests/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"activityBar.background": "#143141",
"titleBar.activeBackground": "#1D445B",
"titleBar.activeForeground": "#F7FBFD"
}
},
"brightscript.bsdk": "embedded"
}
4 changes: 2 additions & 2 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"source-map": "^0.7.3"
},
"devDependencies": {
"brighterscript": "^0.37.4"
"brighterscript": "^0.45.6"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,4 +40,4 @@
"scripts": {
"build": "npx bsc"
}
}
}
4 changes: 3 additions & 1 deletion tests/src/source/Assertion.spec.bs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import "pkg:/source/rooibos/BaseTestSuite.bs"

namespace tests

@noEarlyExit
@suite("Rooibos assertion tests")
class AssertionTests extends Rooibos.BaseTestSuite
class AssertionTests extends rooibos.BaseTestSuite

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("tests basic assertions")
Expand Down
20 changes: 19 additions & 1 deletion tests/src/source/Basic.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace tests

@noEarlyExit
@suite
class BasicTests extends Rooibos.BaseTestSuite
class BasicTests extends rooibos.BaseTestSuite

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("equals fix for stubbed aas")
Expand Down Expand Up @@ -178,9 +178,27 @@ namespace tests
m.assertTrue(isFail)

m.assertEqual(msg, "[one, two, three] != [2one, 2two, 2three]")
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("expectCallFunc")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@it("supports expectCallFunc syntax")
function _()
node = { "id" : "node" }

a = 1
b = 2
value = { "id" : "value" }

m.expectCallFuncOnce(node, "getValue", [a, b], value)

result = node@.getValue(a, b)

m.assertEqual(result, value)
end function


end class
end namespace
2 changes: 1 addition & 1 deletion tests/src/source/Common.spec.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace tests

@suite
class Common extends Rooibos.BaseTestSuite
class Common extends rooibos.BaseTestSuite
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("eqArray")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion tests/src/source/Expect.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace tests

@noEarlyExit
@suite
class ExpectTests extends Rooibos.BaseTestSuite
class ExpectTests extends rooibos.BaseTestSuite

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("expectonce bug")
Expand Down
2 changes: 1 addition & 1 deletion tests/src/source/Infinite-looping-fixes.spec.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace tests

@suite
class InfiniteLoopingFixes extends Rooibos.BaseTestSuite
class InfiniteLoopingFixes extends rooibos.BaseTestSuite

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertEquals")
Expand Down
2 changes: 1 addition & 1 deletion tests/src/source/Matcher.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace tests

@noEarlyExit
@suite
class MatcherTests extends Rooibos.BaseTestSuite
class MatcherTests extends rooibos.BaseTestSuite

protected override function beforeEach()
'make a mock class
Expand Down
4 changes: 3 additions & 1 deletion tests/src/source/NodeExample.spec.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace tests
@tags("fixme")
@ignore("not working")
@SGNode("NodeExample")
@suite
class NodeExampleTests extends Rooibos.BaseTestSuite
class NodeExampleTests extends rooibos.BaseTestSuite
protected override function setup()
m.setupThing = "something created during setup"
end function
Expand Down
2 changes: 1 addition & 1 deletion tests/src/source/Params.spec.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace tests

@suite
class ParamsTest extends Rooibos.BaseTestSuite
class ParamsTest extends rooibos.BaseTestSuite
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("params")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion tests/src/source/issue_13_afterEach_not_running.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace tests

@Ignore("only unignore to test compiler works")
@suite
class AfterEachNotRunning extends Rooibos.BaseTestSuite
class AfterEachNotRunning extends rooibos.BaseTestSuite
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("group1")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion tests/src/source/issue_15_tests_only_on_groups.spec.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace tests
'ADD '@Only ON NEXT LINE TO TEST
@suite()
class OnlyOnGroups extends Rooibos.BaseTestSuite
class OnlyOnGroups extends rooibos.BaseTestSuite
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("tests one")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion tests/src/source/issue_5_duplicateGroupNames.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace tests
@Ignore("only unignore to test compiler works - remove REMOVE_THIS to test")
@noEarlyExit
@suite
class DuplicateGroupNames extends Rooibos.BaseTestSuite
class DuplicateGroupNames extends rooibos.BaseTestSuite

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("tests before each and after each are running")
Expand Down
2 changes: 1 addition & 1 deletion tests/src/source/verifyBeforeEachAfterEach.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace tests

@suite
@strict
class VerifyBeforeEachAfterEach extends Rooibos.BaseTestSuite
class VerifyBeforeEachAfterEach extends rooibos.BaseTestSuite

private beforeEachValue
protected override function setup()
Expand Down

0 comments on commit 5e42076

Please sign in to comment.