blob: ef68e4c60ca1b591f854f49ebe4f11b8c234a54f (
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 "publisher"
require "library"
class TestLibrary < Test::Unit::TestCase
def setup
@prag_press = Publisher.new("Prag Press"),
@pickaxe = Book.new("Programming Ruby 1.9", "dave thomas", @prag_press, 2010)
@agile_web_development_with_rails = Book.new("Agile Web Development with Rails", "chad fowler", @prag_press, 2010)
@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
def test_should_be_able_to_find_all_books_by_an_author
author = "dave thomas"
matches = @library.find_all_matching FindAllBooksByAuthor.new(author)
assert_includes(matches, @pickaxe)
end
end
class FindAllBooksByAuthor
def initialize(author)
@author = author
end
def is_satisfied_by(book)
book.author == @author
end
end
|