Extension:Expect

From MediaWiki.org
Jump to navigation Jump to search

Other languages:
English • ‎norsk bokmål • ‎norsk nynorsk
MediaWiki extensions manual
OOjs UI icon advanced.svg
Expect
Release status: beta
Keepcalms.png
Description Provides extended assertions for Scribunto.
Author(s)
License GNU General Public License 2.0 or later
Download
README, LDoc
Translate the Expect extension
Check usage and version matrix.

Expect provides an extended framework for assertions.

It is based upon compute graphs that are predefined before being used for extensive checks.

Installation[edit]

Expect depends on modules from the Scribunto extension.

  • Download and place the file(s) in a directory called Expect in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'Expect' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage[edit]

The workflow is to define a graph, and then provide arguments to that graph. The definition is done once, but the graph can be reused several times.

-- Load the lib
local expect = require 'expect'

-- Create a few compute graphs
local expectString = expect:create():asType():toBeEqual( 'string' )
local expectNoColon = expect:create():toBeUMatch( '^[^:]*$' )

-- Create an exported hash
local p = {}

-- Add a function
function p.helloWorld( name )
	-- Call the compute graphs
	expectString( name )
	expectNoColon( name )

	-- Should be safe to do whatever now
	return mw.ustring.format( 'Hi there %s!', name )
end

-- Return the exported hash
return p

For further help, see the generated LDoc documentation.

Development[edit]

For recreating the Vagrant-based development environment, see Expect: Topics/Vagrant.

See also[edit]