Project

easy_rspec

0.0
No commit activity in last 3 years
No release in over 3 years
Create customized RSpec templates with a single command
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
>= 0
>= 0
~> 10.0
~> 3.0
 Project Readme

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