summaryrefslogtreecommitdiff
path: root/spec/book_specs.rb
blob: 7199b41e52282609369e985cb30cff01e234515f (plain)
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
44
45
46
require "book"

class TestBook < Test::Unit::TestCase
  def setup
    @publisher = Publisher.new("Pear press");
  end
  def test_should_be_equal
    assert_equal(Book.new("Brain Rules for Baby", "John Medina", @publisher, 2010), Book.new("Brain Rules for Baby", "John Medina", @publisher, 2010))
  end
  def test_should_not_be_equal_because_they_are_different_types
    assert_not_equal(Book.new("blah", "anonymous", @publisher, 2011), Game.new("blah", "?", @publisher, 2010))
  end
  def test_should_not_be_equal_because_they_have_different_titles
    assert_not_equal(Book.new("the game", "neil strauss", @publisher, 2001), Book.new("DDD", "eric evans", @publisher, 2005))
  end
end

describe Book do 
  describe "when testing equality" do 
    def setup
      @publisher = Publisher.new("Pear press");
      @book = Book.new("Brain Rules for Baby", "John Medina", @publisher, 2010)
    end
    it "should be equal when it's the same instance" do 
      @book.must_equal @book
      #assert_equal(@book, @book)
    end
    it "should be equal when they are the same book" do 
      @book.must_equal Book.new("Brain Rules for Baby", "John Medina", @publisher, 2010)
      #assert_equal(@book, Book.new("Brain Rules for Baby", "John Medina", @publisher, 2010))
    end
    it "should not be equal when they are different books" do 
      @book.wont_match Book.new("Brain Rules for Baby", "some other guy", @publisher, 2009)
      #refute_equal(@book, Book.new("Brain Rules for Baby", "some other guy", @publisher, 2009))
    end
  end
end

class Game
  attr_reader :title;
  def initialize(title, author, publisher, year)
    @title=title
    @publisher = publisher
    @year =year
  end
end