Joseph Ishak
Joseph Ishak

Reputation: 1276

Trying to change Ruby Cucumber Transforms Code to Cucumber 3.0.0 Replacement

I recently found this old project for setting up ruby, cucumber, and capybara on this page: jonathanchrisp/capybara-cucumber-ruby-kickstarter

I was able to fix some runtime errors by adding the following line in support/env.rb

require 'capybara/dsl'

However, whenever I run "cucumber" to run the code, it always fails with

undefined method `open_google_maps' for "google maps":String (NoMethodError)

I think the problem is that the "Transforms" code in features/step_definitions/transforms.rb was deprecated in cucumber 3.0.0. The code I am looking at is over 3 years old so I am not sure if the original author will still maintain it. I did reach out to him. In the meantime, I was wondering if there is a Rub/Cucumber expert who can tell me what is the proper way to change the old transform code from:

Transform(/^google maps$/) do |impersonator|
  google_maps
end

Transform(/^the user$/) do |impersonator|
  @current_user
end

Transform(/^a anonymous user$/) do |impersonator|
  a_anonymous_user
end

to something that works in cucumber 3.0.0 and later.

Upvotes: 1

Views: 371

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49910

Transforms were removed from Cucumber 3 and you need to swap over to using ParameterTypes. How to do that is documented in the 'Upgrading to Cucumber 3' blog post at https://cucumber.io/blog/2017/09/21/upgrading-to-cucumber-3 .

For your first transform above it would be something like

ParameterType(
  name: 'GoogleMaps'
  regexp: /google maps/,
  transformer: -> (_) { google_maps }
end

Upvotes: 1

Related Questions