Class Protest::TestCase
In: lib/protest/test_case.rb
Parent: Object

A TestCase defines a suite of related tests. You can further categorize your tests by declaring nested contexts inside the class. See TestCase.context.

Methods

assert   assert_equal   assert_raise   context   global_setup   global_teardown   name   new   pending   raise_exceptions?   real?   run   run   setup   teardown   test   tests  

External Aliases

context -> describe
context -> story
setup -> before
teardown -> after
global_setup -> before_all
global_teardown -> after_all
test -> it
test -> should
test -> scenario

Attributes

description  [RW]  Fancy name for your test case, reports can use this to give nice, descriptive output when running your tests.

Public Class methods

Define a new test context nested under the current one. All setup and teardown blocks defined on the current context will be inherited by the new context. This method is aliased as describe and story for your comfort.

Add a setup block that will be run once for the entire test case, before the first test is run.

Keep in mind that while setup blocks are evaluated on the context of the test, and thus you can share state between them, your tests will not be able to access instance variables set in a global_setup block.

This is usually not needed (and generally using it is a code smell, since you could make a test dependent on the state of other tests, which is a huge problem), but it comes in handy when you need to do expensive operations in your test setup/teardown and the tests won‘t modify the state set on this operations. For example, creating large amount of records in a database or filesystem, when your tests will only read these records.

This method is aliased as before_all for your comfort.

Add a teardown block that will be run once for the entire test case, after the last test is run.

Keep in mind that while teardown blocks are evaluated on the context of the test, and thus you can share state between the tests and the teardown blocks, you will not be able to access instance variables set in a test from your global_teardown block.

See TestCase.global_setup for a discussion on why these methods are best avoided unless you really need them and use them carefully.

This method is aliased as after_all for your comfort.

Initialize a new instance of a single test. This test can be run in isolation by calling TestCase#run.

Run all tests in this context. Takes a Runner instance in order to provide output.

Add a setup block to be run before each test in this context. This method is aliased as before for your comfort.

Add a teardown block to be run after each test in this context. This method is aliased as after for your comfort.

Add a test to be run in this context. This method is aliased as it, should and scenario for your comfort.

Tests added to this context.

Public Instance methods

Ensure a condition is met. This will raise AssertionFailed if the condition isn‘t met. You can override the default failure message by passing it as an argument.

Passes if expected == actual. You can override the default failure message by passing it as an argument.

Passes if the code block raises the specified exception. If no exception is specified, passes if any exception is raised, otherwise it fails. You can override the default failure message by passing it as an argument.

Name of the test

Make the test be ignored as pending. You can override the default message that will be sent to the report by passing it as an argument.

Tests must not re-raise exceptions

This is a real test

Run a test in isolation. Any setup and teardown blocks defined for this test case will be run as expected.

You need to provide a Runner instance to handle errors/pending tests/etc.

If the test‘s block is nil, then the test will be marked as pending and nothing will be run.

[Validate]