README.md in petitest-0.2.1 vs README.md in petitest-0.3.0
- old
+ new
@@ -3,10 +3,12 @@
[![Gem Version](https://badge.fury.io/rb/petitest.svg)](https://rubygems.org/gems/petitest)
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/github/petitest/petitest)
A minimal solid testing framework for Ruby.
+![demo](/images/demo.png)
+
## Installation
Add this line to your application's Gemfile:
```ruby
@@ -25,87 +27,236 @@
gem install petitest
```
## Usage
-### 1. Write test cases
+### Create your test file
-Define a child class of `Petitest::TestGroup` with `#test_xxx` methods.
+Define a child class of `Petitest::Test` with `#test_xxx` methods.
```ruby
require "petitest/autorun"
-class Sometest < Petitest::TestGroup
- def test_empty_string
- assert("")
+class ExampleTest < Petitest::Test
+ def test_addition
+ assert { 1 + 1 == 100 }
end
+end
+```
- def test_false
- assert(false)
- end
+### Run it
- def test_nil
- assert(nil)
- end
+Run your test file as a Ruby script:
- def test_raise
- raise
+```bash
+ruby test/example_test.rb
+```
+
+```
+PetitestTest
+ #test_one_plus_one_to_be_two
+
+
+Counts:
+
+ 1 tests
+ 1 passes
+ 0 failures
+ 0 skips
+
+Times:
+
+ Started: 2017-03-25T15:29:21.243918+09:00
+ Finished: 2017-03-25T15:29:21.244149+09:00
+ Total: 0.000231s
+```
+
+If any test failed, exit code 1 is returned, othewise 0.
+
+```bash
+echo $?
+```
+
+```
+0
+```
+
+## Assertions
+
+Petitest provides only one assertion method, `#assert`.
+
+```ruby
+assert { foo }
+```
+
+If you need more assertions, use plugins like [patitest-assertions](https://github.com/petitest/petitest-assertions).
+
+## DSL
+
+If you want to use `#desc`, `#test` and `#sub_test` DSL, extend `Petitest::DSL` into your test class.
+
+```ruby
+class ExampleTest < Petitest::Test
+ extend ::Petitest::DSL
+
+ test "foo" do
+ assert { foo }
end
- def test_true
- assert(true)
+ desc "fuba"
+ def test_fuba
+ assert { fuba }
end
- def test_zero
- assert(0)
+ sub_test "bar" do
+ test "baz" do
+ assert { baz }
+ end
+
+ sub_test "boo" do
+ test "boz" do
+ assert { boz }
+ end
+ end
end
end
```
-### 2. Run tests
+## Configuration
-Run your test file as a Ruby script:
+### backtrace_filters
-```bash
-ruby test/sometest_test.rb
+Mechanism for filter out unnecessary lines from error backtrace.
+Each element must be able to respond to `#===` method.
+
+```ruby
+Petitest.configuration.backtrace_filters = [
+ -> (line) { line.start_with?("/path/to/petitest/lib") },
+]
```
+### color
+
+Enable colored output.
+
+```ruby
+Petitest.configuration.color = true
```
-.FFF..
-Failures:
+### color_scheme
- 1) PetitestTest#test_false
- assert(false)
- Expected false to be truthy
- # test/petitest_test.rb:9:in `test_false'
+Color scheme for colored output.
- 2) PetitestTest#test_nil
- assert(nil)
- Expected nil to be truthy
- # test/petitest_test.rb:13:in `test_nil'
+```ruby
+Petitest.configuration.color_scheme = {
+ detail: :cyan,
+ error: :red,
+ pass: :green,
+ skip: :yellow,
+}
+```
- 3) PetitestTest#test_raise
- raise
- RuntimeError
+These color types are available on color scheme configuration:
- # test/petitest_test.rb:17:in `test_raise'
+- `:black`
+- `:blue`
+- `:bold`
+- `:cyan`
+- `:green`
+- `:magenta`
+- `:red`
+- `:white`
+- `:yellow`
-Counts:
+### output
- 6 tests
- 3 passes
- 3 failures
- 0 skips
+Output path for some subscribers.
-Times:
+```ruby
+Petitest.configuration.output = ::STDOUT
+Petitest.configuration.output.sync = true
+```
- Started: 2017-03-24T03:09:17.776418+09:00
- Finished: 2017-03-24T03:09:17.776527+09:00
- Total: 0.000109s
+### subscribers
+
+Test event subscribers (test reporters are kind of subscribers).
+
+```ruby
+Petitest.configuration.subscribers = [
+ ::Petitest::Subscribers::DocomentReportSubscriber.new,
+]
```
-## Plug-ins
+These subscribers are provided by default:
+- `Petitest::Subscribers::DocumentReportSubscriber` (default)
+- `Petitest::Subscribers::JsonReportSubscriber`
+- `Petitest::Subscribers::ProgressReportSubscriber`
+
+## Official Plugins
+
+Here are some official plugins for Petitest:
+
- https://github.com/petitest/petitest-assertions
- https://github.com/petitest/petitest-power_assert
- https://github.com/petitest/petitest-tap
+
+## For developers
+
+### Tree
+
+```
+TestPlan
+|---Test 1
+|---Test 2
+|---Test 3
+|---TestGroup 1
+| |---Test 1-1
+| |---Test 1-2
+| |---Test 1-3
+| `---TestGroup1-1
+| |---Test 1-1-1
+| |---Test 1-1-2
+| `---Test 1-1-3
+|---TestGroup2
+| |---Test 2-1
+| |---Test 2-2
+| `---Test 2-3
+`---TestGroup3
+ |---Test 3-1
+ |---Test 3-2
+ |---Test 3-3
+ `---TestGroup3-1
+ |---Test 3-1-1
+ |---Test 3-1-2
+ `---Test 3-1-3
+```
+
+### Order
+
+1. Test 1
+1. Test 2
+1. Test 3
+1. Test 1-1
+1. Test 1-2
+1. Test 1-3
+1. Test 1-1-1
+1. Test 1-1-2
+1. Test 1-1-3
+1. Test 2-1
+1. Test 2-2
+1. Test 2-3
+1. Test 3-1
+1. Test 3-2
+1. Test 3-3
+1. Test 3-1-1
+1. Test 3-1-2
+1. Test 3-1-3
+
+### Events
+
+- `#before_running_test_plan(test_plan)`
+- `#before_running_test_group(test_group)`
+- `#before_running_test(test)`
+- `#after_running_test(test)`
+- `#after_running_test_group(test_group)`
+- `#after_running_test_plan(test_plan)`