[英]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 关于MailingJob,它位于以下位置:/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 谢谢
You are calling a class method. 您正在调用类方法。
So in mailing_job.rb is should be: 因此在mailing_job.rb中应该是:
class MailingJob < Struct.new(:mailing_id)
def self.find_reply(body)
# Lots of processing blah blah
returns body
end
...
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.