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.
context | -> | describe |
context | -> | story |
setup | -> | before |
teardown | -> | after |
global_setup | -> | before_all |
global_teardown | -> | after_all |
test | -> | it |
test | -> | should |
test | -> | scenario |
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.
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.