黄瓜 - 如何在步骤定义中使用方法

时间:2011-03-14 19:34:42

标签: ruby-on-rails ruby-on-rails-3 cucumber

我正在学习使用黄瓜,以便测试电子邮件解析并遇到错误。

在我的步骤定义中,我的步骤定义如下:

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

问题是这个错误:

(::) 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

任何想法为什么,我是黄瓜新手所以希望我不会错过任何明显的东西!

关于MailingJob,它位于:/lib/mailing_job.rb

看起来像这样:

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

谢谢

1 个答案:

答案 0 :(得分:3)

您正在调用类方法。

所以在mailing_job.rb应该是:

class MailingJob < Struct.new(:mailing_id)

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

    returns body  
  end
...
end