Immediate Download Test Driven Development in Ruby A Practical Introduction To TDD Using Problem and Solution Domain Analysis Paranj Ebooks 2024
Immediate Download Test Driven Development in Ruby A Practical Introduction To TDD Using Problem and Solution Domain Analysis Paranj Ebooks 2024
com
https://textbookfull.com/product/test-driven-
development-in-ruby-a-practical-introduction-to-
tdd-using-problem-and-solution-domain-analysis-
paranj/
https://textbookfull.com/product/test-driven-java-development-invoke-
tdd-principles-for-end-to-end-application-development-2nd-edition-
alex-garcia/
textbookfull.com
https://textbookfull.com/product/domain-driven-laravel-learn-to-
implement-domain-driven-design-using-laravel-jesse-griffin/
textbookfull.com
https://textbookfull.com/product/ios-test-driven-development-by-
tutorials-first-edition-learn-real-world-test-driven-development-
joshua-greene/
textbookfull.com
https://textbookfull.com/product/hydroelectric-energy-renewable-
energy-and-the-environment-1st-edition-bikash-pandey/
textbookfull.com
Is Shakespeare any Good And Other Questions on How to
Evaluate Literature 1st Edition Richard Bradford
https://textbookfull.com/product/is-shakespeare-any-good-and-other-
questions-on-how-to-evaluate-literature-1st-edition-richard-bradford/
textbookfull.com
https://textbookfull.com/product/intelligent-residential-buildings-
and-the-behaviour-of-the-occupants-state-of-the-art-pedro-f-pereira/
textbookfull.com
https://textbookfull.com/product/lonely-planet-kuala-lumpur-melaka-
penang-albiston/
textbookfull.com
https://textbookfull.com/product/mathematical-theory-of-bayesian-
statistics-first-edition-watanabe/
textbookfull.com
https://textbookfull.com/product/pediatric-allergy-a-case-based-
collection-with-mcqs-volume-1-nima-rezaei/
textbookfull.com
Running Wild LCR Elite Series 4 1st Edition Christy Reece
https://textbookfull.com/product/running-wild-lcr-elite-series-4-1st-
edition-christy-reece/
textbookfull.com
Test Driven
Development
in Ruby
A Practical Introduction to TDD Using
Problem and Solution Domain Analysis
—
Bala Paranj
Test Driven
Development in Ruby
A Practical Introduction to TDD Using
Problem and Solution Domain Analysis
Bala Paranj
Test Driven Development in Ruby: A Practical Introduction to TDD Using Problem and Solution
Domain Analysis
Bala Paranj
Atlanta, Georgia, USA
ISBN-13 (pbk): 978-1-4842-2637-7 ISBN-13 (electronic): 978-1-4842-2638-4
DOI 10.1007/978-1-4842-2638-4
Library of Congress Control Number: 2017934648
Copyright © 2017 by Bala Paranj
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material
contained herein.
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Ronald Petty
Coordinating Editor: Mark Powers
Copy Editor: April Rondeau
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Cover image designed by Freepik.
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM
Finance Inc is a Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web
page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book's product page, located at www.apress.com/9781484226377. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
This book is dedicated to the memory of my father.
Contents at a Glance
■
■Chapter 1: The Basics�������������������������������������������������������������������������������������������� 1
■
■Chapter 2: Katas�������������������������������������������������������������������������������������������������� 57
■
■Chapter 3: Techniques in TDD���������������������������������������������������������������������������� 125
■
■Chapter 4: Importance of Test Cases����������������������������������������������������������������� 153
■
■Chapter 5: Character-to-Number Conversion���������������������������������������������������� 163
■
■Chapter 6: Conway’s Game of Life��������������������������������������������������������������������� 171
■
■Chapter 7: Gilded Rose�������������������������������������������������������������������������������������� 221
■
■Chapter 8: Dealing with Third-Party APIs���������������������������������������������������������� 263
■
■Chapter 9: Pair Ranking������������������������������������������������������������������������������������ 277
Index��������������������������������������������������������������������������������������������������������������������� 285
v
Contents
■
■Chapter 1: The Basics�������������������������������������������������������������������������������������������� 1
Terminology���������������������������������������������������������������������������������������������������������������������� 1
Kata�������������������������������������������������������������������������������������������������������������������������������������������������������� 1
Coding Kata�������������������������������������������������������������������������������������������������������������������������������������������� 2
Domain��������������������������������������������������������������������������������������������������������������������������������������������������� 2
Problem Domain������������������������������������������������������������������������������������������������������������������������������������� 2
Solution Domain������������������������������������������������������������������������������������������������������������������������������������� 2
Domain Expert���������������������������������������������������������������������������������������������������������������������������������������� 2
Domain Knowledge��������������������������������������������������������������������������������������������������������������������������������� 3
vii
■ Contents
Overview of TDD������������������������������������������������������������������������������������������������������������� 12
Test Driven Development���������������������������������������������������������������������������������������������������������������������� 12
The Five Steps of TDD��������������������������������������������������������������������������������������������������������������������������� 13
Separation of Intent from Implementation�������������������������������������������������������������������������������������������� 16
Ping Pong Pair Programming Technique���������������������������������������������������������������������������������������������� 16
Black Box Perspective�������������������������������������������������������������������������������������������������������������������������� 16
Shift in System and Mental States������������������������������������������������������������������������������������������������������� 17
Importance of Discipline����������������������������������������������������������������������������������������������������������������������� 18
Overcoming Difficulty �������������������������������������������������������������������������������������������������������������������������� 18
Problem-Solving Skills��������������������������������������������������������������������������������������������������� 18
Four Phases of Problem Solving����������������������������������������������������������������������������������������������������������� 19
Subskills of Test Driven Development�������������������������������������������������������������������������������������������������� 20
Alternative Representations����������������������������������������������������������������������������������������������������������������� 25
Divide and Conquer Strategy���������������������������������������������������������������������������������������������������������������� 26
Assertion������������������������������������������������������������������������������������������������������������������������ 28
Test Driving Calculator��������������������������������������������������������������������������������������������������� 30
Canonical Test Structure����������������������������������������������������������������������������������������������������������������������� 30
Arrange, Act, Assert������������������������������������������������������������������������������������������������������������������������������ 30
Calculator��������������������������������������������������������������������������������������������������������������������������������������������� 31
Subtraction������������������������������������������������������������������������������������������������������������������������������������������� 34
Common Mistakes���������������������������������������������������������������������������������������������������������� 37
Common Mistakes in the TDD Cycle����������������������������������������������������������������������������������������������������� 37
Base Conversion����������������������������������������������������������������������������������������������������������������������������������� 38
Code Reflecting Test Data��������������������������������������������������������������������������������������������������������������������� 46
Multiple Assertions������������������������������������������������������������������������������������������������������������������������������� 47
viii
■ Contents
Summary������������������������������������������������������������������������������������������������������������������������ 54
■
■Chapter 2: Katas�������������������������������������������������������������������������������������������������� 57
Fibonacci Sequence������������������������������������������������������������������������������������������������������� 57
Problem Statement������������������������������������������������������������������������������������������������������������������������������� 58
Problem Domain Analysis��������������������������������������������������������������������������������������������������������������������� 58
Solution Domain Analysis��������������������������������������������������������������������������������������������������������������������� 59
Assumptions����������������������������������������������������������������������������������������������������������������������������������������� 62
Test-Driven Fibonacci��������������������������������������������������������������������������������������������������������������������������� 62
Fizz Buzz������������������������������������������������������������������������������������������������������������������������ 71
Problem Statement������������������������������������������������������������������������������������������������������������������������������� 71
Problem Domain Analysis��������������������������������������������������������������������������������������������������������������������� 71
Solution Domain Analysis��������������������������������������������������������������������������������������������������������������������� 72
Test-Driven FizzBuzz���������������������������������������������������������������������������������������������������������������������������� 72
No if-else Constraint����������������������������������������������������������������������������������������������������������������������������� 77
No if Constraint������������������������������������������������������������������������������������������������������������������������������������� 86
Implementation-Independent Tests������������������������������������������������������������������������������������������������������ 88
Crossing the System Boundary������������������������������������������������������������������������������������������������������������ 90
Mocking as a Design Technique����������������������������������������������������������������������������������������������������������� 90
Abstraction Levels in a System������������������������������������������������������������������������������������������������������������ 94
Testing Random Behavior��������������������������������������������������������������������������������������������������������������������� 95
Testing Time-Dependent Behavior�������������������������������������������������������������������������������������������������������� 96
Simulating User Input��������������������������������������������������������������������������������������������������������������������������� 97
Open Closed Principle������������������������������������������������������������������������������������������������������������������������� 100
Difference Reduction�������������������������������������������������������������������������������������������������������������������������� 102
Defect Localization����������������������������������������������������������������������������������������������������������������������������� 104
ix
■ Contents
Stack���������������������������������������������������������������������������������������������������������������������������� 105
Basic Stack����������������������������������������������������������������������������������������������������������������������������������������� 105
Test Precisely and Concretely������������������������������������������������������������������������������������������������������������� 107
Make Your Code Robust���������������������������������������������������������������������������������������������������������������������� 109
Summary���������������������������������������������������������������������������������������������������������������������� 124
■
■Chapter 3: Techniques in TDD���������������������������������������������������������������������������� 125
Obvious Implementation���������������������������������������������������������������������������������������������� 125
Fake It Till You Make It�������������������������������������������������������������������������������������������������� 127
Triangulation����������������������������������������������������������������������������������������������������������������� 129
Addition���������������������������������������������������������������������������������������������������������������������������������������������� 129
Sum a List of Numbers����������������������������������������������������������������������������������������������������������������������� 130
Summary���������������������������������������������������������������������������������������������������������������������� 152
x
■ Contents
■
■Chapter 4: Importance of Test Cases����������������������������������������������������������������� 153
Problem Statement������������������������������������������������������������������������������������������������������ 153
Problem Domain Analysis��������������������������������������������������������������������������������������������� 153
Solution Domain Analysis��������������������������������������������������������������������������������������������� 153
Algorithm Description��������������������������������������������������������������������������������������������������� 156
Code����������������������������������������������������������������������������������������������������������������������������� 156
Summary���������������������������������������������������������������������������������������������������������������������� 162
■
■Chapter 5: Character-to-Number Conversion���������������������������������������������������� 163
Problem Statement������������������������������������������������������������������������������������������������������ 163
Discussion������������������������������������������������������������������������������������������������������������������������������������������ 163
xi
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
■ Contents
Retrospective��������������������������������������������������������������������������������������������������������������� 261
Summary���������������������������������������������������������������������������������������������������������������������� 262
■
■Chapter 8: Dealing with Third-Party APIs���������������������������������������������������������� 263
Subscription Plan��������������������������������������������������������������������������������������������������������� 263
Create a Plan�������������������������������������������������������������������������������������������������������������������������������������� 263
Delete a Plan�������������������������������������������������������������������������������������������������������������������������������������� 264
Index��������������������������������������������������������������������������������������������������������������������� 285
xii
About the Author
xiii
About the Technical Reviewer
xv
Foreword
I have known Bala for more than a decade. In all this time, he has consistently been a leader in the Ruby
community in the San Francisco Bay Area. Bala has mentored many Ruby and Rails developers, including
me. He is very approachable and has a very appealing style of conversation.
Case in point, last week I was waiting for him at the Starbucks near Google’s HQ in Mountain View to
get his opinions on a project I am working on. While I waited, I met a fellow coffee enthusiast who, upon
finding out that I work for Intuit (the TurboTax company), asked me for some career advice. Ten minutes
later, Bala walked in. After a quick introduction to what we were talking about, Bala took the lead on the
mentoring. No more than a minute had passed before the protégé said, “Can I please record this?” Yes, Bala
is that impressive!
Bala thinks differently. He is a genius. In fact, when the above conversation was done, the protégé asked
us for our contact information. Whereas I proceeded to enter my name, number, and email into his phone,
Bala said, “Just go to my website and click on download vCard. Boom.”
Bala’s excellence in communicating rather abstract concepts clearly and concisely is very clear in the
way the lessons and examples are laid out in this book. He builds up the examples one step at a time so that
it is crystal clear what he intends you to learn. He uses various techniques to make sure the concepts stick in
your mind.
My two key takeaways from this book are as follows:
1.
Understanding the problem is the most important part of solving the problem.
2.
Test Driven Development does not magically result in a good design. There is
more to design than just reducing duplication in code.
This is an excellent book, and I highly recommend that you read it if you plan to create great software.
—John Varghese
Devops Evangelist at Intuit
xvii
Acknowledgments
My first thanks go to Steve Anglin, who approached me with the idea of writing a Ruby book. As a first-time
author, I was both petrified and excited at the same time. He was very understanding about my situation and
provided me the freedom to choose the topic and timing of the book.
I would like to thank Rhonda Jezek for pairing with me on most of the examples in this book, and Daniel
Pritchard for believing in me and encouraging me to write the book. I also would like to thank the members
of my Silicon Valley Ruby meetup, who provided valuable feedback about the early material in this book at
the bootcamps and tutorials. Thanks to Emily Bache for providing me with very candid technical feedback,
and Randy Coulman for his inspiring presentations and technical review of one of the chapters. I would also
like to thank Mayank Suri for challenging me and pushing me out of my comfort zone in order to accomplish
bigger goals in my career.
This book builds on top of the work of others like Kent Beck, Robert Martin, Eric Evans, Gerard
Meszaros, Michael Feathers, and others mentioned in the book. I cannot thank Ryan Davis enough for
building a simple and elegant testing framework with a gentle learning curve for beginners.
This book would not have been a reality without Steve Anglin, Mark Powers, and Matthew Moodie. I am
deeply indebted to the Apress team for recognizing my talent and providing me with a channel for my voice.
Last but not least, thanks to Ronald Petty for patiently reviewing my book and pointing out the mistakes.
This book is the result of my search for solutions to overcome the difficulties I faced when I started to
learn TDD. It also distills the design knowledge I have acquired over my career. I sincerely hope that this
book shows empathy for beginners and makes it easier for them to learn TDD.
xix
Introduction
This book is the result of my struggle to learn Test Driven Development. I started documenting the
difficulties that I faced and what I did to overcome them. I started sharing my tips with the members of
my Silicon Valley Ruby meetup and on my blog. You will learn both from my mistakes and from other
developers in this book.
More importantly, if you document your mistakes and start analyzing them, you too will discover new tips
that you can share with others. Mastering TDD is a journey. I hope you enjoy the journey as much as I have
enjoyed writing this book. Good luck.
xxi
CHAPTER 1
The Basics
This chapter will discuss coding kata, basic terminology, overcoming difficulty in TDD, and how to improve
your TDD skills over time. We will look at the distinction between intent and implementation and its role in
coming up with elegant solutions. We will briefly discuss the basics of Test Driven Development (TDD) and
how problem-solving skills fit into TDD. We will also cover designing test cases, assertion, Canonical Test
Structure, and how to avoid common mistakes.
Terminology
This section will introduce you to the basic terminology required to grasp the material in this book. We will
look at basic terms such as kata, coding kata, domain, problem domain, and solution domain.
Kata
Kata is a Japanese word meaning form. In martial arts, it describes a choreographed pattern of movements
used to train yourself to the level of muscle memory. The focus is on making small improvements during
practice. Figure 1-1 shows a choreographed pattern of movements in martial arts.
Coding Kata
A coding kata is a short exercise that is thirty minutes to an hour long. It can be coded in many different
ways. It is likely that coding katas have many solutions. The focus is on learning when you work through
them. The goal is to practice in order to improve your skills, not to achieve perfection.
Domain
What comes to mind when you hear terms such as equity, debt, gross margin, and net income? How about
contour, contrast, opacity, and form? Here’s another example: parallel, ordinate, arc, and angle. A domain is
defined as a specific sphere of activity or knowledge. The first example corresponds to finance. The second
example corresponds to visual communication, and the third corresponds to geometry. Figure 1-2 shows
three different domains—finance, visual communication, and math—consisting of abstractions found in
those domains.
Problem Domain
The problem domain refers to real-world things and concepts related to a problem.
Solution Domain
The solution domain refers to real-world things and concepts related to a solution.
Domain Expert
A domain expert is someone with special knowledge or skill in a particular domain. For instance, an
accountant is an expert in the accounting domain. The development of accounting software requires
knowledge in two different domains, namely accounting and software.
2
Chapter 1 ■ The Basics
Domain Knowledge
Domain knowledge is expertise in a particular problem domain. It is a critical ingredient in coming up with
abstractions that create elegant solutions.
Let’s now see an example of problem domain and solution domain. Let’s say you have leaking sink
problem in your kitchen. You search on the Internet for the term leaking sink. The phrase leaking sink is
found in the problem domain. Once you read about the solution to this problem, you learn about things
like: clevis screw, stopper rod, clevis, retaining nut and so on. These terms belong to the solution domain.
You watch a video and find out that you need to buy a retaining nut to fix the leak. You now start using this
term found in the solution domain, retaining nut, to find the nearest store carrying this item. So, the term:
retaining nut belongs to the solution domain.
Learning TDD
Learning by Coding Kata
Why coding Kata? Test Driven Development (TDD) is a difficult but learnable skill. So, in order to answer
this question, we need to look at why TDD is difficult.
TDD is not a testing technique. It’s an analysis technique, a design technique, really a
technique for all activities of development.
—Kent Beck, Test Driven Development by Example
3
Chapter 1 ■ The Basics
By using the small but precise nature of the coding kata to practice these skills separately, you can
move past this difficulty and hone your TDD skills. So, coding kata is the best way to learn TDD. How do you
practice a coding kata? You will work through a coding kata by following the five steps of TDD, which will be
discussed in an upcoming section.
Learning Retrospective
After you complete a coding kata using TDD, reflect on the TDD practice session. Ask yourself the following
questions:
• What went well during the TDD session?
• What went wrong during the TDD session?
• What can I do differently next time to improve?
The answers to these questions will tell you where you need to focus your efforts in your next practice
session so as to improve your skills. It’s a good idea to keep a journal that records the coding kata name and
the answers to these questions for each practice session.
Intent
The dictionary definition of intent is determined to do something. If you want to travel in your car, your intent
is to drive your car. You don’t reach into the transmission and pull levers to drive. You can drive without
knowing the details of the car engine. You use the visible parts of the car, such as the steering wheel, gas
pedal, brake, and gears, to drive. You can express your intent by using the public interface of the car. In
programming terms, the intent-revealing drive() method is used. The public interface would consist of
things you can do to a car, such as start, stop, drive, turn, and so on.
Implementation
The things under the hood of the car make up the implementation. Only your car mechanic knows about the
details of the car engine. You may be aware of the 3.0 liter V-6 engine, but you have no idea of how it works.
There could be methods that are internal to the class, such as burn_fuel(), that are not part of the public
interface of the car. This means the user does not directly invoke any private methods of the car.
4
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 1 ■ The Basics
Music
Music is composed by music composers. Music composers organize and develop the music to create a
written score that can be interpreted by performers. Performers play the music using different musical
instruments by referring the sheet music. Sheet music is not music. Sheet music is a visual abstraction of
music. To be specific, it is a symbolic abstraction of music that can be read by anyone who knows how to
read music notation. The composers communicate with other musicians across space and time using music
notation. This is the intent, the what, the logical design. Figure 1-4 shows sheet music that communicates
with other musicians.
Playing the music with a musical instrument is the implementation, the how, or the physical design.
There are many physical designs for a given logical design. In this example, the same sheet music can be
used to play the music using different musical instruments. Figure 1-5 shows music being performed by a
musical instrument, achieved by interpreting the sheet music.
5
Chapter 1 ■ The Basics
Lyrics
A lyricist writes the words for a song by organizing sections into one of the agreed upon structures. This
provides the roadmap for the song. Let’s consider the lyrics for the song “Come Together.” John Lennon
wrote this song. This is the what. The how in this case are the performances by The Beatles, Aerosmith, and
Michael Jackson of the same song, “Come Together.”
Home Plan
An architect gets requirements from the client. A hand-drawn sketch consisting of bubbles, squares,
and rectangles captures the idea of where things are and how they interrelate. This diagram becomes
architecture. Figure 1-6 shows the blueprint of a house that captures the design decisions made by the
architect. This blueprint of a house is the what. It is a visual abstraction of the design. You can build many
houses using the same blueprint.
6
Chapter 1 ■ The Basics
Table 1-1 summarizes the intent and implementation of some common, everyday things that you
encounter.
Intent Implementation
Drive a car Internal mechanism of a car that drives
Represent music The process of playing music with a musical instrument
Lyrics of a song The unique way of singing a song by a singer
Plan of a home Houses that conform to the same blueprint but look different
7
Chapter 1 ■ The Basics
Sheep Example
So, how do we separate the intent from implementation? We can use Chris Stevenson’s TestDox (https://
en.wikipedia.org/wiki/TestDox). TestDox expresses the subject in the code as part of a sentence. Here is
an example:
• A sheep eats grass.
• A sheep bleats when frightened.
• A sheep produces delicious milk.
• A sheep moves away from sheep dogs.
In this example, the sheep is the subject. Its behavior is expressed in a sentence. This can be
automatically converted to specifications in code. Figure 1-7 shows the behavior of a sheep expressed as
specifications in code.
In this example, we are using the spec style of the Minitest testing framework to describe the behavior of
a sheep. Minitest ships with the Ruby language. When you think about a system from the outside, you focus
on the intent. In this case, what does the sheep do?
8
Chapter 1 ■ The Basics
The example is easy to read and shows how the eq() method can be used to compare two strings that
are equal and not equal. (Source: https://www.relishapp.com/rspec/rspec-expectations/docs/built-
in-matchers/equality-matchers)
9
Random documents with unrelated
content Scribd suggests to you:
A gleam of light fell across the threshold.
They could see a slipper lying there—one that Maude had
dropped.
The burglars had probably perceived this, and thence argued that
people were afoot, for the light disappeared, and they could hear
whisperings outside the door.
The big bedroom, as it was called, was a square chamber, barely
furnished. The two bedsteads had been placed close to the window
on the left-hand side.
Round and about these beds the six besieged persons were
crouched or seated.
The moonlight poured in at the window in such a manner that
while the whole of the opposite side, except one corner, was as light
as day, the little nook by the beds was buried in impenetrable
darkness.
The one dark corner on the opposite side was formed by the
chimney, which jutted out some little way into the room.
They listened breathlessly for some moments, till they fancied
that they heard a board creak inside the room close to the door; and
at that moment, as if by magic, a voice issued from the corner of the
chimney.
“We are armed with loaded revolvers; if you come a step nearer
we fire!”
The lurid flash of a pistol flamed within the room, and they heard
a ball strike sharply against the wall.
Maude betrayed their hiding-place with a shriek, and fell fainting
in her brother John’s arms.
A loud report rang in their ears, and the room was filled with a
thick, sulphurous smoke.
By the light of the powder’s flame when the first shot was fired,
there was one who had seen the robber’s face—a face, once seen,
not soon to be forgotten. The dark cavernous eyes of the “Badger”
had been distinctly visible to Jane Ryan, who gave a scream of
triumph and revenge.
It was but momentarily that she had caught sight of the
forbidding features of the miscreant; but it was enough for her
purpose.
She levelled her master’s gun at the supposed spot where the
robber was; and as she fired, something fell heavily upon the floor.
A shudder passed over them like a cold wind. They drew their
breath and heard the same whisperings outside the door.
John Ashbrook placed his sister behind himself and his brother.
There was an interval of silence; they began to hope that the
burglars had gone, when presently they perceived something on the
opposite wall.
They watched it with fascinated eyes. It was a small, dark
shadow, creeping towards them along the wall.
It was the shadow of a man’s hand.
Then they heard a harsh, rustling sound, as if something was
being dragged along the floor.
The robbers were taking away the dead body of their comrade.
They did not dare to move, for they knew the burglars were
armed to a far greater extent than they were, and exposure might
prove fatal.
Ten minutes passed thus; ten minutes of frightful suspense to
these farmers—who were brave but not phlegmatic—who now
fought men for the first time, and fought them in the dark.
They could not possibly tell how many there were of their
enemies. To fire the only three remaining charges they had would
have been an act of madness; they therefore thought it prudent to
keep these in reserve for the grand or final conflict.
But the worst was over, as far as the Oakfield housebreakers were
concerned.
Presently the eager tramp of men’s feet echoed from the road
before the farm, and a dozen rough voices were heard bawling to
each other.
The besieged party rushed to the window, and saw in the front of
the house one of the village constabulary force, who was
accompanied by a posse of strong-bodied youths of the immediate
neighbourhood. In addition to these there were shepherds armed
with crowbars, stablemen with their pitchforks, bird-keepers with
their rusty fowling-pieces, woodmen with their billhooks, and a tall
relation of Jane Ryan’s with a substantial kitchen poker.
The reports of the gun and pistol in the dead hour of the night
had aroused the whole neighbourhood.
As may be readily imagined, the strong reinforcement at once
dispelled all anxiety or doubt in the minds of the farmer’s household.
Three men were instantly mounted, and started off in the dark to
the three nearest railway stations. The rest were invited into the
kitchen to wait till daybreak.
There had been an unprecedented number of burglaries
committed at several houses in the neighbourhood within the space
of a few months—hence it was that the rustic population were so
keenly alive when any signal of alarm was given.
To capture the robbers was the wish of everyone assembled at
Oakfield on that eventful night.
With the first streaks of dawn the party congregated in the yard,
and took counsel on the best means of pursuit.
“If they have been carrying a body with them they can’t be very
far off,” said Mr. Jamblin.
“They are lurking about somewhere hard by, I dare say,” said the
police-officer.
“Where’s Jarvis?” cried Will, the carter. “He’d be the boy to find
’em for us. He’d ketch ’em if they burrowed underground like a
rabbit.”
“Would he?” ejaculated the policeman. “He must be a clever
chap.”
“Aye, that he be,” returned another rustic.
“Have you got any more of his sort in this neighbourhood?” asked
the officer.
The rustics made no reply.
“Who is this Jarvis you were speaking of?” inquired John
Ashbrook.
“Jarvis, sir? Why, him as ’listed some years ago, and fought under
Lord Clyde in the Injies. Arter that they sent him to the other Injies,
where the red men be, and they’ve taught him a power of strange
tricks. He came here wi’ us, but he’s got lost since, or summat.”
“No, I baint lost, Joe,” said a tall young man, whose left cheek
was one great red scar, and whose face had been bronzed by no
English sun.
“Why, sure enough, it is Jarvis!” exclaimed Mr. Ashbrook. “Give us
your hand, lad. Sure enough I shouldn’t ha’ known ye, they’ve
knocked ye about so.”
“Aye, that they have, Master Ashbrook,” returned the soldier. “But
tell us, neighbour, what you can about this night’s business.”
“You shall know all I know,” answered the farmer; who thereupon
put the soldier in possession of all the facts with which the reader is
already acquainted.
When he had finished, the soldier said, “I’ll be bound for it that
the body of the dead or wounded man is not very far from here.”
“You think not?”
“Ah! that I do. We came up so soon that they’d have no time to
get far away with that load upon their backs; and most likely they’ve
been forced to hide it in a slovenly way.”
CHAPTER II.
The most celebrated cracksman of his day, Ned Gregson, alias the
Bristol Badger, was certainly the least fortunate of the three ruffians
who contrived to effect an entrance into Oakfield House. He was run
to earth. After he had been carried on the hurdle into the farmhouse
the village surgeon made a superficial examination of his wound,
which was of a fearful nature; the whole of the charge from the gun
fired by Jane Ryan had entered the burglar’s chest, and the loss of
blood was enormous. The only wonder was, that Gregson had not
been killed outright; but he was not the sort of man to be so easily
disposed of. As far as physical strength was concerned he was a
perfect giant; this he had proved on many occasions.
He was more than double the age of Peace, with three times his
strength. Nevertheless, as far as the guilty and lawless lives of the
two men were concerned, there was not much difference between
them; they were both criminals of the worst type, their whole career
being one of profligacy and crime.
Gregson was taken away to the lock-up in charge of the
constabulary, who procured an ambulance from the hospital. The
divisional surgeon was sent for; every care was taken of the
prisoner; and all that skill and attention could do to preserve so
valuable a life as the burglar’s was, as is usual in such cases, not
wanting.
When sufficiently recovered Gregson was examined before the
stipendiary magistrates. The facts deposed to were plain enough,
and the prisoner was committed for trial upon two distinct charges—
namely, murder and burglary.
Mr. John Ashbrook had by this time sufficiently regained his
strength to leave his room and look after his farming stock, but he
was not as yet up to his usual form.
“This extraordinary charge of murder,” said the farmer to Jane,
one afternoon, as he reclined upon the sofa in the front parlour, “it
seems just like a romance. Strange that you should have recognised
the ruffian by the pistol’s flash on that eventful night.”
“I should have known him out of ten thousand. His face was as
familiar to me as if I had seen him but yesterday.”
“Tell us all about it, Jane.”
“Well, master, it’s a sad and sorrowful tale, which I have kept
locked up in my own breast for ever so long, but it is but right you
should know all about it.”
“Right lass, right you are; go on. What made you imagine that the
house was likely to be attacked? You asked me to load the two other
guns.”
“I did, because I felt assured that danger was at hand.”
“Why so?”
“I had a dream—twice I dreamt the same thing—and then I went
over to Mother Crowther and consulted her. She can read the future
—being—being a wise woman.”
“She is a wise woman indeed if she can do that,” remarked the
farmer, with a smile; “what did she say?”
“She consulted a book, cast my nativity, and told me that in less
than three days I should see here or hereabouts the murderer of
James Hopgood.”
“And who might he be?”
“He is dead now; he was my sweetheart,” answered Jane,
hanging down her head.
“Oh, your sweetheart—eh?”
“Yes, before I came here I lived at Squire Gordon’s. A kinder
master never lived. James Hopgood was a carpenter by trade; he
had been doing some work for the squire—building some outhouses,
and while the work was going on he slept in the house.”
“How long ago was this?”
“Aye, it must be nearly six years.”
“You’ve been here over four.”
“That’s true. Indeed, it must be more than six years. I cannot say
to a certainty; but they’ve got the date—the pleece have.”
“No matter, that’s quite near enough—six years or a little more.
What happened then?”
“I will describe all to you, just as it occurred. James Hopgood was
in the kitchen; he and Mary, my fellow-servant, were having supper
together. I was in the back kitchen, when all of a sudden we heard a
scuffle in the passage, and my master cried, ‘Murder!’ James rushed
past me, and flew up the kitchen stairs. Then we heard a heavy fall
in the passage; this was followed by some low moans. I went up to
see what was the matter, and found my master stretched on the
floor of the passage, with blood flowing from a wound in his left
temple. I endeavoured to raise him, but was unable to do so. He
was a stout, heavy man, and I had not strength enough to lift him.”
“Was he killed?”
“No—oh, dear, no; he recovered afterwards. But the worst
remains to be told. Oh, master, these be tears that are a flowin’ from
my eyes. I can see it all now, as if it occurred but yesterday.”
“Yes, your master, the squire, you found him senseless. There’s
no hurry, girl, take your time—don’t flurry yourself.”
“While I was looking at my poor master, I caught sight of James
Hopgood and the burglar—him as I shot down in the big bedroom.
James had closed with the ruffian, who, as far as I could judge, was
striving to shake James off; but he was not able to do this so easily;
they wrestled like two serpents. I felt sick and faint; but,
notwithstanding, I had sufficient strength left to hasten to young
Hopgood’s assistance. I saw the flash of an open knife in the pale
moonlight, saw the gleaming of the desperate wretch’s eyes, and in
another moment the knife was buried up to the hilt in James’s
breast. He fell with a deep groan, and never stirred hand or foot
afterwards.
“I rushed forward, and caught his murderer by the handkerchief
which encircled his throat. After this I lost all consciousness. When I
came to I found myself on the wet grass of the lawn—the ruffian’s
handkerchief was firmly grasped in my right hand.”
“Why, Jane, my girl, this is indeed a horrible story, and have you
kept this all to yourself for these last six years?”
“Indeed I have; but, waking or sleeping, one burning thought has
been in my brain. It is this—to avenge the death of my dear and
true-hearted James.”
The farmer was bewildered—partly dazed by the fearful tale he
had been listening to. He turned his eyes towards his sister, who had
crept into the room to listen to the appalling narrative.
“Did you know of this?” inquired Ashbrook.
“I knew a shocking affair of some sort took place at Squire
Gordon’s when Jane was there, but I never knew till now its precise
nature. I understood that some young man was murdered—that is
all. How and by whom I was never told.”
“And was the man never discovered? An attempt was made to
find him, I s’pose?” asked the farmer of his servant.
“Government offered a reward of a hundred pounds; a description
of the man was printed on handbills, which were sent, so they said,
to every police-station.”
“With what result?”
“With none, except the arrest of a poor harmless fellow, who
never set foot in the squire’s house, and who had no more to do
with the crime than you or I have.”
“And the handkerchief?”
“That I have kept. The knife also with which the murder was
committed was picked up on the lawn; that, too, I have preserved.
They are both now in the possession of the pleece. Ah! we shall
bring it home to the deep-dyed villain. I felt certain that, sooner or
later, he would be caught, the murderin’ thief.”
“What became of the squire?”
“He left England for good, and settled in Brittany. He has a
daughter who is married there.”
“Is he still alive?”
“I believe so. I never heard of his death—oh! I’m pretty sure he’s
alive.”
“Do you think he could identify the man?”
“He told me after his recovery that he saw his features distinctly,
and that he would be able to swear to him. It appeared that
Gregson was making his escape from the house with the things he
had stolen, when he was suddenly and unexpectedly confronted by
the squire, who had come over the fields, crossed the lawn, and
entered by the back door of his residence.”
“We’ve all of us had a narrow escape,” said Maud Ashbrook, “and
it will be a warning to us for the future.”
“I’m glad Jane shot the fellow down,” observed the farmer. “She’s
a true-hearted, brave girl—not, mind ye, but it would ha’ bin better
for him to have fallen by the hands of one of us men.”
“No, master, no,” cried Jane, in a deprecating tone. “I am the
most deeply injured, sick and sore of heart—I who have sworn to
devote the remainder of my life to discover the slayer of James
Hopgood—I was the most fitting person to hunt him down. It has
been done, and he will not escape now.”
Jane had given her evidence before the stipendiary magistrates in
the clearest and most lucid manner. She swore positively to the
prisoner Gregson, whose features she declared had not changed
since she saw them so distinctly on that fatal night. Her fellow-
servant also identified the prisoner, whom she saw, so she averred,
through the back-parlour window at the time Jane had hold of him
by the handkerchief.
He was also recognised by several of the police as a well-known
burglar, who had been convicted several times.
Gregson, who was about as hardened a ruffian as it was possible
to conceive, knew and felt that his game was up; nevertheless he
clung to the hope, as most criminals do of his class, that he might
escape the last dread sentence of the law—perhaps his life might be
spared.
He was taken to Broxwell Gaol; his custodians conducted him
through the lodge, then he passed through a square with a green
plot of grass in the middle, encircled by a gravel walk.
It was like a college quadrangle.
Gregson looked at the grass and the turnkeys who came out to
meet him. He was conducted up a flight of stone steps, and one of
the turnkeys who had joined him and the constabulary who had him
under their charge tapped at a thick oak door, which was covered
with iron nails and secured with a gigantic lock.
They were admitted immediately into a little room, which was
almost entirely filled by a clerks’ desk and stool.
Upon this stool was seated an old man, with a pair of iron-rimmed
spectacles on his nose, making entries in an account-book.
The turnkey who had opened the door to them now closed it with
an ominous sound.
The key clanked loudly in the lock.
The Bristol Badger was in prison.
The turnkey unlocked another door and disappeared. In a few
moments he returned, dismissed the constable, and ordered the
prisoner to follow him.
They entered a snow-white corridor, which was lined with iron
doors, and above with galleries, also of iron, bright and polished.
Gregson was placed in a cell, for some time in the company of a
single turnkey, who stood by him, rigid and voiceless as a statue,
watchful as a lynx.
The “cracksman” assumed an air of dejection, and kept his eyes
fixed upon the ground.
He had only partially recovered from his wound. From this a vast
number of shots had been extracted; but several more, it was
thought, still remained in the flesh.
The burning pain in his chest had not entirely left him, although it
was not nearly so insupportable as at first.
Presently the door of the cell opened, and a gentleman in plain
clothes came in. He had a ruddy complexion, with a brown
moustache and beard.
Gregson recognised him immediately. He was the governor.
The recognition was mutual.
“So,” he said, “you have come here again?”
“They’ve brought me here,” muttered the cracksman.
“Precisely. Of course you know the usual forms prescribed by the
authorities. We must put you through the ordeal of a warm bath.
“Turn on the tap, Wilson,” said the governor; and in a few
minutes the bath was filled with hot water.
They took off his handcuffs, and then stood by him as he
undressed.
“Do you know, governor, that I’ve been wounded—well-nigh to
death? It’s too bad to put a cove in hot water in my state.”
“Wounded, eh? We’ll send for the doctor.”
The prison surgeon was brought into the room.
He glanced at the wound, which still presented an angry
appearance.
“The bath won’t hurt you. There is no necessity for you to
immerse your chest or shoulders in the water. In my opinion you will
be better for it.”
“All right,” returned Gregson; “you shall have your way. I’m not
one to make things disagreeable.”
And forthwith he jumped in.
The governor paced the corridor for the next ten minutes or so
under pretence of superintending the arrangements of the prisoners’
dinners, which ascended from the kitchen on a great tray by means
of mysterious machinery.
On his return he called another turnkey, and ordered him to have
the prisoner’s clothes brushed and cleaned.
“You have got plenty of money,” he said to Gregson. “You are
suffering from a severe wound. We don’t wish to deal harshly with
you.”
“I’m much obliged, I’m sure,” returned the Badger.
The governor took no notice of this last observation, which, to say
the truth, was half conciliatory and half sarcastic.
“We will therefore allow you to wear your own clothes, and to
procure your own meals from an eating-house if you prefer it.”
“Yes, I do prefer it, if it makes no difference.”
“So be it, then. You will see by the printed copy of the rules which
is hung up in every cell that you are not allowed more than one pint
of wine or one quart of malt liquor daily, and that, if you undertake
to board yourself, you must do so altogether. Besides this you will be
allowed books to read and paper to write upon, and other little
comforts, under my supervision, as I have no desire to treat you
with unnecessary severity during the brief period that will elapse
while you are awaiting your trial. I hope you will conduct yourself in
a proper and becoming manner.”
The cracksman nodded, and seemed by his demeanour to
appreciate the lenity which the governor displayed.
“You are very good, sir, I’m sure,” he muttered. “I wish all
gentlemen in your position were equally kind and merciful.”
The governor bowed in a dignified manner, and then left the cell.
The turnkey returned with Gregson’s clothes, and stood by him as he
dressed. He was then conducted to Cell No. 15.
There they showed him how to ring the bell, how to pull the slide
from the grating when he wanted fresh air, and how to manage the
water taps and the bed furniture.
They also informed him that when he wanted anything from the
town there was a prison servant attached to the establishment
whose office it was to run errands for the prisoners who were
waiting for trial.
The turnkeys made these explanations with a courteous accent,
for turnkeys have a sort of veneration for great criminals.
And Ned Gregson, in this respect, was a man of mark.
The prison officials went out of the cell backwards, as if they were
retiring from a royal presence; they locked the door with an
ostentatious noise that they might thereby strike a wholesome awe
into the mind of their prisoner.
Gregson sat himself down upon the wooden stool in his cell
without moving.
The bitterness of his thoughts it would not be so easy to describe.
He remembered with harrowing distinctness the most remote
incident of the night upon which the ill-fated James Hopgood fell
beneath the fatal blow.
“And that cursed woman!” ejaculated the Badger. “Who would
have dreamt of her being an inmate of the farmhouse? And the oily-
tongued Peace, he has got clear off, I’ll dare be sworn; and the
chances are that he is now playing that old fiddle of his—whilst I—I
—”
Here he uttered an impious oath, and then lapsed into silence
again.
He sat for two hours a prey to the most agonising thoughts.
At the expiration of that time he uttered curses loud and deep. He
ran frantically round his narrow cell.
One of the turnkeys opened the door, and told him that he must
make less noise. There was a punishment for making an outcry of
that nature, and he pointed to one of the printed rules.
The “cracksman” answered with a howl of rage, and squatted
abjectly on his stone floor.
The turnkey, who was pretty well used to scenes of this nature,
and who, therefore, made due allowance, repeated his warning and
shut the door.
Soon after this the prison servant brought a wooden tray in.
There were two dishes, each surrounded by a pewter cover. One
contained three slices of roast mutton, floating in lukewarm gravy;
the other contained four good-sized potatoes.
Gregson, who was still on the floor, looked at them supinely.
“Governor! thought you would like a little dinner,” said the man
kindly; and he propped up a slab which was hanging from the wall,
placed the tray on it, reached down a salt dish from a shelf in the
corner, where it had grown dusty, in company with a bible and two
hymn books.
“Will you take beer or wine?”
“I want wine,” said the Badger, sulkily.
“Very good, I will bring you a pint; it’s against the rules to have
any more.”