[英]wrong number arguments (0 for 1) (ArgumentError)
看起來rspec並未將任何參數傳遞給該方法,即使它們已寫入spec文件中也是如此。
方法:
def echo(msg)
msg
end
考試:
require './echo.rb'
describe echo do
it 'echoes' do
expect(echo('hello')).to eq('hello')
end
end
終端輸出:
/home/.../scratch/echo.rb:1:in `echo': wrong number of arguments (0 for 1) (ArgumentError)
from /home/.../scratch/scratch_spec.rb:3:in '<top (required)>'
from /home/.../.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in 'load'
...
您應該更改:
describe echo do
至:
describe 'echo' do
即將方法名稱作為字符串。 否則,它會在此時嘗試調用echo
方法,並且您在此處不傳遞參數,因此會遇到上述錯誤。
因此,這應該可以完美地工作:
describe 'echo' do
it 'echoes' do
expect(echo('hello')).to eq('hello')
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.