Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.90 KB | None | 0 0
  1. # # Book Titles
  2. #
  3. # # Topics
  4. #
  5. # * classes and objects
  6. # * instance variables
  7. # * setter methods
  8. # * strings
  9. #
  10. # # Notes
  11. #
  12. # 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.
  13. #
  14.  
  15. require 'book'
  16.  
  17. describe Book do
  18.  
  19.   before do
  20.     @book = Book.new
  21.   end
  22.  
  23.   describe 'title' do
  24.     it 'should capitalize the first letter' do
  25.       @book.title = "inferno"
  26.       expect(@book.title).to eq("Inferno")
  27.     end
  28.  
  29.     it 'should capitalize every word' do
  30.       @book.title = "stuart little"
  31.       expect(@book.title).to eq("Stuart Little")
  32.     end
  33.  
  34.     describe 'should capitalize every word except...' do
  35.       describe 'articles' do
  36.         specify 'the' do
  37.           @book.title = "alexander the great"
  38.           expect(@book.title).to eq("Alexander the Great")
  39.         end
  40.  
  41.         specify 'a' do
  42.           @book.title = "to kill a mockingbird"
  43.           expect(@book.title).to eq("To Kill a Mockingbird")
  44.         end
  45.  
  46.         specify 'an' do
  47.           @book.title = "to eat an apple a day"
  48.           expect(@book.title).to eq("To Eat an Apple a Day")
  49.         end
  50.       end
  51.  
  52.       specify 'conjunctions' do
  53.         @book.title = "war and peace"
  54.         expect(@book.title).to eq("War and Peace")
  55.       end
  56.  
  57.       specify 'prepositions' do
  58.         @book.title = "love in the time of cholera"
  59.         expect(@book.title).to eq("Love in the Time of Cholera")
  60.       end
  61.     end
  62.  
  63.     describe 'should always capitalize...' do
  64.       specify 'I' do
  65.         @book.title = "what i wish i knew when i was 20"
  66.         expect(@book.title).to eq("What I Wish I Knew When I Was 20")
  67.       end
  68.  
  69.       specify 'the first word' do
  70.         @book.title = "the man in the iron mask"
  71.         expect(@book.title).to eq("The Man in the Iron Mask")
  72.       end
  73.     end
  74.   end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement