Skip to content

Create customized RSpec templates for pre-existing files with a single command

License

Notifications You must be signed in to change notification settings

jasonmattingly/easy_rspec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyRspec

Maintainability Test Coverage Gem Version 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.has_account?
        false
      end
    end

    Generated test file:

    describe Customer do
      describe '#name' do
        context '' do
          it '' do
          end
        end
      end
    
      describe '.has_account?' 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

About

Create customized RSpec templates for pre-existing files with a single command

Resources

License

Stars

Watchers

Forks

Packages

No packages published