This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
257 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
## Inside Tests | ||
|
||
### describe | ||
``` | ||
describe(phrase, callback) | ||
``` | ||
|
||
This function creates a new `describe` block. These blocks correspond to the **things** that are being tested. | ||
|
||
Put `it` blocks inside of `describe` blocks to describe what behavior should be correct. | ||
|
||
For example: | ||
|
||
```lua | ||
describe("This cheese", function() | ||
it("should be moldy", function() | ||
expect(cheese.moldy).to.equal(true) | ||
end) | ||
end) | ||
``` | ||
|
||
### it | ||
``` | ||
it(phrase, callback) | ||
``` | ||
|
||
This function creates a new 'it' block. These blocks correspond to the **behaviors** that should be expected of the thing you're testing. | ||
|
||
For example: | ||
|
||
```lua | ||
it("should add 1 and 1", function() | ||
expect(1 + 1).to.equal(2) | ||
end) | ||
``` | ||
|
||
### itFOCUS and itSKIP | ||
``` | ||
itFOCUS(phrase, callback) | ||
itSKIP(phrase, callback) | ||
``` | ||
|
||
These methods are special versions of `it` that automatically mark the `it` block as *focused* or *skipped*. They're necessary because `FOCUS` and `SKIP` can't be called inside `it` blocks! | ||
|
||
### FOCUS | ||
``` | ||
FOCUS() | ||
``` | ||
|
||
When called inside a `describe` block, `FOCUS()` marks that block as *focused*. If there are any focused blocks inside your test tree, *only* focused blocks will be executed, and all other tests will be skipped. | ||
|
||
When you're writing a new set of tests as part of a larger codebase, use `FOCUS()` while debugging them to reduce the amount of noise you need to scroll through. | ||
|
||
For example: | ||
|
||
```lua | ||
describe("Secret Feature X", function() | ||
FOCUS() | ||
|
||
it("should do something", function() | ||
end) | ||
end) | ||
|
||
describe("Secret Feature Y", function() | ||
it("should do nothing", function() | ||
-- This code will not run! | ||
end) | ||
end) | ||
``` | ||
|
||
!!! note | ||
`FOCUS` does not work inside an `it` block. The bodies of these blocks aren't executed until the tests run, which is too late to change which tests will run. | ||
|
||
### SKIP | ||
``` | ||
SKIP() | ||
``` | ||
|
||
This function works similarly to `FOCUS()`, except instead of marking a block as *focused*, it will mark a block as *skipped*, which stops any of the test assertions in the block from being executed. | ||
|
||
!!!note | ||
`SKIP` does not work inside an `it` block. The bodies of these blocks aren't executed until the tests run, which is too late to change which tests will run. | ||
|
||
### expect | ||
``` | ||
expect(value) | ||
``` | ||
|
||
Creates a new `Expectation`, used for testing the properties of the given value. | ||
|
||
Expectations are intended to be read like English assertions. These are all true: | ||
|
||
```lua | ||
-- Equality | ||
expect(1).to.equal(1) | ||
expect(1).never.to.equal(2) | ||
|
||
-- Nil checking | ||
expect(1).to.be.ok() | ||
expect(false).to.be.ok() | ||
expect(nil).never.to.be.ok() | ||
|
||
-- Type checking | ||
expect(1).to.be.a("number") | ||
expect(newproxy(true)).to.be.a("userdata") | ||
|
||
-- Function throwing | ||
expect(function() | ||
error("nope") | ||
end).to.throw() | ||
|
||
expect(function() | ||
-- I don't throw! | ||
end).never.to.throw() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Often during development, you'll want to only run the test that's concerned with the specific code you're working on. | ||
|
||
TestEZ provides the `SKIP()` and `FOCUS()` functions to either skip or focus the block that the call is contained in. | ||
|
||
This mechanism does not work for `it` blocks; use `itSKIP` and `itFOCUS` instead. Code inside `it` blocks is not run until tests are executed, while `describe` blocks are run immediately to figure out what tests a project contains. | ||
|
||
For example, you might want to run the tests targeting a specific method or two for a `DateTime` module: | ||
|
||
`DateTime.spec.lua` | ||
```lua | ||
return function() | ||
describe("new", function() | ||
FOCUS() | ||
|
||
it("does really important things", function() | ||
-- This block will run! | ||
end) | ||
end) | ||
|
||
itFOCUS("has all methods we expect", function() | ||
-- Calling FOCUS() would be too late here, so we use itFOCUS instead. | ||
|
||
-- This block will run, too | ||
end) | ||
|
||
describe("Format()", function() | ||
it("formats things", function() | ||
-- This block will never run! | ||
end) | ||
end) | ||
end | ||
``` | ||
|
||
!!! warning | ||
`FOCUS` and `SKIP` are intended exclusively for development. It's not recommended that tests containing these calls are checked into version contorl. | ||
|
||
Future versions of TeztEZ will be able to detect this when running in a CI system and fail tests to prevent that from happening. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*In the future, TestEZ will have pre-built model files for use within Roblox without other tools.* | ||
|
||
### Method 1: Rojo (Roblox) | ||
* Copy the `lib` directory into your codebase | ||
* Rename the folder to `TestEZ` | ||
* Use [Rojo](https://github.com/LPGhatguy/rojo) to sync the files into a place | ||
|
||
### Method 2: Lemur (CI Systems) | ||
You can use [Lemur](https://github.com/LPGhatguy/Lemur) paired together with a regular Lua 5.1 interpreter to run tests written with TestEZ. | ||
|
||
This is the best approach when testing Roblox Lua libraries using existing continuous integration systems like Travis-CI. We use this technique to run tests for [Rodux](https://github.com/Roblox/Rodux) and other libraries. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
TestEZ provides a convenient method to run tests in a single pass: | ||
|
||
```lua | ||
local TestEZ = require(<path to TestEZ>) | ||
|
||
TestEZ.TestBootstrap:run(MY_TESTS) | ||
``` | ||
|
||
The method also returns information about the test run that can be used to take further action! | ||
|
||
The internals of TestEZ are being reworked, so accessing other APIs at this time isn't recommended. |
Oops, something went wrong.