AnApprentice
AnApprentice

Reputation: 111080

cucumber - How to use a Method in a Step Definition

I'm learning to use cucumber, in order to test email parsing and am running into an error.

In my step definitions, I have a step defined as follows:

Given /^a email reply from gmail$/ do
  # Get the Raw Email
  raw_email = File.read("#{Rails.root}/features/step_definitions/email_replies/gmail_webapp_standard_1.txt")
  # Send it to the mailingjob to find the reply
  parsed_email = MailingJob.find_reply(raw_email)
  # more stuff will come once the above is working
end

Problem is this errors with:

(::) failed steps (::)

undefined method `find_reply' for MailingJob:Class (NoMethodError)
./features/step_definitions/email_steps.rb:5:in `/^a email reply from gmail$/'
features/ingest_emails.feature:7:in `Given a email reply from gmail'

Failing Scenarios:
cucumber features/ingest_emails.feature:6 # Scenario: GMAIL Web App Email Reply

Any ideas why, I'm new to cucumber so hopefully I'm not missing something to obvious!

Regarding MailingJob, that lives here: /lib/mailing_job.rb

And looks a like this:

class MailingJob < Struct.new(:mailing_id)

  include ActionView::Helpers

  def perform

    begin
      .....
    end
  end


  def find_reply(body)
    # Lots of processing blah blah

    returns body  
  end

Thank you

Upvotes: 0

Views: 969

Answers (1)

Eric Koslow
Eric Koslow

Reputation: 2064

You are calling a class method.

So in mailing_job.rb is should be:

class MailingJob < Struct.new(:mailing_id)

  def self.find_reply(body)
    # Lots of processing blah blah

    returns body  
  end
...
end

Upvotes: 3

Related Questions