EasyRspec

Maintainability Test Coverage build status

EasyRspec allows you to build an RSpec test file from scratch with a single command. The RSpec test file will be generated with:

  1. A file path mirroring the path of the file being tested.

    Original file path: app/models/users/customer.rb

    Generated test file path: spec/models/users/customer_spec.rb

  2. Correct headers describing the class being tested

    Original file header: class Customer < ApplicationRecord

    Generated test file header: describe Customer do

  3. Describe blocks for instance and class methods found in the original file

    Original file:

    class Customer < ApplicationRecord
      def name
        if first_name && last_name
          "#{first_name} #{last_name}"
        else
          "Lu Peachem"
        end
      end
    
      def self.always_right?
        false
      end
    end
    

    Generated test file:

    describe Customer do
      describe '#name' do
        context '' do
          it '' do
          end
        end
      end
    
      describe '.always_right?' do
        context '' do
          it '' do
          end
        end
      end
    end
    

    Install

    gem install easy_rspec
    

    Or add to your Gemfile:

    gem 'easy_rspec'
    

    Usage

    Simply type easy_rspec ClassName into the console, where ClassName is the name of the class you'd like to create an RSpec test file for. If, for instance, the name of the class you'd like to create a test file for is Customer, you would type

    easy_rspec Customer
    

    and then press enter.

If a test file already exists at the expected RSpec file path, you will receive an error message and no file will be created nor will the pre-existing file be changed.

EasyRspec only generates tests for files that are located in your app/ directory. If there are multiple files in your app/ directory that match the class you requested, you will be asked to specify which file you were intending to create a test file for:

Which number represents your file path?
0. app/models/users/customer.rb
1. app/models/customer.rb