AutoRSpec

Monica Kosciuk
Jul 23, 2017 · 3 min read

After typing the same shell commands into iTerm over the course of the Unit Testing with RSpec section of Launch Academy’s Ignition Curriculum and after adding the same lines to the top of my Ruby files and .rspec file, I decided to automate all of this legwork.

Meet AutoRSpec, my first of probably many fun (really it’s actually fun to automate something after you’ve written the same lines dozens of times) expeditions into shell scripting for UNIX.

What does it do?

AutoRSpec:

  • Runs bundle init to create a Gemfile for the working directory
  • Adds the pry and rspec gems to the created Gemfile
  • Runs bundle to install the gems within Gemfile and update the Gemfile dependencies
  • Runs rspec — init to initialize the RSpec
  • Add — color to the .rspec file created when RSpec was initialized
  • Asks the user for a file name to create the unit testing Ruby spec file and its counterpart Ruby file that will be tested.
  • Given the name “filename”, creates the following files and folder structure:
 working_directory
|-- lib
| '--- filename.rb
'-- spec
|--- lib
| '--- filename_spec.rb
'--- spec_helper.rb
  • Updates the “filename_spec.rb” file to include require “spec_helper”
  • Updates the “filename_spec.rb” file to include require_relative “../../lib/filename.rb”

Here’s a before and after screenshot of what to expect when running the shell script “create_spec.sh”:

Before AutoRSpec…

After AutoRSpec!

I’m sure as I learn more about shell commands, I’ll refactor this code to remove any unnecessary steps I find, but I feel really happy for now that I was able to think of a way to speed up a process, plan it out, and actually execute my plan to a successful outcome.

Before attending Launch Academy, I rarely used a UNIX terminal, but was pretty familiar with using DCL for OpenVMS, so this was a learning experience and will continue to be so as I write more scripts to automate steps that I think could be performed faster than me typing them in.

Monica Kosciuk

Written by

Full-Stack Developer // Lifelong Learner // Engineer // Climbing Enthusiast // Improviser

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade