Download Test Driven Development in Ruby A Practical Introduction to TDD Using Problem and Solution Domain Analysis Paranj ebook All Chapters PDF
Download Test Driven Development in Ruby A Practical Introduction to TDD Using Problem and Solution Domain Analysis Paranj ebook All Chapters PDF
com
https://textbookfull.com/product/test-driven-development-in-
ruby-a-practical-introduction-to-tdd-using-problem-and-
solution-domain-analysis-paranj/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/test-driven-java-development-invoke-
tdd-principles-for-end-to-end-application-development-2nd-edition-
alex-garcia/
textboxfull.com
https://textbookfull.com/product/domain-driven-laravel-learn-to-
implement-domain-driven-design-using-laravel-jesse-griffin/
textboxfull.com
https://textbookfull.com/product/ios-test-driven-development-by-
tutorials-first-edition-learn-real-world-test-driven-development-
joshua-greene/
textboxfull.com
https://textbookfull.com/product/matlab-a-practical-introduction-to-
programming-and-problem-solving-stormy-attaway/
textboxfull.com
https://textbookfull.com/product/matlab-a-practical-introduction-to-
programming-and-problem-solving-stormy-attaway-2/
textboxfull.com
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
[email protected], 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 [email protected], 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
■ 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
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
Chapter 1 ■ The Basics
This test does not reveal the intent of rolling ten times. We don’t know why it invokes the roll method
ten times, because the intent is hidden. We can make the intent explicit by asking the question: “What does
it mean to hit all ten pins?” In the bowling game domain, it means a strike. So, we can express it directly in
code as follows:
The strike method is intent-revealing and expresses the domain concept mentioned in the test name
directly in the code. It clearly communicates the meaning of a strike in a bowling game to other developers.
10
Chapter 1 ■ The Basics
11
Chapter 1 ■ The Basics
From what, we move to how. The focus shifts from analysis to design. You will be looking at the solution
domain. Your mental state is how. For how, you will focus on what is inside the system, as illustrated in
Figure 1-11. You will consider the details of the system under test.
A professional artist starts to draw a portrait with a general outline that gives the basic shape of the face,
eyes, and so on. At this stage, the attributes of a person, such as eyes and lips, could be those of anyone. They
don’t look unique to the portrait subject. As the artist gradually adds more details and adds depth using
shading, the drawing comes to life and resembles the subject. The final portrait fits the structure provided by
the general outline drawn in the initial stages of the drawing. Software developers work in a similar way in
order to write software to solve a given problem.
Overview of TDD
This section is a brief introduction to Test Driven Development. We will answer questions such as what,
why, and how. We will discuss why we start with a failing test and are minimal when implementing the
production code. We will also see how TDD separates the intent from implementation, how to get all the
benefits of TDD, and, finally, what makes TDD difficult.
Clean code that works gives you a chance to learn all the lessons that the code has to teach
you. If you only slap together the first thing you think of, you never have time to think of a
second, better thing. The intent is to learn and come up with a better solution.
—Kent Beck, Test Driven Development by Example
12
Chapter 1 ■ The Basics
Figure 1-12. The TDD steps repeat to form the TDD cycle
In the first step, we write a test. In the second step, we record a requirement as a test. We also explicitly
design the client API. Designing the API here means answering questions such as the following:
• Does the method name reveal the intent?
• Should this be an instance method or a class method?
• What are the parameters to this method?
• What are the required parameters?
• What are the optional parameters?
• Should this parameter be passed in to the constructor instead of being passed in to
the method?
• Should the parameter have a default value?
13
Another Random Scribd Document
with Unrelated Content
That each thrice third night from its rim there fell
Eight rings, as their parent fair.”
The Dwarfs, Oehlenschläger (Pigott’s tr.).
Now a lump of iron was cast in the flames, and with a new caution
not to forfeit their success by inattention, Sindri passed out, leaving
Brock to ply the bellows and wrestle with the gadfly, which this time
stung him above the eye until the blood began to flow in such a
stream, that it prevented his seeing what he was doing. Hastily raising
his hand for a second, Brock dashed aside the stream of blood; but
short as was the interruption, Sindri uttered an exclamation of
disappointment when he drew his work out of the fire, for the hammer
he had fashioned had too short a handle.
“Then the dwarf raised his hand to his brow for the smart,
Ere the iron well out was beat,
And they found that the haft by an inch was too short,
But to alter it then ’twas too late.”
The Dwarfs, Oehlenschläger (Pigott’s tr.).
“Skrymir’s thongs
Seemed to thee hard,
When at the food thou couldst not get,
When, in full health, of hunger dying.”
Sæmund’s Edda (Thorpe’s tr.).
Angry because of his snoring, which kept them awake, Thor thrice
dealt him fearful blows with his hammer. These strokes, instead of
Utgard-loki. annihilating the monster, merely evoked sleepy
comments to the effect that a leaf, a bit of bark, or a
twig from a bird’s nest overhead had fallen upon his face. Early on the
morrow, Skrymir left Thor and his companions, pointing out the
shortest road to Utgard-loki’s castle, which was built of great ice
blocks, with huge glittering icicles as pillars. The gods, slipping
between the bars of the great gate, presented themselves boldly
before the king of the giants, Utgard-loki, who, recognizing them,
immediately pretended to be greatly surprised at their small size, and
expressed a wish to see for himself what they could do, as he had
often heard their prowess vaunted.
Loki, who had fasted longer than he wished, immediately declared
he was ready to eat for a wager with any one. So the king ordered a
great wooden trough full of meat to be brought into the hall, and
placing Loki at one end and his cook Logi at the other, he bade them
see which would win. Although Loki did wonders, and soon reached
the middle of the trough, he still found himself beaten, for whereas he
had picked the bones clean, his opponent had devoured both them
and the trough.
Smiling contemptuously, Utgard-loki said that it was evident they
could not do much in the eating line, and so nettled Thor thereby, that
he declared if Loki could not eat more than the voracious cook, he felt
confident he could drain the biggest vessel in the house, such was his
unquenchable thirst. Immediately a horn was brought in, and, Utgard-
loki declaring that good drinkers emptied it at one draught, moderately
thirsty persons at two, and small drinkers at three, Thor applied his
lips to the rim. But, although he drank so deep that he thought he
would burst, the liquid still came almost up to the rim when he raised
his head. A second and third attempt to empty this horn proved
equally unsuccessful. Thialfi then offered to run a race, and a young
fellow named Hugi soon outstripped him, although he made
remarkably good time.
Thor next proposed to show his strength by lifting great weights,
but when challenged to pick up the giant’s cat, he tugged and
strained, only to succeed in raising one paw from the floor, although
he had taken the precaution to enhance his strength as much as
possible by tightening his belt Megin-giörd.
Thialfi, who, in the mean while, had disposed of the great clay
giant with its cowardly mare’s heart, now rushed to his master’s
rescue; but all his efforts and those of the assembled gods, whom he
quickly summoned, could not raise the pinioning leg. While they were
standing there, helplessly wondering what they should do next, Thor’s
little son Magni came up. According to varying accounts, he was then
only three days or three years old, but he quickly seized the giant’s
foot, and, unaided, set his father free, declaring that had he only been
summoned sooner he would easily have disposed of both giant and
squire. This exhibition of strength upon his part made the gods
wonder greatly, and helped them to recognize the truth of the various
predictions, which one and all declared that their descendants would
be mightier than they, would survive them, and would rule in their turn
over the new heaven and earth.
To reward his son for his timely aid, Thor gave him the steed
Gullfaxi (golden-maned), to which he had fallen heir by right of
conquest, and Magni ever after rode this marvelous horse, which
almost equaled the renowned Sleipnir in speed and endurance.
After vainly trying to remove the stone splinter from his forehead,
Thor sadly returned home to Thrud-vang, where Sif’s
Groa, the
sorceress. loving efforts were equally unsuccessful. She therefore
resolved to send for Groa (green-making), a sorceress,
noted for her skill in medicine and for the efficacy of her spells and
incantations. Groa immediately signified her readiness to render every
service in her power to the god who had so often benefited her, and
solemnly began to recite powerful runes, under whose influence Thor
felt the stone grow looser and looser. In his delight at the prospect of a
speedy deliverance, Thor wished to reward the enchantress. Knowing
that nothing could give greater pleasure to a mother than the prospect
of seeing a long-lost child, he therefore told her he had recently
crossed the Elivagar, or ice streams, to rescue her little son Orvandil
(germ) from the frost giants’ cruel power, and had succeeded in
carrying him off in a basket. But, as the little rogue would persist in
sticking one of his bare toes through a hole in the basket, it had been
frost bitten, and Thor, accidentally breaking it off, had flung it up into
the sky, where it shone as a star, known in the North as “Orvandil’s
Toe.”
Delighted with these tidings, the prophetess paused in her
incantations to express her joy, but, having forgotten just where she
left off, she was never able to continue her spell, and the flint stone
remained imbedded in Thor’s forehead, whence it could never be
dislodged.
Of course, as Thor’s hammer always did him such good service, it
was the most prized of all his possessions, and his dismay was very
great when he awoke one morning and found it gone. His cry of anger
and disappointment soon brought Loki to his side, and to him Thor
confided the secret of his loss, declaring that were the giants to hear
of it, they would soon attempt to storm Asgard and destroy the gods.
Loki declared he would try to discover the thief and recover the
hammer, if Freya would only lend him her falcon
Thor and
Thrym. plumes, and immediately hastened off to Folkvang to
borrow them. In the form of a bird he then winged his
flight across the river Ifing, and over the barren stretches of Jötun-
heim, where he shrewdly suspected the thief was to be found. There
he saw Thrym, prince of the frost giants and god of the destructive
thunder storm, sitting alone on a hillside, and, artfully questioning him,
soon learned that he had stolen the hammer, had buried it deep
underground, and would never give it up unless Freya were brought to
him, in bridal array, ready to become his wife.
“Once I employed
My asamight
In the realm of giants,
When Gialp and Greip,
Geirrod’s daughters,
Wanted to lift me to heaven.”
Norse Mythology (R. B. Anderson).
Geirrod now challenged Thor to show his strength and skill, and
without waiting for the preconcerted signal, flung a red-hot wedge at
him. Thor, quick of eye and a practiced catcher, caught the missile
with the giantess’s iron glove, and hurled it back at his opponent.
Such was the force of the god, that the missile passed, not only
through the pillar behind which the giant had taken refuge, but through
him and the wall of the house, and buried itself deep in the earth
without.
Thor then marched up to the giant’s corpse, which at the blow
from his weapon had been changed into stone, and set it up in a
conspicuous place, as a monument of his strength and of the victory
he had won over his redoubtable foes, the mountain giants.
Thor’s name has been given to many of the places he was wont to
Worship of frequent, such as the principal harbor of the Faroe
Thor. Islands, and to families which claim to be descended
from him. It is still extant in such names as Thunderhill
in Surrey, and in the family names of Thorburn and Thorwaldsen, but
is most conspicuous in the name of one of the days of the week,
Thor’s day or Thursday.
Tyr, Tiu, or Ziu was the son of Odin, and, according to different
mythologists, his mother was either Frigga, queen of the gods, or a
beautiful giantess whose name is unknown, but who was a
personification of the raging sea. He is the god of martial honor, and
one of the twelve principal deities of Asgard. Although he appears to
have had no special dwelling there, he was always welcome to
Vingolf or Valhalla, and occupied one of the twelve thrones in the
great council hall of Glads-heim.
Tyr was regarded also as the god of courage and of war, and
therefore frequently invoked by the various nations of
The god of
war. the North, who cried to him as well as to Odin to
obtain victory. That he ranked next to Odin and Thor is
proved by his name, Tiu, having been given to one of the days of the
week, Tiu’s day, which in modern English has become Tuesday.
Under the name of Ziu, Tyr was the principal divinity of the Suabians,
who originally called their capital, the modern Augsburg, Ziusburg.
This people, venerating the god as they did, were wont to worship
him under the emblem of a sword, his distinctive attribute, and in his
honor held great sword dances, where various figures were carried
out. Sometimes the participants forming two long lines, crossed their
swords, point upwards, and challenged the boldest among their
number to take a flying leap over them. At other times the warriors
joined their sword points closely together in the shape of a rose or
wheel, and when this figure was complete invited their chief to stand
on the navel thus formed of flat, shining steel blades, and then they
bore him upon it through the camp in triumph. The sword point was
further considered so sacred that it became customary to register
oaths upon it.
Tyr was identical with the Saxon god Saxnot (from sax, a sword),
and with Er, Heru, or Cheru, the chief divinity of the Cheruski, who
also considered him god of the sun, and deemed his shining sword
blade an emblem of its rays.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com