What is .spec, and is there a way I can use it?

Heya!

I’m working on a new framework that comes with many libraries pre-included. One of those libraries, Roact, has modules inside of it that end with .spec, as shown in the screenshot below:

image

When I opened a spec file, I noticed it looked something like this:

return function()
	local createElement = require(script.Parent.createElement)

	local oneChild = require(script.Parent.oneChild)

	it("should get zero children from a table", function()
		local children = {}

		expect(oneChild(children)).to.equal(nil)
	end)

	it("should get exactly one child", function()
		local child = createElement("Frame")
		local children = {
			foo = child,
		}

		expect(oneChild(children)).to.equal(child)
	end)

	it("should error with more than one child", function()
		local children = {
			a = createElement("Frame"),
			b = createElement("Frame"),
		}

		expect(function()
			oneChild(children)
		end).to.throw()
	end)

	it("should handle being passed nil", function()
		expect(oneChild(nil)).to.equal(nil)
	end)
end

Notice how methods such as it and expect exist without them being explicitly declared by the programmer. Since this was my first time seeing this in all my time on Roblox, I was a bit lost.

I realized through experimentation that if you rename a module to end with .spec, those methods become automatically inherited… sort of.

The most confusing part is that if I call require(something.spec)() on a spec module, I usually get an error saying those said methods do not exist:

image

There is absolutely nothing on the internet I can find that describes what these files do. Does anybody know what they do, and if usable by the frontend user, how to use them?

I appreciate any and all help!

1 Like

This is a file for the BDD-testing unit testing suite developed by Roblox known as TestEZ. Read more here:

https://roblox.github.io/testez/

4 Likes