ruby-on-rails – Newbie Cucumber挂断了??成功?没有方法错误
发布时间:2020-12-17 04:00:23 所属栏目:百科 来源:网络整理
导读:所以我在“Pragmatic Cucumber”中的第一个项目,我在步骤定义中得到一个未定义的方法错误.错误来自$?成功?不用说我很困惑.我错过了什么宝石? 这是步骤定义 Given /^the input "(.*?)"$/ do |input| @input = inputendWhen /^the calculator is run$/ do @
所以我在“Pragmatic Cucumber”中的第一个项目,我在步骤定义中得到一个未定义的方法错误.错误来自$?成功?不用说我很困惑.我错过了什么宝石?
这是步骤定义 Given /^the input "(.*?)"$/ do |input| @input = input end When /^the calculator is run$/ do @output = 'ruby calc.rb #{@input}' raise('Command failed!') unless $?.success? #$?.success? is failing. look that up. end Then /^the output should be "(.*?)"$/ do |arg1| pending # express the regexp above with the code you wish you had end 这是错误. Feature: Adding Scenario: Add two numbers # features/adding.feature:3 Given the input "2+2" # features/step_definitions/calculator_steps.rb:1 When the calculator is run # features/step_definitions/calculator_steps.rb:5 undefined method `success?' for nil:NilClass (NoMethodError) ./features/step_definitions/calculator_steps.rb:7:in `/^the calculator is run$/' features/adding.feature:5:in `When the calculator is run' Then the output should be "4" # features/step_definitions/calculator_steps.rb:10 Failing Scenarios: cucumber features/adding.feature:3 # Scenario: Add two numbers 1 scenario (1 failed) 3 steps (1 failed,1 skipped,1 passed) 0m0.012s 那么,这里的问题是什么?我知道.success?是对的,为什么不是$?注册?谢谢! 解决方法
您需要使用反引号而不是引号来运行命令:
@output = 'ruby calc.rb #{@input}' 应该: @output = `ruby calc.rb #{@input}` 编辑: 刚试过这个 – 你想要非常小心地使用这个结构. $的价值?不会在Cucumber场景之间清除,因此很容易对先前场景中运行的命令的结果进行断言.您可能希望查看Aruba,它专门针对需要Cucumber执行或断言命令行程序的情况而设计. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |