summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <m@mokhan.ca>2011-11-14 10:57:11 -0700
committermo k <m@mokhan.ca>2011-11-14 10:57:11 -0700
commitead52656a2f9ca1b5f5dc20034453f1886953885 (patch)
treef4ec3ab4f775aefae40ce6206b281b566edc9200
parent6ff3206ed3c5a22292687a515bf3feb53f893285 (diff)
just found out that MiniTest::Mock falls apart when trying to return different values for a single method when passing in different parameters.
-rw-r--r--lib/library.rb2
-rw-r--r--test/library_specs.rb15
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/library.rb b/lib/library.rb
index f3765b5..d33806e 100644
--- a/lib/library.rb
+++ b/lib/library.rb
@@ -9,6 +9,6 @@ class Library
@books.find { |book| book.is_titled?(title) } != nil
end
def find_all_matching(criteria)
- @books.find_all {|book| criteria.is_satisfied_by book }
+ @books.find_all {|book| criteria.is_satisfied_by(book) }
end
end
diff --git a/test/library_specs.rb b/test/library_specs.rb
index dc48f50..aae141a 100644
--- a/test/library_specs.rb
+++ b/test/library_specs.rb
@@ -25,4 +25,19 @@ class TestLibrary < Test::Unit::TestCase
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