黄瓜步骤定义文件无法使用在同一项目中的ruby类中重写的关键字puts

时间:2015-07-01 08:44:45

标签: ruby cucumber gherkin

我有一个步骤定义文件,其中包含以下行

puts "Beginning step execution"

在一个名为helper.rb的单独文件(非ruby类)中,我有覆盖掉的put,所以我可以输出带有这样的时间戳的puts

def puts(o)
  timenow = Time.now
  if o.is_a? Array
    msg = timenow.to_s+" OUT: "+o.to_s
  else
    msg = timenow.to_s+" OUT: "+o
  end
  super(msg.black)
end

我得到的错误是

  

2015-06-30 14:44:59 +0100 OUT:错误:未定义的方法<<' for nil:NilClass 2015-06-30 14:44:59 +0100 OUT:/Library/Ruby/Gems/2.0.0/gems/gherkin-2.12.2/lib/gherkin/formatter/json_formatter.rb:89:inwrite “   /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.18/lib/cucumber/formatter/gherkin_formatter_adapter.rb:166:in puts'/Library/Ruby/Gems/2.0.0/gems/cucumber-1.3 .18 / lib / cucumber / ast / tree_walker.rb:181:send_to_all中的inblock'   /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.18/lib/cucumber/ast/tree_walker.rb:179:in each'/Library/Ruby/Gems/2.0.0/gems/cucumber-1.3 0.18 / LIB /黄瓜/ AST / tree_walker.rb:179:insend_to_all”   /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.18/lib/cucumber/ast/tree_walker.rb:173:in broadcast'/Library/Ruby/Gems/2.0.0/gems/cucumber-1.3 0.18 / LIB /黄瓜/ AST / tree_walker.rb:154:输入   /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.18/lib/cucumber/runtime/user_interface.rb:14:in puts'/Library/Ruby/Gems/2.0.0/gems/cucumber-1.3 0.18 / LIB /黄瓜/ rb_support / rb_world.rb:107:输入   /Users/jenkins/workspace/TEST-regression-test_trial_mini/automation/ios/features/support/hooks.rb:104:在'/Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.18/中的块LIB /黄瓜/ core_ext / instance_exec.rb:48:ininstance_exec”   /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.18/lib/cucumber/core_ext/instance_exec.rb:48:in block in cucumber_instance_exec'/ Library/Ruby/Gems/2.0.0/gems/cucumber -1.3.18 / lib目录/黄瓜/ core_ext / instance_exec.rb:69:incucumber_run_with_backtrace_filtering”   /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.18/lib/cucumber/core_ext/instance_exec.rb:36:in cucumber_instance_exec'/Library/Ruby/Gems/2.0.0/gems/cucumber-1.3 0.18 / LIB /黄瓜/ rb_support / rb_hook.rb:14:ininvoke”   /Library/Ruby/Gems/2.0.0/gems/cucumber-1.3.18/lib/cucumber/language_support/language_methods.rb:114:in invoke'/Library/Ruby/Gems/2.0.0/gems/cucumber-1.3 .18 / lib / cucumber / language_support / language_methods.rb:102:execute_before'中的inblock

这种打印错误的方法很好

 def pute(o)
  timenow = Time.now
  if o.is_a? Array
    msg = timenow.to_s+" OUT: "+o.to_s
  else
    msg = timenow.to_s+" OUT: "+o
  end
  Kernel.puts(msg.red)
end

我认为这可能是超级问题,但这种使用warn而不是put进行打印的方法也可以正常工作

def warn(o)
  p "entered warn in gui_helper"
  timenow = Time.now
  if o.is_a? Array
    msg = timenow.to_s+" OUT: "+o.to_s
  else
    msg = timenow.to_s+" OUT: "+o
  end
  super(msg.black)
end

我们已经有很长一段时间使用这个代码了,而这几天前突然就开始发生了,它似乎只影响了我的一些机器。我比较了黄瓜,红宝石,小黄瓜和我们正在使用的其他关键宝石的版本,没有区别。在同一项目中的ruby类中调用puts方法可以正常工作。似乎问题是在步骤定义文件中特别使用关键字PUTS已经停止工作,因为Gherkin认为在write方法中传递的文本是nil?有人想知道为什么会这样吗?

0 个答案:

没有答案