0
我在Ruby中創建一個directed_graph類來練習使用RSpec。我不斷收到上面的錯誤(在第13行,下面一行是「eql(0)」)。遇到:語法錯誤,意外tidENTIFIER,期待keyword_end
我真的不明白這個錯誤,特別是因爲這個RSpec代碼看起來與我爲其他項目編寫的其他RSpec代碼非常相似。
require "directed_graph"
include directed_graph
describe directed_graph do
describe ".vertices" do
context "given an empty graph" do
it "returns an empty hash" do
g = directed_graph.new()
expect(g.vertices().length()).to() eql(0)
end
end
end
end
編輯:我認爲這個問題是(1)directed_graph是一個類,類必須用大寫字母開始(所以我改名爲將DirectedGraph),和(2)你不應該寫「包括「上課。
我修正了這兩個問題,現在我的代碼似乎很好地運行。如果我錯過了一些大事,我會把它留在這裏。