简体   繁体   English

这个rspec测试有什么问题

[英]What's wrong with this rspec test

I have a helper class in rails that has a method like this: 我在rails中有一个辅助类,该类具有以下方法:

def doSomething(name, *args)
 result = ""
 args.each do |arg|
  if (name == 'something')
   result += arg
  end
 end 
 result
end

My rspec method to test is like this: 我要测试的rspec方法是这样的:

it "Should return a hex array for normal input" do
  expect(helper.doSomething("somename", 1, 2,3, 4,5)).to eq("")
end

When I run the rspec I run into the following error: 当我运行rspec时,遇到以下错误:

ArgumentError: wrong number of arguments(1 for 0) ArgumentError:参数数量错误(1代表0)

What am I doing wrong here? 我在这里做错了什么? Any help is appreciated. 任何帮助表示赞赏。

EDIT:::: 编辑::::

Sorry folks this is not the complete code. 抱歉,这不是完整的代码。 I tried to create something similar but in correcting my previous code I discovered the error in some other part. 我尝试创建类似的内容,但是在更正先前的代码时,我在其他部分发现了该错误。

It would be great if you could include the stack trace from the error as well. 如果您还可以包括错误中的堆栈跟踪信息,那将是很好的。 Your test looks correct except for the fact that you are trying to add fixnums to a string at result += arg , which will result in an implicit conversion error. 您的测试看起来正确,除了您尝试在result += arg处向字符串添加fixnums的事实之外,这将导致隐式转换错误。

I'd say fix that first, and if the problem still exists, please post additional information. 我先说要解决此问题,如果问题仍然存在,请发布其他信息。

I think you're missing array syntax in your rspec method. 我认为您在rspec方法中缺少数组语法。

Right now your doSomething method has 6 arguments in rspec when it should have 2 arguments(which it does when you establish it in your helper). 现在,您的doSomething方法在rspec中应该有2个参数(在您的帮助器中建立它时才这样做)有6个参数。 Try to refactor this part of your rspec test ("somename", 1, 2,3, 4,5) *The numbers should be in array syntax. 尝试重构rspec测试的这一部分(“ somename”,1、2、3、4、5)*数字应采用数组语法。

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

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