user5733116
user5733116

Reputation:

wrong number arguments (0 for 1) (ArgumentError)

Looks like rspec is not passing any arguments to the method, even though they're written in the spec file.

The method:

def echo(msg)
  msg
end

The test:

require './echo.rb'

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

terminal output:

/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'
...

Upvotes: 0

Views: 86

Answers (1)

K M Rakibul Islam
K M Rakibul Islam

Reputation: 34336

You should change:

describe echo do

to:

describe 'echo' do

i.e. putting the method name as string. Otherwise, it tries to call the echo method at this point and you don't pass the argument here and hence you get the mentioned error.

So, this should work perfectly:

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

Upvotes: 2

Related Questions