EasyRspec allows you to build an RSpec test file from scratch with a single command. The RSpec test file will be generated with:
-
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
-
Correct headers describing the class being tested
Original file header:
class Customer < ApplicationRecord
Generated test file header:
describe Customer do
-
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
gem install easy_rspec
Or add to your Gemfile:
gem 'easy_rspec'
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