DEV Community

Discussion on: Zero tests → App with tests?

Collapse
 
kyleboe profile image
Kyle Boe • Edited

We use rspec-jumpstart for our clients who need test coverage help before beginning a Rails upgrade.

GitHub logo tjchambers / rspec-jumpstart

RSpec 3 code generator toward existing Ruby code.

rspec-jumpstart

RSpec 3 code generator toward existing Ruby code. This gem will help you working on existing legacy code which has no tests.

Build Status Maintainability

Installation

rubygems.org/gems/rspec-jumpstart

gem install rspec-jumpstart

Usage

rspec-jumpstart ./app
rspec-jumpstart ./lib
rspec-jumpstart ./lib/yourapp/util.rb

Options

$ rspec-jumpstart -h
Usage: rspec-jumpstart [options]
    -f                               Create if absent or append to the existing spec
        --force
    -n                               Dry run mode (shows generated code to console)
        --dry-run
    -r                               Run in Rails mode
        --rails
    -o VAL                           Output directory (default: ./spec)
        --output-dir VAL
    -D VAL                           Delta template path (e.g. ./rails_controller_delta.erb)
        --delta-template VAL
    -F VAL                           Full template path (e.g. ./rails_controller_full.erb)
        --full-template VAL
    -v                               Print version
        --version

Output example

Unfortunately, lib/foo/bar_baz.rb has no test. That's too bad...

module Foo
  class BarBaz
    def self.xxx(a, b = "aaa")
    end
    def yyy
    end
    private

    def zzz(a)
    end

  end
end

OK, run rspec-jumpstart now!

$ rspec-jumpstart lib/foo/bar_baz.rb
./spec/foo/bar_baz_spec.rb created.

spec/foo/bar_baz_spec.rb will be created…

Collapse
 
ark profile image
Ark Shraier

wow, that's what I was looking for 👏. Will give it a try!

Maybe there's something to generate factory_bot factories from existing models?