2015-09-26 29 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