summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-02-11 12:35:36 -0700
committermo k <mo@mokhan.ca>2012-02-11 12:35:36 -0700
commit34a96fd1cd221b2b60095940419797786fa61d76 (patch)
tree7a0353b799a8f1ae696f192ffbadc273441cae72
parent1358abc89dc3a5709a65a40b6e2a327a1e816b30 (diff)
spiking out developwithpassion_fakes. i like it!
-rw-r--r--lib/library.rb2
-rw-r--r--lib/specifications/find_all_books_by_author.rb2
-rw-r--r--test/library_specs.rb2
-rw-r--r--test/spec_helper.rb5
-rw-r--r--test/specifications/find_all_books_by_author_specs.rb18
-rw-r--r--test/ts_all.rb2
6 files changed, 28 insertions, 3 deletions
diff --git a/lib/library.rb b/lib/library.rb
index d33806e..5f958fa 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/lib/specifications/find_all_books_by_author.rb b/lib/specifications/find_all_books_by_author.rb
index c142f6a..7e53e55 100644
--- a/lib/specifications/find_all_books_by_author.rb
+++ b/lib/specifications/find_all_books_by_author.rb
@@ -2,7 +2,7 @@ class FindAllBooksByAuthor
def initialize(author)
@author = author
end
- def is_satisfied_by(book)
+ def is_satisfied_by?(book)
book.author == @author
end
end
diff --git a/test/library_specs.rb b/test/library_specs.rb
index aae141a..c231101 100644
--- a/test/library_specs.rb
+++ b/test/library_specs.rb
@@ -27,7 +27,7 @@ class TestLibrary < Test::Unit::TestCase
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?, true, [@pickaxe])
# mock.expect(:is_satisfied_by, false, [@agile_web_development_with_rails])
matches = @library.find_all_matching(mock)
diff --git a/test/spec_helper.rb b/test/spec_helper.rb
new file mode 100644
index 0000000..638274e
--- /dev/null
+++ b/test/spec_helper.rb
@@ -0,0 +1,5 @@
+require 'developwithpassion_fakes'
+
+def fake
+ return DevelopWithPassion::Fakes::Fake.new
+end
diff --git a/test/specifications/find_all_books_by_author_specs.rb b/test/specifications/find_all_books_by_author_specs.rb
new file mode 100644
index 0000000..6e929e3
--- /dev/null
+++ b/test/specifications/find_all_books_by_author_specs.rb
@@ -0,0 +1,18 @@
+require 'specifications/find_all_books_by_author'
+
+describe FindAllBooksByAuthor do
+ before do
+ @author = 'blah'
+ @book = fake
+ @book.stub(:author).and_return(@author)
+ @sut = FindAllBooksByAuthor.new(@author)
+ end
+ describe "when the book is by the author we are looking for" do
+ it "should return true" do
+ @result.must_equal true
+ end
+ before do
+ @result = @sut.is_satisfied_by?(@book)
+ end
+ end
+end
diff --git a/test/ts_all.rb b/test/ts_all.rb
index b8bb61a..3fbf7ad 100644
--- a/test/ts_all.rb
+++ b/test/ts_all.rb
@@ -2,6 +2,8 @@ require "test/unit"
require "minitest/autorun"
require "minitest/spec"
+require 'spec_helper'
require "book_specs"
require "library_specs"
require "stack_specs"
+require "specifications/find_all_books_by_author_specs"