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
36
37
38
39
40
41
42
43
|
require "book"
require "publisher"
require "library"
require "specifications/find_all_books_by_author"
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
def test_should_be_able_to_use_mocks
mock = MiniTest::Mock.new
mock.expect(:is_satisfied_by?, true, [@pickaxe])
# mock.expect(:is_satisfied_by, false, [@agile_web_development_with_rails])
matches = @library.find_all_matching(mock)
#dump(matches)
assert_includes(matches, @pickaxe)
# refute_includes(matches, @agile_web_development_with_rails)
end
def dump(matches)
matches.each do |item|
puts "#{item.title}"
end
end
end
|