必须进行以下测试:
require 'book'
describe Book do
before do
@book = Book.new
end
describe 'title' do
it 'should capitalize the first letter' do
@book.title = "inferno"
@book.title.should == "Inferno"
end
我不确定我该做什么。我有以下代码:
class Book
@book = Book.new
def title
x = @book
y = x.split("")
y[0] = y[0].upcase
z = y.join("")
z
end
end
但它不会通过,我该怎么办?
答案 0 :(得分:1)
编写自定义Book#title=
和Book#title
方法以通过RSpec测试。
class Book
def title=(t)
@title = t.capitalize
end
def title
@title
end
end