2012-02-07 46 views
0

我想我打了RSPEC錯誤的錯誤,而只是想它第一次......RSPEC錯誤帶班分析器(?)

在下面的例子中,RSPEC是名敏感類:與'解析器'在parser.rb文件測試失敗,但只是重命名它'FooParser'使它的工作。

require_relative './parser.rb' 
describe Parser do 
    it 'should do the trick' do 
     @parser = Parser.new "test.pas" 
    end 
end 

會抱怨我的構造函數的參數,甚至有一個簡單的代碼是這樣的:

class Parser 
    def initialize arg 
    end 
end 

的RSPEC錯誤日誌看起來是這樣的:

1) Parser should do the trick 
    Failure/Error: @parser = Parser.new "test.pas" 
     ArgumentError: 
     wrong number of arguments(1 for 0) 
+1

給我們一個堆棧跟蹤和確切的錯誤消息或它沒有發生。 – 2012-02-07 18:00:55

+0

如果RSpec錯誤已被報告,那麼這裏不是問的地方。 – 2012-02-07 20:05:35

回答

0

寫在該規範的問題應該有效(順便說一句,什麼也不做),但我猜測在你的真實規範中,你試圖使用should這個暗含的主題,像這樣:

it 'should do the trick' do 
    @parser = Parser.new "test.pas" 
    should_not be_nil 
end 

如果使用shouldshould_not裸這樣,Rspec的必須找出你測試的內容。它會查看你是否正在描述一個類 - 你是誰 - 並嘗試實例化它 - 在你的情況下使用Parser.new而沒有參數。

你可能想是這樣的:

it 'should do the trick' do 
    Parser.new("test.pas").should_not be_nil 
end 

這是一個愚蠢的測試,但也許這說明了(可能是什麼)的問題。