June 18, 2018

Intro to setting up a BDD framework with VS Code + Gauge + Ruby

With Integrated Development Environments (IDE), I am quick to adopt whatever the rest of the developers on the team use. For Java development, I like IntelliJ IDEA Ultimate Edition. For JavaScript, Atom.io. And for writing the Capybara + Ruby framework, I have also been using Atom. The problem is that the BDD framework we are using at work -- Gauge -- has plugins that help refactor Gauge tests written in Java, but hasn't had anything for refactoring Gauge tests written in Ruby... until now.

With this blog article, I will be investigating Visual Studio Code -- commonly known as VS Code -- and how it helps refactor tests.

Why am I currently using Ruby for my automation framework if the BDD Framework hasn't supported it? Both Chef.io -- what I use to spin up virtual environments -- and GitLab.com -- the code storage / continuous integration environment also uses Ruby.

I've written a bit about Gauge and drafted a quick-and-dirty Gauge + Ruby + Selenium project, on this blog. With this experiment, we will be editing Gauge's built in project, setting up everything on my Windows 10 machine at home.

If you want to view a summary what the gauge-vscode can do, view the official docs on GitHub.

Setting Up VS Code + Ruby + Gauge

Setting up Ruby:

  • To set up the Ruby programming language on a Windows environment, follow the directions on RubyInstaller.org.
  • Note, there are many ways of installing Ruby. Here are a few examples.
  • Make sure to install the bundler gem from Bundle.iogem install bundler

Using Windows? Install Chocolatey:

  • Open the Command Prompt as Administrator
  • Follow instructions for  Install Chocolatey.org, the Windows Package Manager, copying the command text, and pasting it in the Windows command shell. 
  • Close and reopen your command prompt, running, again, as an administrator. 
Install Gauge:
  • Follow the prompts for installing Gauge at https://gauge.org/get-started.html
  • Once you have Chocolatey installed, it is: choco install gauge
  • Is gauge working? Type: gauge -v
Create New Gauge-Ruby project:
  • Create the subfolder where you want to keep the project. For this project, I went to C:\Users\tmaher\ and created a new folder, gauge-ruby. Enter the subfolder.
  • Initialize a new Gauge-Ruby project: gauge init ruby. 
  • After all project dependencies are downloaded and installed from Rubygems.org, make sure you can run the test project: bundle exec gauge run specs/
  • Want to see exactly what is happening? Run the project in verbose mode with -v: bundle exec gauge run specs/ -v
  • Are updates available?: gauge-update ruby
As you can see below, the sample project tallies up vowels "aeiou" (leaving out 'y'), in words such as "Gauge", "Mingle", "Snap", etc.

Output of the Gauge Sample Project.
... If you want to see what the code is doing, and don't feel like setting up a project, you can check out the code produced in the Gauge 0.9.7 project on my GitHub site

Setting up VS Code:

  • Downloads for Windows, Mac, or Linux is on the Code.VisualStudio.com Downloads page. 
  • VS Code wanted me to immediately wanted me to Download Git. I had uninstalled it since I wanted to upgrade to the new version. It provided a handy link to download, and I could set up VS Code as an editor. 
Install the Ruby plugin:
  • The Welcome page displayed a Customize widget that I was able to click in order to see the Exentions: Marketplace. I was able to scroll down to "Ruby" and click to install it. This is from Rubyide's vscode-ruby project. Like Atom.io, VS Code seems fast, lightweight, and able to be customized with various plugins. 
Welcome to VS Code!
Install the VS Code Gauge Plugin:

  • See the square thingy on the bottom? Hover your cursor over it, and it should tell you that it is Extensions. Select that, and search for the keyword "gauge". Select to install it. 

VS Code Welcome Screen

Now that we have everything set up, let's give everything a whirl!

  • Open up VS Code
  • Select File -> Open Folder, and open up your project. Mine was in C:\Users\tmaher\gauge-ruby
What a nice touch, ThoughtWorks! To help get us started, we are presented with a new dashboard. 

The Gauge Dashboard
  • Apply & Reload recommended changes. Add a workspace folder by going to File -> Add Folder to Workspace
  • Open the Command Palette: In VS Code, select View -> Command Palette, type in "Gauge" then select Gauge: Welcome, to go back to the Welcome screen.   
On the Welcome Screen, it provides:
  • Ways to learn the Gauge toolset by providing links to help you learn the Gauge terminologies, and how Gauge uses Markdown.
  • "Run All Specifications" runs the tests from inside VS Code. 
  • How to Report an Issue, Ask a Qustion, Chat, or go the the Google Group forum. 

Running Gauge Tests in VS Code

  • From UI: Opening the Command Palette, typing in "Gauge" and selecting "Gauge: Run All Specifications". You may need to raise the output panel to see the results. By default it only showed one or two lines of output. 
  • From Terminal: On the panel at the bottom, listing Problems, Output, Debug Console, and Terminal, select the Terminal tab. This will show either the Windows PowerShell or the Mac Terminal. Enter: bundle exec gauge run specs/

View Reports
  • Want to see reports? Select where it says "Successfully generated html-report", and it will output the location to the command line. Go there, press the Enter key, and the reports will be entered into your browser. 

I highly advise you to get used to executing things through the Terminal in VS Code, especially if you are used to Windows environments, like I am. The main thing that had been holding me back in my automation development career had been my fear of using the command line. It's easier. It's quicker. And it will get you working in the same way the software developers on your team are working. 

