Ruby on rails 参数数目错误(0代表1)(ArgumentError)

Ruby on rails 参数数目错误(0代表1)(ArgumentError),ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,看起来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

看起来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'
...
/home/../scratch/echo.rb:1:in'echo':参数数量错误(0代表1)(ArgumentError)
from/home/../scratch/scratch_spec.rb:3:in''
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
致:

i、 e.将方法名称作为字符串。否则,它会在此时尝试调用
echo
方法,而您没有在此处传递参数,因此您会得到所提到的错误

因此,这应该可以完美地工作:

describe 'echo' do
  it 'echoes' do
    expect(echo('hello')).to eq('hello')    
  end
end

如果我也在descripe行
descripe echo('hello')do
中传递参数,则似乎有效。这是有意的吗?
describe 'echo' do
  it 'echoes' do
    expect(echo('hello')).to eq('hello')    
  end
end