summaryrefslogtreecommitdiff
path: root/test/library_specs.rb
blob: a87a87ce844ee1264b3c8fc619e0c52ab23f1939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "book"

# require "library"
class Library
  def initialize
    @books = []
  end
  def add(book)
    @books << book
  end
  def contains(title)
    # puts @books.public_methods
    found = @books.find do |book| 
      book.title == title
    end
    found != nil
    # @books.any?
  end
end

class TestLibrary < Test::Unit::TestCase
  def setup
    @pickaxe = Book.new("The Ruby Programming Language")
    @agile_web_development_with_rails = Book.new("Agile Web Development with Rails")
    @library = Library.new
    @library.add @pickaxe
    @library.add @agile_web_development_with_rails
  end
  def test_should_tell_if_a_book_was_added
    assert_equal(true, @library.contains(@pickaxe.title))
  end
  def test_should_tell_when_a_book_was_not_added
    assert_equal(false, @library.contains("little red riding hood"))
  end
end