DEV Community

Phil
Phil

Posted on

The case for Ruby in end-to-end testing

I have been using Ruby for about a decade and am a self-professed "Rubyist". I fully understand when the inventor claimed that Ruby was "made for developer happiness and productivity". I am just happy writing anything in this language.

Selenium WebDriver has other language bindings (Java, JS, Python, C#). Cypress uses JS/TS. Playwright supports bindings other than Ruby 😿. But there is truly something elegant about what Ruby can do for tests. Perhaps I'm vain. Let's look at the below example, where we look to test the required field inputs on Grubhub's login page.

feature "Grubhub Login" do

  scenario "Submitting empty fields produces error messages" do
    visit 'https://www.grubhub.com/login'
    click_button 'Sign in'
    page.should have_text 'Email is required'
    page.should have_text 'Password is required'
  end

end
Enter fullscreen mode Exit fullscreen mode

This is literally all of it. It practically screams Cucumber/Gherkin or even plain old English that a non-programmer would write! It's not very "noisy looking", with its lack of semi-colons, colons, curly braces, and even parentheses. Just a simple do-end block and we have our test.

Here are a few other advantages that I'll rattle off:

  • Ease of adoption. For any SDET or tester that is looking to become more involved with coding, Ruby is an easy language to learn quickly. Teams that I have led in my career have progressed in their SDET paths successfully using Ruby as a gateway to a career in coding.
  • Object Oriented-ness allows for some powerful design patterns to be used as tests grow in scale and complexity.
  • Since everything's an object, we avoid some of the ugliness (subjective, I know) around promises, callbacks, and deep method chaining you might see in Cypress JS tests.
  • At the same time while Ruby is an OOP language, the functional programming aspects are all there. Code re-use is very important in building automated tests.
  • Dependencies are easy to manage with bundler. In a single test suite, we'll have all of our libraries related to WebDriver, DSLs, and even driver executables all ready to go with a simple bundle install. Even remote execution and containerization can be packaged all neat and tidy.
  • Test reporting is also tightly coupled with the suite through the use of rspec as the test runner.

Yes, my bias is showing from miles away. But here, I hope to share the joy that Ruby has brought me that truly makes things easy to read, easy to write, and dare I say it: Fun to develop tests!!

Top comments (0)