Easytest¶ ↑
makes you write tests easily
Easytest is a tiny testing framework for Ruby with a familiar DSL.
Installation¶ ↑
Add this line to your Gemfile for Bundler:
gem "easytest"
Or install it via gem:
gem install easytest
Documentation¶ ↑
You can read more about Easytest on the official website.
Usage¶ ↑
This section explains easy usage.
First, put test/addition_test.rb as below:
require "easytest" extend Easytest::DSL test "addition" do expect(1 + 2).to_eq 2 end
Then, run easytest:
$ easytest
FAIL test/addition_test.rb
✕ addition (should equal)
Expected: 2
Received: 3
# test/addition_test.rb:6:in `block in <top (required)>'
Tests: 1 failed, 0 passed, 1 total (1 files)
Time: 0.00087 seconds
Oops. Let’s fix the failure:
- expect(1 + 2).to_eq 2 + expect(1 + 2).to_eq 3
Then, run it again:
$ easytest PASS test/addition_test.rb Tests: 1 passed, 1 total (1 files) Time: 0.00077 seconds
The test now passes! 🎉
Hooks¶ ↑
You can add hooks called before and after to each test case:
before do # set up something... end after do # clean up something... end test "something" do # test something... end
Skip¶ ↑
If you want to skip any cases, you can change test to skip:
- test "addition" do + skip "addition" do
Skipped cases will be reported as “skipped”.
Only¶ ↑
If you want to run only any cases, you can use test to only:
- test "addition" do + only "addition" do
Only cases with only will be run, and other cases will be skipped.
To-do¶ ↑
If you want to write to-do cases, you can use test without a block:
test "addition"
To-do cases will be reported as “todo”.
Watch¶ ↑
If you want to run tests immediately when changing code, specify the --watch option:
easytest --watch
This watch mode is useful during development.