From ead52656a2f9ca1b5f5dc20034453f1886953885 Mon Sep 17 00:00:00 2001 From: mo k Date: Mon, 14 Nov 2011 10:57:11 -0700 Subject: just found out that MiniTest::Mock falls apart when trying to return different values for a single method when passing in different parameters. --- lib/library.rb | 2 +- test/library_specs.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3