{"id":13521502,"url":"https://github.com/Nedomas/zapata","last_synced_at":"2025-03-31T20:31:36.928Z","repository":{"id":19205469,"uuid":"22439125","full_name":"Nedomas/zapata","owner":"Nedomas","description":"An Automatic Automated Test Writer","archived":false,"fork":false,"pushed_at":"2020-03-02T14:12:14.000Z","size":249,"stargazers_count":414,"open_issues_count":0,"forks_count":25,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-27T18:11:39.917Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nedomas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-30T18:04:37.000Z","updated_at":"2024-10-19T00:58:34.000Z","dependencies_parsed_at":"2022-08-21T01:50:26.084Z","dependency_job_id":null,"html_url":"https://github.com/Nedomas/zapata","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nedomas%2Fzapata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nedomas%2Fzapata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nedomas%2Fzapata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nedomas%2Fzapata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nedomas","download_url":"https://codeload.github.com/Nedomas/zapata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246535969,"owners_count":20793361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:00:35.230Z","updated_at":"2025-03-31T20:31:36.612Z","avatar_url":"https://github.com/Nedomas.png","language":"Ruby","readme":"# Zapata\n\nWho has time to write tests? This is a revolutionary tool to make them write\nthemselves.\n\n[![Gem Version](http://img.shields.io/gem/v/zapata.svg?style=flat)][rubygems]\n[![Build Status](http://img.shields.io/travis/Nedomas/zapata.svg?style=flat)][travis]\n[![Dependency Status](http://img.shields.io/gemnasium/Nedomas/zapata.svg?style=flat)][gemnasium]\n[![Coverage Status](http://img.shields.io/coveralls/Nedomas/zapata/master.svg?style=flat)][coveralls]\n\n![Emiliano Zapata](https://cloud.githubusercontent.com/assets/1877286/3753719/af3bfec2-1814-11e4-8790-242c2b26a8e9.jpg)\n\n# What is your problem?\n\nThere comes a day where you have this bullshit class ``RobotToTest``. We need\ntests. :shipit:\n\n```ruby\nclass RobotToTest\n  def initialize(human_name, cv)\n    @name = robot_name(human_name)\n  end\n\n  def robot_name(human_name)\n    \"#{self.class.prefix}_#{human_name}\"\n  end\n\n  def cv\n    { planets: planets }\n  end\n\n  def nested_fun_objects(fun_objects)\n    'It was fun'\n  end\n\n  def self.prefix\n    'Robot'\n  end\n\n  private\n\n  def planets\n    ['Mars', Human.home]\n  end\n\n  def fun_objects\n    [%i(array in array), { hash: nested_hash }]\n  end\n\n  def nested_hash\n    { in_hash: { in: array } }\n  end\n\n  def array\n    %w(array)\n  end\nend\n\n# just another class to analyze\nclass Human\n  def initialize\n    human_name = 'Emiliano'\n  end\n\n  def self.home\n    'Earth'\n  end\nend\n```\n\n## Solving it\n\nYou run ``zapata generate app/models/robot_to_test.rb`` and pop the champagne.\nZapata generated ``spec/models/robot_to_test_spec.rb`` for you.\n\n```ruby\ndescribe RobotToTest do\n  let(:robot_to_test) do\n    RobotToTest.new('Emiliano', { planets: ['Mars', Human.home] })\n  end\n\n  it '#robot_name' do\n    expect(robot_to_test.robot_name('Emiliano')).to eq('Robot_Emiliano')\n  end\n\n  it '#cv' do\n    expect(robot_to_test.cv).to eq({ planets: ['Mars', 'Earth'] })\n  end\n\n  it '#nested_fun_objects' do\n    expect(robot_to_test.nested_fun_objects([\n      [:array, :in, :array],\n      {\n        hash: {\n          in_hash: {\n            in: ['array']\n          }\n        }\n      }\n    ])).to eq('It was fun')\n  end\n\n  it '#prefix' do\n    expect(RobotToTest.prefix).to eq('Robot')\n  end\nend\n```\n\n## What does it do?\n\nIt tries to write a passing RSpec spec off the bat. It does fancy analysis\nto predict the values it could feed to the API of a class.\n\n__To be more specific:__\n- Analyzes all vars and methods definitions in ``app/models``\n- Checks what arguments does a testable method in ``app/models/robot_to_test.rb`` need\n- Searches for such variable or method name in methods in analyzed\n- Selects the most probable value by how many times it was repeated in code\n- Runs the RSpec and fills in the expected values of the test with those returned by RSpec\n\nFor more things it can currently do check test files\nhttps://github.com/Nedomas/zapata/tree/master/spec\n\n## Workflow with Zapata\n\nSay you are writing some new feature on your existing project.\nBefore writing that, you probably want to test out the current functionality.\nBut who has time for that?\n\nYou let *Zapata* create that quick spec for you.\nThink of it as a *current functionality lock*.\nWrite more code and when you're happy with the result - lock it up again.\n\n## Requirements\n\n- Ruby 2.1+\n- Rails 3.0+\n\n## Installation\n\nAdd `zapata` to your `Gemfile`. It currently only works if the library is added to the `Gemfile`.\n\n```ruby\ngem 'zapata', groups: %w(development test)\n```\n\n## Usage\n\nTo use run\n```sh\nzapata generate app/models/model_name.rb\n```\n\nTo ignore other files and analyze a single model you want to generate a spec for:\n```sh\nzapata generate app/models/model_name.rb --single\n```\n\n## Collaboration :heart:\n\nIt is encouraged by somehow managing to bring a cake to your house. I promise,\nI will really try.\n\nThis is a great project to understand language architecture in general. A\nproject to let your free and expressionistic side shine through by leaving meta\nhacks and rainbows everywhere.\n\nThank you to everyone who do. I strongly believe that this can make the\ndeveloper job less robotic and more creative.\n\n1. [Fork it](https://github.com/Nedomas/zapata/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\nTo install, run:\n```sh\ncd zapata\nscript/bootstrap\n```\n\nFor specs:\n\n```sh\nscript/test\n\n# or\n\nbundle exec rspec --pattern \"spec/*_spec.rb\"\n```\n\n## Awareness\n\nI am well aware that this is featured in [Ruby Weekly 223](http://rubyweekly.com/issues/223).\nOn that note I'd like to thank everybody who helped it shine through.\n\nSpecial thanks to my comrade [@jpalumickas](https://github.com/jpalumickas), with whom we share a vision of a better world.\nAlso - thank you [@edgibbs](https://github.com/edgibbs), for being the early contributor. \n[@morron](https://github.com/morron) - for caring.\n\nHuge 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.\n\n## Copyright\nCopyright (c) 2014-2018 Justas, Andrew, Ed, Dmitry, Domas.\nSee [LICENSE](LICENSE) for details.\n\n[rubygems]: https://rubygems.org/gems/zapata\n[travis]: http://travis-ci.org/Nedomas/zapata\n[gemnasium]: https://gemnasium.com/Nedomas/zapata\n[coveralls]: https://coveralls.io/r/Nedomas/zapata\n[codeclimate]: https://codeclimate.com/github/Nedomas/zapata\n","funding_links":[],"categories":["Ruby","Tools","Testing"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNedomas%2Fzapata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNedomas%2Fzapata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNedomas%2Fzapata/lists"}