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 easytestDocumentation
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
endThen, 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 secondsOops. Let's fix the failure:
- expect(1 + 2).to_eq 2
+ expect(1 + 2).to_eq 3Then, run it again:
$ easytest
PASS test/addition_test.rb
Tests: 1 passed, 1 total (1 files)
Time: 0.00077 secondsThe 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...
endSkip
If you want to skip any cases, you can change test to skip:
- test "addition" do
+ skip "addition" doSkipped 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" doOnly 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 --watchThis watch mode is useful during development.