Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nedomas/zapata
An Automatic Automated Test Writer
https://github.com/nedomas/zapata
Last synced: 6 days ago
JSON representation
An Automatic Automated Test Writer
- Host: GitHub
- URL: https://github.com/nedomas/zapata
- Owner: Nedomas
- License: mit
- Created: 2014-07-30T18:04:37.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-03-02T14:12:14.000Z (almost 5 years ago)
- Last Synced: 2024-12-16T05:06:38.327Z (13 days ago)
- Language: Ruby
- Homepage:
- Size: 243 KB
- Stars: 414
- Watchers: 15
- Forks: 27
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Zapata
Who has time to write tests? This is a revolutionary tool to make them write
themselves.[![Gem Version](http://img.shields.io/gem/v/zapata.svg?style=flat)][rubygems]
[![Build Status](http://img.shields.io/travis/Nedomas/zapata.svg?style=flat)][travis]
[![Dependency Status](http://img.shields.io/gemnasium/Nedomas/zapata.svg?style=flat)][gemnasium]
[![Coverage Status](http://img.shields.io/coveralls/Nedomas/zapata/master.svg?style=flat)][coveralls]![Emiliano Zapata](https://cloud.githubusercontent.com/assets/1877286/3753719/af3bfec2-1814-11e4-8790-242c2b26a8e9.jpg)
# What is your problem?
There comes a day where you have this bullshit class ``RobotToTest``. We need
tests. :shipit:```ruby
class RobotToTest
def initialize(human_name, cv)
@name = robot_name(human_name)
enddef robot_name(human_name)
"#{self.class.prefix}_#{human_name}"
enddef cv
{ planets: planets }
enddef nested_fun_objects(fun_objects)
'It was fun'
enddef self.prefix
'Robot'
endprivate
def planets
['Mars', Human.home]
enddef fun_objects
[%i(array in array), { hash: nested_hash }]
enddef nested_hash
{ in_hash: { in: array } }
enddef array
%w(array)
end
end# just another class to analyze
class Human
def initialize
human_name = 'Emiliano'
enddef self.home
'Earth'
end
end
```## Solving it
You run ``zapata generate app/models/robot_to_test.rb`` and pop the champagne.
Zapata generated ``spec/models/robot_to_test_spec.rb`` for you.```ruby
describe RobotToTest do
let(:robot_to_test) do
RobotToTest.new('Emiliano', { planets: ['Mars', Human.home] })
endit '#robot_name' do
expect(robot_to_test.robot_name('Emiliano')).to eq('Robot_Emiliano')
endit '#cv' do
expect(robot_to_test.cv).to eq({ planets: ['Mars', 'Earth'] })
endit '#nested_fun_objects' do
expect(robot_to_test.nested_fun_objects([
[:array, :in, :array],
{
hash: {
in_hash: {
in: ['array']
}
}
}
])).to eq('It was fun')
endit '#prefix' do
expect(RobotToTest.prefix).to eq('Robot')
end
end
```## What does it do?
It tries to write a passing RSpec spec off the bat. It does fancy analysis
to predict the values it could feed to the API of a class.__To be more specific:__
- Analyzes all vars and methods definitions in ``app/models``
- Checks what arguments does a testable method in ``app/models/robot_to_test.rb`` need
- Searches for such variable or method name in methods in analyzed
- Selects the most probable value by how many times it was repeated in code
- Runs the RSpec and fills in the expected values of the test with those returned by RSpecFor more things it can currently do check test files
https://github.com/Nedomas/zapata/tree/master/spec## Workflow with Zapata
Say you are writing some new feature on your existing project.
Before writing that, you probably want to test out the current functionality.
But who has time for that?You let *Zapata* create that quick spec for you.
Think of it as a *current functionality lock*.
Write more code and when you're happy with the result - lock it up again.## Requirements
- Ruby 2.1+
- Rails 3.0+## Installation
Add `zapata` to your `Gemfile`. It currently only works if the library is added to the `Gemfile`.
```ruby
gem 'zapata', groups: %w(development test)
```## Usage
To use run
```sh
zapata generate app/models/model_name.rb
```To ignore other files and analyze a single model you want to generate a spec for:
```sh
zapata generate app/models/model_name.rb --single
```## Collaboration :heart:
It is encouraged by somehow managing to bring a cake to your house. I promise,
I will really try.This is a great project to understand language architecture in general. A
project to let your free and expressionistic side shine through by leaving meta
hacks and rainbows everywhere.Thank you to everyone who do. I strongly believe that this can make the
developer job less robotic and more creative.1. [Fork it](https://github.com/Nedomas/zapata/fork)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull RequestTo install, run:
```sh
cd zapata
script/bootstrap
```For specs:
```sh
script/test# or
bundle exec rspec --pattern "spec/*_spec.rb"
```## Awareness
I am well aware that this is featured in [Ruby Weekly 223](http://rubyweekly.com/issues/223).
On that note I'd like to thank everybody who helped it shine through.Special thanks to my comrade [@jpalumickas](https://github.com/jpalumickas), with whom we share a vision of a better world.
Also - thank you [@edgibbs](https://github.com/edgibbs), for being the early contributor.
[@morron](https://github.com/morron) - for caring.Huge thanks to [@marcinruszkiewicz](https://github.com/marcinruszkiewicz) for reviving this gem to life in 2019/2020. Also additional thanks to [@jpalumickas](https://github.com/jpalumickas) for all the extra fixes and modernizing the codebase. This would not be done without you all.
## Copyright
Copyright (c) 2014-2018 Justas, Andrew, Ed, Dmitry, Domas.
See [LICENSE](LICENSE) for details.[rubygems]: https://rubygems.org/gems/zapata
[travis]: http://travis-ci.org/Nedomas/zapata
[gemnasium]: https://gemnasium.com/Nedomas/zapata
[coveralls]: https://coveralls.io/r/Nedomas/zapata
[codeclimate]: https://codeclimate.com/github/Nedomas/zapata