Project | Ataru |
---|---|
CI | |
Gem Version |
Ataru is a gem that provides a command line tool for testing code samples in the documentation files. You can also integrate ataru in your continuous integration process on Travis CI.
Ataru will check if your documentation is still in sync with the application it was written for. The output of the results has the MiniTest style.
Ataru can read files written in Github Flavoured Markdown, as it uses Kramdown with Github Flavoured Markdown Parser.
Ataru is currently able to test the Ruby code only.
It checks the Ruby syntax and implements assertions (assert_equal
) in place of #=>
and # =>
.
The dependencies of your gem have to be in the range of the latest major versions of:
In most cases, you need to create the setup file (for more info read Setup section).
Add ataru to your project Gemfile.
From the top level of your project execute:
$ bundle install
To create the setup file (for more info read Setup section) execute:
$ bundle exec ataru setup
Finally, execute:
$ bundle exec ataru check
$ bundle exec ataru check PROJECT_ROOT/foo/bar/filename_1.md PROJECT_ROOT/foo/bar/filename_2.md
Check the results.
If this is a file called example.md
:
```ruby
def bad
false
end
def good
true
end
bad #=> true
good #=> true
```
which renders as:
def bad
false
end
def good
true
end
bad #=> true
good #=> true
Check it with ataru:
$ ataru check example.md
Run options: --seed 33946
# Running:
F
Finished in 0.001232s, 811.9236 runs/s, 811.9236 assertions/s.
1) Failure:
#<Class:0x000000033451b8>#test_example_0 [example.md:10]:
Expected: true
Actual: false
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
Add ataru to your project Gemfile.
From the top level of your project execute:
$ bundle install
To create the setup file (for more info read Setup section) execute:
$ bundle exec ataru setup
In your .travis.yml
file add:
script:
- bundle exec rake build
- bundle exec rake ataru check
script:
Now you can commit and push the changes to github.
Check the results of your build.
The setup file has to be created in order to enable ataru to read your project source code and use it for its checks.
What is more, in that file you can write some setup code, that will be run before (and after, shall you want that) each snippet.
If you'd like to use instance variables, define them in setup
method.
If you'd like to clean up after running tests, write your clean up code in teardown
method.
If you like local variables, you can use methods (see example below).
This is ataru_setup.rb
file for an imaginary gem my_fancy_lib
, where instance and local variables @number
and number
are defined:
require 'my_fancy_lib'
module Setup
def setup
@number = 21
end
def teardown
end
def number
12
end
which allows us to use them in the code snippets in README.md
file:
```ruby
assert_equal @number + 1, 22
```
```ruby
assert_equal number + 1, 13
```
Ataru comes with an easy to use generator for creating the setup file. When the generator process is finished, created file is automatically passed to ataru.
To create the setup file execute:
$ bundle exec ataru setup
Open created file in your text editor, do your requires and, optionally, write some setup code. Save the file.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)