我在使用rspec
. 在我的book.rb
文件中,代码块通过了所有针对书籍标题中单词大写的测试(“杀死一只知更鸟”、“地狱”)。但是,当我从终端运行 rake 时,我反复收到错误消息
"Failure/Error: @book.title.should == "Inferno"
ArgumentError:
wrong number of arguments (0 for 1)".
我尝试更改参数并删除标题方法,但没有任何效果,即使程序将标题大写,我仍然收到错误消息。谢谢,非常感谢任何帮助!
class Book
attr_accessor :title, :littlewords
def initialize
@littlewords = ["the", "a", "an", "and", "of", "in"]
end
def title
@title
end
def title(lit)
@title = ''
books = lit.split
books.each do |title|
title.capitalize! unless (littlewords.to_s).include?(title)
end
books[0] = books[0].upcase
books.first.capitalize!
books.join(' ')
end
end
s = Book.new
puts s.title("to kill a mockingbird")
puts s.title("inferno")