Transforms

334 views
Skip to first unread message

mark lane

unread,
Nov 30, 2017, 2:21:01 PM11/30/17
to Cucumber and Cheese
Hi 

I am having some problems with the Transform.rb file when attempting to run. I seem to be getting the following error:


undefined method `Transform' for main:Object (NoMethodError)

The book doesn't ask me to define this method so I was wondering why I am getting it?

I have saved the file to my Support directory as stated as transformations.rb 

The file itself = 

Transform /^line item (\d+)$/ do |line_string

line_string.to_i

end


 Thaks a lot



Carlito GZ

unread,
Dec 4, 2017, 4:15:13 AM12/4/17
to Cucumber and Cheese
Hi Mark

Did you resolve this problem? What version of Cucumber were you running?

mark lane

unread,
Dec 4, 2017, 7:34:16 AM12/4/17
to Cucumber and Cheese
Hey Carlito ,

It appears that as I am running a latter version of Ruby, Which means Starting with 3.0 of Cucumber Transform has retired.

https://cucumber.io/blog/2017/09/21/upgrading-to-cucumber-3

What I still can't work out is that if number.to_i is now built into version 3, then how would I use this in the Step Definition in the book where it uses the out of date Transform file.

When /^I should see “([^”]*)” as the subtotal for (line item \d+)$/ do |subtotal, line_item|
expect(on(ShoppingCartPage).subtotal_for_line_item(line_item)).to eql subtotal
end

Do I need to define this as a method again?

Thanks 


Mark

Spartan Test Solutions

unread,
Dec 4, 2017, 10:10:16 AM12/4/17
to mark lane, Cucumber and Cheese
Hi Mark

In the newer version of Cucumber it will now give you something along the lines of: 

When("I should see {string} as the subtotal for line item {int}") do |string, int|
  pending # Write code here that turns the phrase above into concrete actions
end

I would refactor your code to the following:

When("I should see {string} as the subtotal for line item {int}") do |string, int|
  expect(on(ShoppingCartPage).subtotal_for_line_item(int)).to eq(string)
end

Please note I'm using RSpec 3.7


Reply all
Reply to author
Forward
0 new messages