From 34a96fd1cd221b2b60095940419797786fa61d76 Mon Sep 17 00:00:00 2001 From: mo k Date: Sat, 11 Feb 2012 12:35:36 -0700 Subject: spiking out developwithpassion_fakes. i like it! --- lib/library.rb | 2 +- lib/specifications/find_all_books_by_author.rb | 2 +- test/library_specs.rb | 2 +- test/spec_helper.rb | 5 +++++ test/specifications/find_all_books_by_author_specs.rb | 18 ++++++++++++++++++ test/ts_all.rb | 2 ++ 6 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/spec_helper.rb create mode 100644 test/specifications/find_all_books_by_author_specs.rb 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" -- cgit v1.2.3