2015-09-26 28 views
0

您好我需要知道如何做错误以下新红宝石和试图修复从rspec的

rspec的代码:

2) WebServer::Htaccess#authorized? for valid-user with valid credentials returns true 
Failure/Error: expect(htaccess_valid_user.authorized?(encrypted_string)).to be_true 
ArgumentError: 
    wrong number of arguments calling `authorized?` (1 for 0) 
# ./spec/lib/config/htaccess_spec.rb:82:in `(root)' 
# ./spec/lib/config/htaccess_spec.rb:44:in `stub_htpwd_file' 
# ./spec/lib/config/htaccess_spec.rb:41:in `stub_htpwd_file' 
# ./spec/lib/config/htaccess_spec.rb:40:in `stub_htpwd_file' 
# ./spec/lib/config/htaccess_spec.rb:81:in `(root)' 

这里是spec.rb文件

let(:htaccess_valid_user) { WebServer::Htaccess.new(valid_user_content) } 
let(:htaccess_user) { WebServer::Htaccess.new(user_content) } 

describe '#authorized?' do 
context 'for valid-user' do 
    context 'with valid credentials' do 
    it 'returns true' do 
     stub_htpwd_file do 
     expect(htaccess_valid_user.authorized?(encrypted_string)).to be_true 
     end 
    end 
    end 

    context 'with invalid credentials' do 
    it 'returns false' do 
     stub_htpwd_file do 
     expect(htaccess_valid_user.authorized?(encrypted_string('bad user'))).not_to be_nil 
     expect(htaccess_valid_user.authorized?(encrypted_string('bad user'))).to be_false 
     end 
    end 
    end 
end 

我是ruby TDD的新手,现在我所有的文件都是

def authorized? 



end 

我很流利的Node.js,但这对我来说是全新的。

请帮忙。

回答

2

它就在错误信息中。

ArgumentError: 
    wrong number of arguments calling `authorized?` (1 for 0) 

您已将参数传递给authorized?方法。

expect(htaccess_valid_user.authorized?(encrypted_string)).to be_true 
             ^^^^^^^^^^^^^^^^^^ 

authorized?没有参数。

def authorized? 
end 

与Javascript不同,Ruby会检查您传递的参数是否正确。如果您不指定参数列表,则默认为强制执行不参数。 Add some

def authorized?(authorization) 
end