Finding Previously Defined Steps

Let's say you defined a step:

 step 'Vowels in English language are <vowels>.' do |vowels|  
  @vowels = vowels.scan(/./)  

This readable step, full of detail, can be hard to remember, when trying to implement it in a spec file.

If we open up the spec file, specs/example.specs, from the very moment we type a bullet point to add a new step, a popup is displayed showing all the previously designed steps. Enter a few more words, such as "language" and it will filter down to the step "Vowels in English language are..." 

Previously defined specs are shown

Rephrase Test Steps

Gauge uses Markdown as a theme to write tests. Each specification has a heading. Each scenario has a subheading. And each step is captured as a bullet point, which corresponds to a step implementation. 

When a test is executing, the spec takes the language of the step and attempts to match it to a phrase in the step implementation. What happens if you want to make changes to the wording? If you do not find all areas in the specs that match the step definition, things will start failing. 

What if we wanted to rephrase the step definition "The word <word> has <count> vowels." to read as: "There are <count> vowels in the word <word>"?

We could easily do it through the command line! Just like on the command line, we could go to the Terminal and type in:

gauge refactor "The word <word> has <count> vowels." "There are <count> vowels in the word <word>"

... This is a really nice start on a much needed plugin. I hope they come up with one for IntelliJ IDEA + Ruby and RubyMine!

Happy Testing!

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

Twitter | YouTube | LinkedIn | Articles


sasi said...

I have to agree with everything in this post. Thanks for useful sharing information.
Hadoop Training in Chennai
Big data Training in Chennai
Hadoop Training in Bangalore
Big Data Course in Coimbatore
Big data course in bangalore
Big Data Hadoop Training in Bangalore
Big Data Training in Bangalore
Python Training in Bangalore
salesforce training in bangalore
hadoop training in marathahalli
hadoop training in btm

Riya Raj said...

Very informative blog! I am glad that I came across your article. I'm learning a lot from here. Keep us updated by sharing more such blogs.
AWS Training in Chennai
Amazon web services Training in Chennai
AWS course in Chennai
DevOps Training in Chennai
AWS Training in OMR
AWS Training in Porur
AWS training in Adyar
AWS training in Thiruvanmiyur

sridharraj said...

awesome article,content has very informative ideas, waiting for the next update...
Hibernate Training in Chennai
Hibernate course in Chennai
Hibernate Training institute in Chennai
hibernate training in T nagar
hibernate training in Guindy
Spring Training in Chennai
clinical sas training in chennai
DOT NET Training in Chennai
QTP Training in Chennai
LoadRunner Training in Chennai

Janu said...

Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

Jackie Co Kad said...

Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important. Project Center in Chennai It’s what organizations do with the data that matters. Big data can be analyzed for insights that lead to better decisions and strategic business moves.

Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

for ict 99 said...

The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Final Year Projects for CSE.

Software management seeks for decision support to identify technologies like JavaScript that meet best the goals and characteristics of a software project or improvement programme. JavaScript Training in Chennai Accessible experiences and repositories that effectively guide that technology selection are still lacking.

Aim of technology domain analysis is to describe the class of context situations (e.g., kinds of JavaScript software projects) in which a software engineering technology JavaScript Training in Chennai can be applied successfully

The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

Best way to hire it telecom technicians said...

Red Hat Certified Engineer is a professional who has expertise in handling the Red Hat Enterprise Linux System. The Certified Engineer takes care of various tasks such as setting kernel runtime parameters, handling various types of system logging and providing certain kinds of network operability. The professionals must have the ability to install networking services and security on servers running Red Hat Enterprise Linux.

Red Hat Certified Engineer

Admin said...

192.168.l.l is an IP address used by many routers and modems as the default gateway. address can be used by the users to gain the router admin access and configure their routers and networks.

Admin said... IP Address. To access the admin page type into your web browser's address bar or click on the link below.

svrtechnologies said...

Firstly talking about the Blog it is providing the great information providing by you . Thanks for that .Hope More articles from you . Next i want to share some information about Salesforce training in Banglore .

krnphrneseng said...

We provide 24/7 customer service to answer your questions and comments efficiently, polite to ensure you always receive VEGUS168 from our friendly staff.vegus168 โปรโมชั่น

Vietnam Airline said...

Đặt mua vé máy bay tại Aivivu

vé máy bay đi Mỹ giá bao nhiêu

cách săn vé máy bay giá rẻ tết 2021

giá vé máy bay sang canada

giá vé máy bay đi Pháp của Vietnam Airline

giá vé máy bay đi Anh

vé máy bay giá rẻ hôm nay

combo đà lạt ivivu

combo nha trang 4 ngày 3 đêm

xin visa trung quoc o tphcm

office.com/setup said...

Hоw dо ореn-ѕоurсе рrоduсtіvіtу ѕuіtеѕ compare tо MS Office - аnd dоеѕ іt mаkе ѕеnѕе fоr уоur оrgаnіzаtіоn tо сhооѕе frее соmmunіtу software rаthеr thаn Microsoft's commercially licensed оffеrіng? www.office.com/setup www.office.com/setup

Sophia Williams said...

Here I am for the first time, and I found beneficial information. Very nice and well-explained article. Thanks for sharing.
office.com/setup | office.com/setup | Mcafee.com/Activate | www.Mcafee.com/Activate