diff options
| -rw-r--r-- | lib/library.rb | 3 | ||||
| -rw-r--r-- | test/library_specs.rb | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/library.rb b/lib/library.rb index 4f1321a..f3765b5 100644 --- a/lib/library.rb +++ b/lib/library.rb @@ -8,4 +8,7 @@ class Library def contains(title) @books.find { |book| book.is_titled?(title) } != nil end + def find_all_matching(criteria) + @books.find_all {|book| criteria.is_satisfied_by book } + end end diff --git a/test/library_specs.rb b/test/library_specs.rb index f2972c1..ef68e4c 100644 --- a/test/library_specs.rb +++ b/test/library_specs.rb @@ -20,6 +20,16 @@ class TestLibrary < Test::Unit::TestCase 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 |
