Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Basic Capybara-Gauge: Setup Ruby Environments for The-Internet

This is the second part of a series of blog posts. Care to go back to the beginning? 

With the last part, we analyzed the App Under Test, Dave Haeffner's The-Internet and came up with some test specifications. With this entry, we will be setting up the Ruby environment that will be running the Capybara-Gauge tests.

Although I am developing this project on my Macbook with this example, it is possible to install Ruby, Gauge on a Windows Machine.  See my article, Intro to setting up a BDD framework with VS Code + Gauge + Ruby.



Create New Directory For Capybara-Gauge Project 


Coding projects, I store in my Home directory, under the /src directory. Let's create a new folder for the project, called capybara-gauge. Firing up the Mac Terminal, I can go to Home by using the shortcut to change the directory to it:  cd ~
  • cd ~/src
  • mkdir capybara-gauge
  • cd capybara-gauge

 

Check If Ruby Is Installed

 Do you already have Ruby installed? In the Mac Terminal:
  • ruby -v
... No Ruby version? I like iusing the Ruby Environment manager rbenv to set up the Ruby environment so I can switch back and forth between different Ruby versions. Rbenv uses Bundler to update dependencies.

No Ruby? Install It With RBENV!

Do you have the Homebrew package manager on your Macbook? It installs many helpful packages for the MacOS. Check to see if you have it by:
  • brew -v
If not go to Brew.sh and install it according to the script shown.
  • /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once Homebrew is installed, you can install rbenv with:
  • brew install rbenv 
The latest stable version of Ruby, as of this writing, is Ruby 2.5.1. Make sure it is on the list:
  •  rbenv install --list
The last stable version is "2.5.1" at the time of this writing. To install this version:
  • rbenv install 2.5.1

Bring on the Bundler!

 Want an easy way to update all your Ruby dependencies? Bring on the Bundler! To install Bundler:
  • gem install bundler
 All your Ruby dependencies can be stored in a Gemfile, which you will set to reference  'https://rubygems.org', where people can find, publish, and install Ruby gems.

What is a Ruby gem? From Guides.RubyGems.Org:

"The RubyGems software allows you to easily download, install, and use ruby software packages on your system. The software package is called a 'gem' which contains a packaged Ruby application or library.

"Gems can be used to extend or modify functionality in Ruby applications. Commonly they’re used to distribute reusable functionality that is shared with other Rubyists for use in their applications and libraries. Some gems provide command line utilities to help automate tasks and speed up your work".

... This is like how we used Maven to help build Java projects, storing items in the MvnRepository.com.


From Bundler's GitHub project:

"Bundler makes sure Ruby applications run the same code on every machine.

"It does this by managing the gems that the application depends on. Given a list of gems, it can automatically download and install those gems, as well as any other gems needed by the gems that are listed. Before installing gems, it checks the versions of every gem to make sure that they are compatible, and can all be loaded at the same time. After the gems have been installed, Bundler can help you update some or all of them when new versions become available. Finally, it records the exact versions that have been installed, so that others can install the exact same gems".


... If you also want to learn even more about Bundler, check their site and read, What is Bundler?

Install Gauge-Ruby


We've covered ThoughtWorks Gauge, a human readable way to set up tests, quite extensively on this blog:
  •  Chapter Excerpt: How To Gauge What Your Tests Are Doing
  • A Brief Overview of Gauge, a BDD Automation Framework, brought to you by Thoughtworks!
 ... It is basically Cucumber with bullet points and a Markdown format. We use it at work. Since we have many moving parts where multiple steps need to happen all at once to get environments spun up and agents installed, it suits our needs.

We will be following the documentation in Docs.Gauge.Org for the Latest Installation:

To install Gauge via Homebrew:
  •  brew install gauge
To install the Ruby plugin for Gauge, along with HTML reporting:
  • gauge install ruby
  • gauge install html-report
Want an XML report? Also do:
  • gauge install xml-report

Scaffold Initial Gauge-Ruby Project

To build out scaffolding for your first Gauge project:
  • gauge init ruby
You should receive a message saying: "Successfully initialized the project. Run specifications with "bundle exec gauge run specs/".

Run the command:
  • bundle exec gauge run specs/
... You will see that Ruby gem metadata is fetched from RubyGems.org,  dependencies are resolved, and Bundler installs and updates everything that Gauge needs to run, and installs everything in the subdirectory, /vendor/bundle.

It also runs two mock tests, checking that given a word, it can count vowels in single or multiple words. Need more information? Run the tests in verbose mode!
  • bundle exec gauge run specs/ -v

View The Project


Open the project using your favorite IDE (Integrated Development Environment) or text editor such as RubyMine, Atom.io, VS Code or Sublime Text Editor... Though, at the time of this writing, only VS Code supports a Gauge debugger.

You will see a structure much like this: https://github.com/tjmaher/gauge_0.9.7_default_code

The important parts:
  • Specs: The specifications for your application, used for testing purposes. This is where we will putting the test scenarios we came up with last time. 
  • Step Implementations: Joining the steps listed in the specs with code to act out what is needed in the tests. 
  • Reports: View what passed and what failed in the HTML Reports. 
  • Gemfile: Where we store our Ruby dependencies. 
Next time, now that we have an environment, we will set up Capybara to open up a browser. Happy Testing!

Basic Capybara-Gauge:
  • Part One: Analyzing The-Internet
  • Part Two: Setup Ruby Environment
  • Part Three: Setup Capybara to Test Opening Chrome
  • Part Four: Add Option For Chrome Headless
  • Part Five: Add Test Steps and Spec Implementations
  • Part Six: Setup Chrome and ChromeDriver Logging
  • Part Seven: Rubocop Code Review

-T.J. Maher
Sr. QA Engineer, Software Engineer in Test
Meetup Organizer, Ministry of Testing - Boston

Twitter | YouTube | LinkedIn | Articles


This post first appeared on Adventures In Automation, please read the originial post: here

Share the post

Basic Capybara-Gauge: Setup Ruby Environments for The-Internet

×

Subscribe to Adventures In Automation

Get updates delivered right to your inbox!

Thank you for your subscription

×