调试这个Ruby单元测试时遇到了麻烦,但无法弄清楚我做错了什么。这是代码:
require 'test/unit.rb'
require 'wordplay.rb'
class TestWordPlay < Test::Unit::TestCase
def test_sentences
assert_equal(["a", "b", "c d", "e f g"], "a.b. c d. e f g".sentences)
test_text = %q{Hello. This is a test
of sentence separation. This is the end of the test.}
assert_equal("This is the end of the test", test_text.sentences[2])
end
def test_words
assert_equal(%w{this is a test}, "this is a test".words)
assert_equal(%w{these are mostly words}, "these are, mostly, words".words)
end
# Testing best sentence choice
def test_sentence_choice
assert_equal('This is a great test')
WordPlay.best_sentence(['This is a test', 'This is another test', 'This is a great test']
%w{test great this}))
assert_equal('This is a great test', WordPlay.best_sentence(['This is a great test'],
%w{'still the best'}))
end
end
/Users/pdenlinger/ruby/wordplaylib/wordplaytest.rb:23: syntax error, unexpected tQWORDS_BEG, expecting ')'
%w{test great this}))
^
/Users/pdenlinger/ruby/wordplaylib/wordplaytest.rb:23: syntax error, unexpected ')', expecting kEND
%w{test great this}))
^
答案 0 :(得分:3)
在这一行
WordPlay.best_sentence(['This is a test', 'This is another test', 'This is a great test'] %w{test great this}))
在第一个参数之后,您似乎没有逗号。然后有两个结束括号,但你只有一个开放的肠胃外。
请考虑编辑您的问题以使代码更具可读性(提示:如果一行以4个空格开头并且前面有空行,则它看起来像代码)。