简体   繁体   English

是否可以从红宝石方法中调用黄瓜步骤?

[英]Is it possible to call cucumber step from ruby method?

It's possible to call cucumber step from step definition . 可以从步骤定义中调用黄瓜步骤 I'd want to call step from ordinary ruby method, ie: 我想从普通的ruby方法调用step,即:

module MyHelpers
  def self.my_method
    step %{My step}
  end
end

Currently when I do it, I have 目前,当我这样做时

undefined method `step' for MyHelpers:Module (NoMethodError)

Is it possible to invoke step from Ruby method? 是否可以从Ruby方法调用step?

I don't think you can call step on ruby methods. 我不认为您可以调用ruby方法。 Since "step" is for repeating for step definition on cucumber using capybara gem. 由于“步骤”用于重复使用水豚宝石对黄瓜进行步骤定义。

Better way to call your method again without repeating just define it as global method and call it. 更好的方法来再次调用您的方法而无需重复,只需将其定义为全局方法并调用它即可。

In order to call one step definition from another step definition do this: 为了从另一个步骤定义中调用一个步骤定义,请执行以下操作:

And(/^I delete the integration quote$/) do 和(/ ^我删除积分报价$ /)
step "I delete the quote" 步骤“我删除报价”
end 结束

And(/^I delete the quote$/) do end 并且(/ ^我删除报价$ /)结束

Important to remember is the "And", "When" and "Then" is inherited, ie I cannot do this 要记住的重要一点是“ And”,“ When”和“ Then”是继承的,即我不能这样做

Then(/^I delete the integration quote$/) do 然后(/ ^我删除积分报价$ /)
step "And I delete the quote" 步骤“我删除报价”
end 结束

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM