ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - Nedomas/zapata: An Automatic Automated Test Writer
An Automatic Automated Test Writer. Contribute to Nedomas/zapata development by creating an account on GitHub.
Visit Site

GitHub - Nedomas/zapata: An Automatic Automated Test Writer

GitHub - Nedomas/zapata: An Automatic Automated Test Writer

Zapata

Who has time to write tests? This is a revolutionary tool to make them write themselves.

Gem Version Build Status Dependency Status Coverage Status

Emiliano Zapata

What is your problem?

There comes a day where you have this bullshit class RobotToTest. We need tests. :shipit:

class RobotToTest
  def initialize(human_name, cv)
    @name = robot_name(human_name)
  end

  def robot_name(human_name)
    "#{self.class.prefix}_#{human_name}"
  end

  def cv
    { planets: planets }
  end

  def nested_fun_objects(fun_objects)
    'It was fun'
  end

  def self.prefix
    'Robot'
  end

  private

  def planets
    ['Mars', Human.home]
  end

  def fun_objects
    [%i(array in array), { hash: nested_hash }]
  end

  def nested_hash
    { in_hash: { in: array } }
  end

  def array
    %w(array)
  end
end

# just another class to analyze
class Human
  def initialize
    human_name = 'Emiliano'
  end

  def 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.

describe RobotToTest do
  let(:robot_to_test) do
    RobotToTest.new('Emiliano', { planets: ['Mars', Human.home] })
  end

  it '#robot_name' do
    expect(robot_to_test.robot_name('Emiliano')).to eq('Robot_Emiliano')
  end

  it '#cv' do
    expect(robot_to_test.cv).to eq({ planets: ['Mars', 'Earth'] })
  end

  it '#nested_fun_objects' do
    expect(robot_to_test.nested_fun_objects([
      [:array, :in, :array],
      {
        hash: {
          in_hash: {
            in: ['array']
          }
        }
      }
    ])).to eq('It was fun')
  end

  it '#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 RSpec

For 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.

gem 'zapata', groups: %w(development test)

Usage

To use run

zapata generate app/models/model_name.rb

To ignore other files and analyze a single model you want to generate a spec for:

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
  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 Request

To install, run:

cd zapata
script/bootstrap

For specs:

script/test

# or

bundle exec rspec --pattern "spec/*_spec.rb"

Awareness

I am well aware that this is featured in Ruby Weekly 223. On that note I'd like to thank everybody who helped it shine through.

Special thanks to my comrade @jpalumickas, with whom we share a vision of a better world. Also - thank you @edgibbs, for being the early contributor. @morron - for caring.

Huge thanks to @marcinruszkiewicz for reviving this gem to life in 2019/2020. Also additional thanks to @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 for details.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory