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.
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 ~
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?
We've covered ThoughtWorks Gauge, a human readable way to set up tests, quite extensively on this blog:
We will be following the documentation in Docs.Gauge.Org for the Latest Installation:
To install Gauge via Homebrew:
Run the command:
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!
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:
-T.J. Maher
Sr. QA Engineer, Software Engineer in Test
Meetup Organizer, Ministry of Testing - Boston
Twitter | YouTube | LinkedIn | Articles
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? 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
- /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- brew install rbenv
- rbenv install --list
- 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
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!
We will be following the documentation in Docs.Gauge.Org for the Latest Installation:
To install Gauge via Homebrew:
- brew install gauge
- gauge install ruby
- gauge install html-report
- gauge install xml-report
Scaffold Initial Gauge-Ruby Project
To build out scaffolding for your first Gauge project:- gauge init ruby
Run the command:
- bundle exec gauge run specs/
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.
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