Skip to content

Commit d09d56b

Browse files
committed
Updates
1 parent 9322074 commit d09d56b

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

book.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ def lost
3030
def available?
3131
@status == :available
3232
end
33+
34+
def hold
35+
@status = :on_hold
36+
end
37+
38+
def release
39+
@status = :available
40+
end
3341
end

books.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
---
2-
- !ruby/object:Book
1+
---
2+
- !ruby/object:Book
3+
title: ! 'JavaScript: The Good Parts'
34
author: Douglas Crockford
45
category: :development
56
status: :available
6-
title: "JavaScript: The Good Parts"
7-
- !ruby/object:Book
7+
- !ruby/object:Book
8+
title: Designing with Web Standards
89
author: Jeffrey Zeldman
910
category: :design
1011
status: :available
11-
title: Designing with Web Standards
12-
- !ruby/object:Book
12+
- !ruby/object:Book
13+
title: Don't Make me Think
1314
author: Steve Krug
1415
category: :usability
1516
status: :available
16-
title: Don't Make me Think
17-
- !ruby/object:Book
17+
- !ruby/object:Book
18+
title: JavaScript Patterns
1819
author: Stoyan Stefanov
1920
category: :development
2021
status: :available
21-
title: JavaScript Patterns
22-
- !ruby/object:Book
22+
- !ruby/object:Book
23+
title: Responsive Web Design
2324
author: Ethan Marcotte
2425
category: :design
2526
status: :available
26-
title: Responsive Web Design
27-
- !ruby/object:Book
27+
- !ruby/object:Book
28+
title: The Clean Coder
2829
author: Uncle Bob Martin
2930
category: :development
3031
status: :available
31-
title: The Clean Coder

spec/book_spec.rb

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,16 @@
2727
end
2828
end
2929

30-
describe "#checkout" do
30+
describe "checking out a book" do
31+
before :each do
32+
@book.checkout
33+
end
34+
3135
context "when book is available" do
32-
it "changes status to loaned" do
33-
@book.status.should eql :available
34-
@book.checkout
35-
@book.status.should eql :on_loan
36-
end
36+
it { @book.status.should eql :on_loan }
3737
end
3838
context "when book is not available" do
39-
it "raises an error" do
40-
@book.checkout
41-
@book.status.should eql :on_loan
42-
lambda { @book.checkout }.should raise_error
43-
end
39+
it { lambda { @book.checkout }.should raise_error }
4440
end
4541
end
4642

@@ -60,6 +56,7 @@
6056
end
6157
end
6258
end
59+
6360

6461
describe "#lost" do
6562
it "changes status to lost" do
@@ -71,4 +68,30 @@
7168
describe "when a book is available" do
7269
it { @book.should be_available }
7370
end
71+
72+
describe "placeing a book on hold" do
73+
before :each do
74+
@book.hold
75+
end
76+
77+
context "the book is available" do
78+
it "should change status to on hold" do
79+
@book.status.should == :on_hold
80+
end
81+
end
82+
end
83+
84+
describe "when removing a book from hold" do
85+
before :each do
86+
@book.hold
87+
@book.release
88+
end
89+
90+
context "the book is on hold" do
91+
it "should change status to available" do
92+
@book.status.should == :available
93+
end
94+
end
95+
end
96+
7497
end

0 commit comments

Comments
 (0)