0
我目前正在做TestFirst.org的Ruby练习。这是一个通过让你构建代码来通过测试来教授Ruby的程序。我提到这是说我没有写这个RSpec代码,但会很感激知道如何解决它。RSpec未能通过学生练习
RSpec的:
# Book Titles in English obey some strange capitalization rules. For example,
# "and" is lowercase in "War and Peace". This test attempts to make sense of
# some of those rules.
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
it 'should capitalize every word' do
@book.title = "stuart little"
@book.title.should == "Stuart Little"
end
describe 'should capitalize every word except...' do
describe 'articles' do
specify 'the' do
@book.title = "alexander the great"
@book.title.should == "Alexander the Great"
end
specify 'a' do
@book.title = "to kill a mockingbird"
@book.title.should == "To Kill a Mockingbird"
end
specify 'an' do
@book.title = "to eat an apple a day"
@book.title.should == "To Eat an Apple a Day"
end
end
specify 'conjunctions' do
@book.title = "war and peace"
@book.title.should == "War and Peace"
end
specify 'prepositions' do
@book.title = "love in the time of cholera"
@book.title.should == "Love in the Time of Cholera"
end
end
describe 'should always capitalize...' do
specify 'I' do
@book.title = "what i wish i knew when i was 20"
@book.title.should == "What I Wish I Knew When I Was 20"
end
specify 'the first word' do
@book.title = "the man in the iron mask"
@book.title.should == "The Man in the Iron Mask"
end
end
end
end
之前,它甚至分析我写它来测试代码,它给这个错误:
C:\Users\Computer\Documents\learn_ruby\08_book_titles>rake
(in C:/Users/Computer/Documents/learn_ruby)
You must use ANSICON 1.31 or later (http://adoxa.3eeweb.com/ansicon/) to use colour on Windows
Book
title
should capitalize the first letter (FAILED - 1)
Failures:
1) Book title should capitalize the first letter
Failure/Error: @book = Book.new
NameError:
uninitialized constant Book
# ./08_book_titles/book_titles_spec.rb:20:in `block (2 levels) in <top (required)>'
Finished in 0 seconds
1 example, 1 failure
Failed examples:
rspec ./08_book_titles/book_titles_spec.rb:24 # Book title should capitalize the first letter
C:/RailsInstaller/Ruby2.1.0/bin/ruby.exe -S rspec C:/Users/Computer/Documents/learn_ruby/08_book_titles/book_titles_spec
.rb -IC:/Users/Computer/Documents/learn_ruby/08_book_titles -IC:/Users/Computer/Documents/learn_ruby/08_book_titles/solu
tion -f documentation -r ./rspec_config failed
我试着用搜索引擎的错误消息,但没有运气。我刚刚开始学习,而我没有专业知识来解决这个RSpec代码。任何帮助将不胜感激这位有需要的学生。
编辑:
我是个白痴,不明白发生了什么正在问我的。继续下去。
谢谢你,但只是改变了错误的: 1)图书标题应首字母大写 故障/错误:@ book.title = “炼狱” NoMethodError: 未定义的方法' title ='for# #.08_book_titles/book_titles_spec.rb:28:in ' –
2015-03-03 02:48:23
@ChristopherByrd它需要有一个title属性。国际海事组织,你开始有点在你的头上;你知道Ruby的一切吗? – 2015-03-03 02:49:53
您需要开始定义解决测试的方法。您会注意到,在测试文件夹的index.html中,它提到了有关对象和实例的主题。 [一些参考](http://www.tutorialspoint.com/ruby/ruby_classes.htm) – 2015-03-03 02:50:44