100% found this document useful (8 votes)
30 views

Jasmine JavaScript Testing 2nd Edition Test your JavaScript applications efficiently using Jasmine and React js Paulo Ragonha All Chapters Instant Download

applications

Uploaded by

oylerhanifft
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (8 votes)
30 views

Jasmine JavaScript Testing 2nd Edition Test your JavaScript applications efficiently using Jasmine and React js Paulo Ragonha All Chapters Instant Download

applications

Uploaded by

oylerhanifft
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Download the full version of the ebook at

https://ebookfinal.com

Jasmine JavaScript Testing 2nd Edition Test


your JavaScript applications efficiently
using Jasmine and React js Paulo Ragonha

https://ebookfinal.com/download/jasmine-
javascript-testing-2nd-edition-test-your-
javascript-applications-efficiently-using-jasmine-
and-react-js-paulo-ragonha/

Explore and download more ebook at https://ebookfinal.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Reinventing Cybersecurity 1st Edition Jasmine Henry

https://ebookfinal.com/download/reinventing-cybersecurity-1st-edition-
jasmine-henry/

ebookfinal.com

Learning Three js the JavaScript 3D Library for WebGL 2nd


Edition Jos Dirksen

https://ebookfinal.com/download/learning-three-js-the-
javascript-3d-library-for-webgl-2nd-edition-jos-dirksen/

ebookfinal.com

Test Driven JavaScript Development 1st Edition Christian


Johansen

https://ebookfinal.com/download/test-driven-javascript-
development-1st-edition-christian-johansen/

ebookfinal.com

Continuous Testing with Ruby Rails and JavaScript 1st


Edition Ben Rady

https://ebookfinal.com/download/continuous-testing-with-ruby-rails-
and-javascript-1st-edition-ben-rady/

ebookfinal.com
Using Node js for UI Testing 1st Edition Teixeira

https://ebookfinal.com/download/using-node-js-for-ui-testing-1st-
edition-teixeira/

ebookfinal.com

Dojo Using the Dojo JavaScript Library to Build Ajax


Applications 1st Edition James E. Harmon

https://ebookfinal.com/download/dojo-using-the-dojo-javascript-
library-to-build-ajax-applications-1st-edition-james-e-harmon/

ebookfinal.com

Learning JavaScript 2nd Edition Shelley Powers

https://ebookfinal.com/download/learning-javascript-2nd-edition-
shelley-powers/

ebookfinal.com

Object Oriented JavaScript 2nd Edition Stoyan Stefanov

https://ebookfinal.com/download/object-oriented-javascript-2nd-
edition-stoyan-stefanov/

ebookfinal.com

Pro JavaScript Techniques 2nd Edition John Resig

https://ebookfinal.com/download/pro-javascript-techniques-2nd-edition-
john-resig/

ebookfinal.com
Jasmine JavaScript Testing 2nd Edition Test your
JavaScript applications efficiently using Jasmine and
React js Paulo Ragonha Digital Instant Download
Author(s): Paulo Ragonha
ISBN(s): 9781785282041, 1785282042
File Details: PDF, 1.55 MB
Year: 2015
Language: english
[1]

www.it-ebooks.info
Jasmine JavaScript Testing
Second Edition

Test your JavaScript applications efficiently


using Jasmine and React.js

Paulo Ragonha

BIRMINGHAM - MUMBAI

www.it-ebooks.info
Jasmine JavaScript Testing
Second Edition

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: August 2013


Second edition: April 2015

Production reference: 1210415

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.

ISBN 978-1-78528-204-1

www.packtpub.com

www.it-ebooks.info
Credits

Author Project Coordinator


Paulo Ragonha Suzanne Coutinho

Reviewers Proofreaders
Hany A. Elemary Paul Hindle
Ryzhikov Maksim Linda Morris
Veer Shubhranshu Shrivastav
Sergey Simonchik Indexer
Tejal Soni

Commissioning Editor
Amarabha Banerjee Production Coordinator
Aparna Bhagat

Acquisition Editor
Larissa Pinto Cover Work
Aparna Bhagat

Content Development Editor


Manasi Pandire

Technical Editor
Anushree Arun Tendulkar

Copy Editor
Sarang Chari

www.it-ebooks.info
About the Author

Paulo Ragonha is a software engineer with over 7 years of professional experience.


An advocate of the open Web, he is inspired and driven to build compelling
experiences on top of this ubiquitous platform.

He loves to hack, so you will often see him wandering around in conferences or
attending hackathons. His most recent professional experiences ranged from DevOps
(with Chef and Docker) to moving up the stack with Node.js, Ruby, and Python and
all the way toward building single-page applications (mostly with Backbone.js and
"ad hoc" solutions).

Passionate about automation, he sees testing as a liberating tool to enjoy the craft of
writing code even more. Back in 2013, he wrote the first edition of the book Jasmine
JavaScript Testing, Packt Publishing.

Paulo has an amazing wife, who he loves very much. He lives in beautiful
Florianópolis, a coastal city in the south of Brazil. He is a casual speaker, a biker,
a runner, and a hobbyist photographer.

www.it-ebooks.info
About the Reviewers

Hany A. Elemary is a software engineer / technical team lead at OCLC in


Columbus, Ohio, currently working on the next generation of mobile/web apps
(http://www.worldcat.org and WorldCat for local institutions). He has been blessed
with diverse experience while working for multiple companies (from small software
shops to large corporations) and seeing different releasable software strategies. He
has a clear focus and passion for mobile/web UI design, interactions, usability, and
accessibility. When there is time, he enjoys playing his acoustic guitar, AnnaMaria.

Special thanks to my close friends and family for always pushing me


to be better in every aspect of life.

Ryzhikov Maksim is a 27-year-old software developer from Saint Petersburg,


Russia.

He develops complex web applications. He graduated from the physics faculty at


Saint Petersburg State University. His journey into the world of software development
started not so long ago—5 years ago.

His brother invited him to join the team that developed programs for American
hospitals, as an HTML developer.

Ryzhikov started with developing a simple, static site for hospitals and then studied
JavaScript, Ruby, and SQL and worked as a full-stack developer. In 5 years of work
in the area of IT, he has worked in various projects and teams. He developed medical
systems, dating sites, web mail (Yandex.Mail), and now he helps develop tools for
developers at JetBrains.

www.it-ebooks.info
Veer Shubhranshu Shrivastav is an Indian software developer working
with Tata Consultancy Services since 2013 and is a former research intern at IIIT-
Delhi. He has worked on different technologies, such as PHP, Moodle, jQuery,
AngularJS, RequireJS, Android, Jasmine, Ionic, and so on, and also takes an interest
in cryptography, network security, and database technologies. He has worked with
various Indian IT start-ups, helping them as a software architect.

With his interest in the open source community, he developed a Pro*C library
named CODBC, which is available at http://codbc.com. The library enables
an object-oriented approach to connect C++ and Oracle Database.

Sergey Simonchik is a software developer living and working in Saint Petersburg,


Russia. He is lucky because he has a wonderful wife and a kind cat. Sergey develops
the WebStorm IDE at JetBrains. He is working on improving JavaScript unit testing
support and other IDE features.

www.it-ebooks.info
www.PacktPub.com
Support files, eBooks, discount offers,
and more
For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and
as a print book customer, you are entitled to a discount on the eBook copy. Get in touch
with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
and eBooks.
TM

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser

Free access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.

www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Preface v
Chapter 1: Getting Started with Jasmine 1
JavaScript – the bad parts 1
Jasmine and behavior-driven development 3
Downloading Jasmine 4
Summary 6
Chapter 2: Your First Spec 7
The Investment Tracker application 7
Jasmine basics and thinking in BDD 8
Setup and teardown 14
Nested describes 18
Setup and teardown 19
Coding a spec with shared behavior 19
Understanding matchers 20
Custom matchers 21
Built-in matchers 26
Summary 32
Chapter 3: Testing Frontend Code 33
Thinking in terms of components (Views) 34
The module pattern 35
Using HTML fixtures 36
Basic View coding rules 40
The View should encapsulate a DOM element 41
Integrating Views with observers 43
Testing Views with jQuery matchers 48
The toBeMatchedBy jQuery matcher 49
The toContainHtml jQuery matcher 50
The toContainElement jQuery matcher 50

[i]

www.it-ebooks.info
Table of Contents

The toHaveValue jQuery matcher 50


The toHaveAttr jQuery matcher 50
The toBeFocused jQuery matcher 51
The toBeDisabled jQuery matcher 51
More matchers 51
Summary 51
Chapter 4: Asynchronous Testing – AJAX 53
Acceptance criterion 53
Setting up the scenario 55
Installing Node.js 55
Coding the server 55
Running the server 56
Writing the spec 57
Asynchronous setups and teardowns 57
Asynchronous specs 58
Timeout 59
Summary 60
Chapter 5: Jasmine Spies 61
The "bare" spy 61
Spying on an object's functions 62
Testing DOM events 63
Summary 64
Chapter 6: Light Speed Unit Testing 65
Jasmine stubs 65
Jasmine Ajax 67
Installing the plugin 67
A fake XMLHttpRequest 67
Summary 69
Chapter 7: Testing React Applications 71
Project setup 72
Our first React component 72
The Virtual DOM 75
JSX 76
Using JSX with Jasmine 78
Component attributes (props) 80
Component events 82
Component state 85
Component life cycle 89
Composing components 91
Summary 92
[ ii ]

www.it-ebooks.info
Table of Contents

Chapter 8: Build Automation 93


Module bundler – webpack 94
Module definition 94
Webpack project setup 95
Managing dependencies with NPM 96
Webpack configuration 97
The spec runner 99
Testing a module 100
Test runner: Karma 100
Quick feedback loop 102
Watch and run the tests 102
Watch and update the browser 103
Optimizing for production 103
Static code analysis: JSHint 105
Continuous integration – Travis-CI 107
Adding a project to Travis-CI 107
Project setup 108
Summary 108
Index 109

[ iii ]

www.it-ebooks.info
www.it-ebooks.info
Preface
This book is about being a better JavaScript developer. So, throughout the chapters,
you will not only learn about writing tests in the Jasmine 'idiom', but also about
the best practices in writing software in the JavaScript language. It is about
acknowledging JavaScript as a real platform for application development and
leveraging all its potential. It is also about tooling and automation and how to make
your life easier and more productive.

Most importantly, this book is about craftsmanship of not only working software,
but also well-crafted software.

Jasmine JavaScript Testing, Second Edition is a practical guide to writing and


automating JavaScript testing for web applications. It uses technologies such as
Jasmine, Node.js, and webpack.

Over the course of the chapters, the concept of test-driven development is explained
through the development of a simple stock market Investment Tracker application. It
starts with the basics of testing through the development of the base domain classes
(such as stock and investment), passes through the concepts of maintainable browser
code, and concludes with a full refactoring to a React.js application build on ECMA
Script 6 modules and automated build.

What this book covers


Chapter 1, Getting Started with Jasmine, covers the motivations behind testing a
JavaScript application. It presents the concept of BDD and how it helps you to write
better tests. It also demonstrates how easy it is to download Jasmine and start coding
your first tests.

[v]

www.it-ebooks.info
Preface

Chapter 2, Your First Spec, helps you learn the thought process behind thinking
in terms of test-driven development. You will code your very first JavaScript
functionality driven by tests. You will also learn the basic functions of Jasmine
and how to structure your tests. Also demonstrated, is how Jasmine matchers work
and how you can create one of your own to improve your tests' code readability.

Chapter 3, Testing Frontend Code, covers some patterns in writing maintainable


browser code. You will learn about thinking in terms of components and how to use
the module pattern to better organize your source files. You will also be presented
with the concept of HTML fixtures and how you can use it to test your JavaScript
code without requiring your servers to render an HTML. You will also learn about
a Jasmine plugin called jasmine-jquery and how it can help you write better tests
with jQuery.

Chapter 4, Asynchronous Testing – AJAX, talks about the challenges in testing AJAX
requests and how you can use Jasmine to test any asynchronous code. You will learn
about Node.js and how to create a very simple HTTP server to use as a fixture to
your tests.

Chapter 5, Jasmine Spies, presents the concept of test doubles and how to use spies to
do behavior checking.

Chapter 6, Light Speed Unit Testing, helps you to learn about the issues with AJAX
testing and how you can make your tests run faster using stubs or fakes.

Chapter 7, Testing React Applications, introduces you to React, a library to build user
interfaces, and covers how you can use it to improve the concepts presented in
Chapter 3, Testing Frontend Code, to create richer and more maintainable applications,
of course, driven by tests.

Chapter 8, Build Automation, presents you with the power of automation. It introduces
you to webpack, a bundling tool for frontend assets. You will start to think in terms
of modules and their dependencies, and you will learn how to code your tests as
modules. You will also learn about packing and minifying the code to production
and how to automate this process. Finally, you are going to learn about running your
tests from a command line and how this can be used in a continuous integration
environment with Travis.ci.

[ vi ]

www.it-ebooks.info
Preface

What you need for this book


Besides a browser and a text editor, the only requirement to run some of the
examples, is Node.js 0.10.x.

Who this book is for


This book is a must-have material for web developers new to the concept of unit
testing. It's assumed that you have a basic knowledge of JavaScript and HTML.

Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.

Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"We can include other contexts through the use of the include directive."

A block of code is set as follows:


describe("Investment", function() {
it("should be of a stock", function() {
expect(investment.stock).toBe(stock);
});
});

When we wish to draw your attention to a particular part of a code block, the relevant
lines or items are set in bold:
describe("Investment", function() {
it("should be of a stock", function() {
expect(investment.stock).toBe(stock);
});
});

Any command-line input or output is written as follows:


# npm install --save-dev webpack

New terms and important words are shown in bold. Words that you see on
the screen, for example, in menus or dialog boxes, appear in the text like this:
"Clicking the Next button moves you to the next screen."

[ vii ]

www.it-ebooks.info
Preface

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention


the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.

Downloading the example code


You can download the example code files from your account at http://www.
packtpub.com for all the Packt Publishing books you have purchased. If you
purchased this book elsewhere, you can visit http://www.packtpub.com/support
and register to have the files e-mailed directly to you.

[ viii ]

www.it-ebooks.info
Preface

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/


content/support and enter the name of the book in the search field. The required
information will appear under the Errata section.

Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.

Please contact us at [email protected] with a link to the suspected


pirated material.

We appreciate your help in protecting our authors and our ability to bring you
valuable content.

Questions
If you have a problem with any aspect of this book, you can contact us at
[email protected], and we will do our best to address the problem.

[ ix ]

www.it-ebooks.info
www.it-ebooks.info
Getting Started with Jasmine
It is an exciting time to be a JavaScript developer; technologies have matured,
web browsers are more standardized, and there are new things to play with every
day. JavaScript has become an established language, and the Web is the true
open platform of today. We've seen the rise of single-page web applications, the
proliferation of Model View Controller (MVC) frameworks, such as Backbone.js
and AngularJS, the use of JavaScript on the server with Node.js, and even mobile
applications created entirely with HTML, JavaScript, and CSS using technologies
such as PhoneGap.

From its humble beginnings with handling HTML forms, to the massive applications
of today, the JavaScript language has come very far, and with it, a number of tools
have matured to ensure that you can have the same level of quality with it that you
have with any other language.

This book is about the tools that keep you in control of your JavaScript development.

JavaScript – the bad parts


There are many complications when dealing with client JavaScript code; the obvious
one, is that you cannot control the client's runtime. While on the server, you can
run a specific version of your Node.js server, you can't oblige your clients to run the
latest version of Chrome or Firefox.

The JavaScript language is defined by the ECMAScript specification; therefore, each


browser can have its own implementation of a runtime, which means there could be
small differences or bugs between them.

[1]

www.it-ebooks.info
Getting Started with Jasmine

Besides that, you have issues with the language itself. Brendan Eich developed
JavaScript in just 10 days, under a lot of management pressure at Netscape. Although
it got itself right in its simplicity, first-class functions, and object prototypes, it also
introduced some problems with the attempt to make the language malleable and
allow it to evolve.

Every JavaScript object is mutable; this means that there is nothing you can do to
prevent a module from overwriting pieces of other modules. The following code
illustrates how simple it is to overwrite the global console.log function:
console.log('test');
>> 'test'
console.log = 'break';
console.log('test');
>> TypeError: Property 'log' of object #<Console> is not a function

This was a conscious decision on the language design; it allows developers to tinker
and add missing functionality to the language. But given such power, it is relatively
easy to make a mistake.

Version 5 of the ECMA specification introduced the Object.seal function, which


prevents further changes on any object once called. But its current support is not
widespread; Internet Explorer, for example, only implemented it on its version 9.

Another problem, is with how JavaScript deals with type. In other languages, an
expression like '1' + 1 would probably raise an error; in JavaScript, due to some
non-intuitive type coercion rules, the aforementioned code results in '11'. But the
main problem is in its inconsistency; on multiplication, a string is converted into a
number, so '3' * 4, is actually 12.

This can lead to some hard-to-find problems on big expressions. Suppose you have
some data coming from a server, and although you are expecting numbers, one value
came as a string:
var a = 1, b = '2', c = 3, d = 4;
var result = a + b + c * d;

The resulting value of the preceding example is '1212', a string.

These are just two common problems faced by developers. Throughout the book,
you are going to apply best practices and write tests to guarantee that you don't fall
into these, and other, pitfalls.

[2]

www.it-ebooks.info
Chapter 1

Jasmine and behavior-driven


development
Jasmine is a little behavior-driven development (BDD) test framework created by
the developers at Pivotal Labs, to allow you to write automated JavaScript unit tests.

But before we can go any further, first we need to get some fundamentals right,
starting with what a test unit is.

A test unit is a piece of code that tests a functionality unit of the application code. But
sometimes, it can be tricky to understand what a functionality unit can be, so for that
reason, Dan North came up with a solution in the form of BDD, which is a rethink of
test-driven development (TDD).

In traditional unit testing practice, the developer is left with loose guidelines on how
to start the process of testing, what to test, how big a test should be, or even how to
call a test.

To fix these problems, Dan took the concept of user stories from the standard agile
construct, as a model on how to write tests.

For example, a music player application could have an acceptance criterion such as:

Given a player, when the song has been paused, then it should indicate that the
song is currently paused.

As shown in the following list, this acceptance criterion is written following an


underlying pattern:

• Given: This provides an initial context


• When: This defines the event that occurs
• Then: This ensures an outcome

In Jasmine, this translates into a very expressive language that allows tests to be
written in a way that reflects actual business values. The preceding acceptance
criterion written as a Jasmine test unit would be as follows:
describe("Player", function() {
describe("when song has been paused", function() {
it("should indicate that the song is paused", function() {

});
});
});

[3]

www.it-ebooks.info
Getting Started with Jasmine

You can see how the criterion translates well into the Jasmine syntax. In the next
chapter, we will get into the details of how these functions work.

With Jasmine, as with other BDD frameworks, each acceptance criterion directly
translates to a test unit. For that reason, each test unit is usually called a spec, short
for specification. During the course of this book, we will be using this terminology.

Downloading Jasmine
Getting started with Jasmine is actually pretty simple.

Open the Jasmine website at http://jasmine.github.io/2.1/introduction.


html#section-Downloads and download the Standalone Release (version 2.1.3 is
going to be used in the book).

While at the Jasmine website, you might notice that it is actually a live page
executing the specs contained in it. This is made possible by the simplicity of the
Jasmine framework, allowing it to be executed in the most diverse environments.

After you've downloaded the distribution and uncompressed it, you can open the
SpecRunner.html file on your browser. It will show the results of a sample test
suite (including the acceptance criterion we showed you earlier):

This shows the SpecRunner.html file opened on the browser

This SpecRunner.html file is a Jasmine browser spec runner. It is a simple HTML file
that references the Jasmine code, the source files, and the test files. For convention
purposes, we are going to refer to this file simply as runner.

[4]

www.it-ebooks.info
Chapter 1

You can see how simple it is by opening it on a text editor. It is a small HTML file
that references the Jasmine source:
<script src="lib/jasmine-2.1.3/jasmine.js"></script>
<script src="lib/jasmine-2.1.3/jasmine-html.js"></script>
<script src="lib/jasmine-2.1.3/boot.js"></script>

The runner references the source files:


<script type="text/javascript" src="src/Player.js"></script>
<script type="text/javascript" src="src/Song.js"></script>

The runner references a special SpecHelper.js file that contains code shared
between specs:
<script type="text/javascript" src="spec/SpecHelper.js"></script>

The runner also references the spec files:


<script type="text/javascript" src="spec/PlayerSpec.js"></script>

Downloading the example code


You can download the example code files for all Packt books you have
purchased from your account at http://www.packtpub.com. If you
purchased this book elsewhere, you can visit http://www.packtpub.
com/support and register to have the files e-mailed directly to you.

The Jasmine framework is set up inside the lib/jasmine-2.1.3/boot.js file, and


although it's an extensive file, most of its content is in documentation on how the
setup actually happens. It is recommended that you open it in a text editor and study
its content.

Although, for now, we are running the specs in the browser, in Chapter 8, Build
Automation, we are going to make the same specs and code run on a headless
browser, such as PhantomJS, and have the results written on the console.

A headless browser is a browser environment without its graphical user interface.


It can either be an actual browser environment, such as PhantomJS, which uses the
WebKit rendering engine, or a simulated browser environment, such as Envjs.

And although not covered in this book, Jasmine can also be used to test server-side
JavaScript code written for environments such as Node.js.

This Jasmine flexibility is amazing, because you can use the same tool to test all sorts
of JavaScript code.

[5]

www.it-ebooks.info
Getting Started with Jasmine

Summary
In this chapter, you saw some of the motivations behind testing a JavaScript
application. I showed you some common pitfalls of the JavaScript language
and how BDD and Jasmine both help you to write better tests.

You have also seen how easy it is to download and get started with Jasmine.

In the next chapter, you are going to learn how to think in BDD and code your
very first spec.

[6]

www.it-ebooks.info
Your First Spec
This chapter is about the basics, and we are going to guide you through how to write
your first spec, think in test-first terms for development, and also show you all the
available global Jasmine functions. By the end of the chapter, you should know how
Jasmine works and be ready to start doing your first tests by yourself.

The Investment Tracker application


To get you started, we need an example scenario: consider that you are developing
an application to track investments in the stock market.

The following screenshot of the form illustrates how a user might create a new
investment on this application:

This is a form to add investments

This form will allow the input of three values that define an investment:

• First, we will input Symbol, which represents which company (stock) the
user is investing in
• Then, we will input how many Shares the user has bought (or invested in)
• Finally, we will input how much the user has paid for each share
(Share price)

[7]

www.it-ebooks.info
Your First Spec

If you are unfamiliar with how the stock market works, imagine you are shopping
for groceries. To make a purchase, you must specify what you are buying, how many
items you are buying, and how much you are going to pay. These concepts translate
to an investment as:

• A stock, which is defined by a symbol, such as PETO, can be understood to be


a grocery type
• The number of shares is the quantity of items you have purchased
• The share price is the unit price of each item

Once the user has added an investment, it must be listed along with their other
investments, as shown in the following screenshot:

This is a form and list of investments

The idea is to display how well their investments are going. Since the prices of the
stocks fluctuate over time, the difference between the price the user has paid and
the current price indicates whether it is a good (profit) or a bad (loss) investment.

In the preceding screenshot, we can see that the user has two investments:

• One is in the AOUE stock, which is scoring a profit of 101.80%


• Another is in the PETO stock, which is scoring a loss of -42.34%

This is a very simple application, and we will get a deeper understanding of its
functionality as we go on with its development.

Jasmine basics and thinking in BDD


Based on the application presented previously, we can start writing acceptance
criteria that define investment:

• Given an investment, it should be of a stock


• Given an investment, it should have the invested shares' quantity

[8]

www.it-ebooks.info
Chapter 2

• Given an investment, it should have the share price paid


• Given an investment, it should have a cost

Using the standalone distribution downloaded in the previous chapter, the first
thing we need to do is create a new spec file. This file can be created anywhere,
but it is a good idea to stick to a convention, and Jasmine already has a good one:
specs should be in the /spec folder. Create an InvestmentSpec.js file and add
the following lines:
describe("Investment", function() {

});

The describe function is a global Jasmine function used to define test contexts.
When used as the first call in a spec, it creates a new test suite (a collection of test
cases). It accepts two parameters, which are as follows:

• The name of the test suite—in this case, Investment


• A function that will contain all its specs

Then, to translate the first acceptance criterion (given an investment, it should be of


a stock) into a Jasmine spec (or test case), we are going to use another global Jasmine
function called it:
describe("Investment", function() {
it("should be of a stock", function() {

});
});

It also accepts two parameters, which are as follows:

• The title of the spec—in this case, should be of a stock


• A function that will contain the spec code

To run this spec, add it to the runner, as follows:


<!-- include spec files here... -->
<script type="text/javascript" src="spec/InvestmentSpec.js"></script>

[9]

www.it-ebooks.info
Your First Spec

Execute the spec by opening the runner on the browser. The following output
can be seen:

This is the first spec's passing result on the browser

It might sound strange to have an empty spec passing, but in Jasmine, as with other
test frameworks, a failed assertion is required to make the spec fail.

An assertion (or expectation) is a comparison between two values that must result
in a boolean value. The assertion is only considered a success if the result of the
comparison is true.

In Jasmine, assertions are written using the global Jasmine function expect, along
with a matcher that indicates what comparison must be made with the values.

Regarding the current spec (it is expected that the investment is of a stock), in
Jasmine this translates to the following code:
describe("Investment", function() {
it("should be of a stock", function() {
expect(investment.stock).toBe(stock);
});
});

Add the preceding highlighted code to the InvestmentSpec.js file. The expect
function takes only one parameter, which defines the actual value, or in other words,
what is going to be tested—investment.stock—and expects the chaining call to a
matcher function, which in this case is toBe. That defines the expected value, stock,
and the comparison method to be performed (to be the same).

Behind the scenes, Jasmine makes a comparison to check whether the actual value
(investment.stock) and expected value (stock) are the same, and if they are not,
the test fails.

[ 10 ]

www.it-ebooks.info
Chapter 2

With the assertion written, the spec that previously passed has now failed, as shown
in the following screenshot:

This shows the first spec's failure results

This spec failed because, as the error message states, investment is not defined.

The idea here is to do only what the error is indicating us to do, so although you
might feel the urge to write something else, for now let's just create this investment
variable with an Investment instance in the InvestmentSpec.js file, as follows:
describe("Investment", function() {
it("should be of a stock", function() {
var investment = new Investment();
expect(investment.stock).toBe(stock);
});
});

Don't worry that the Investment() function doesn't exist yet; the spec is about to
ask for it on the next run, as follows:

Here the spec asks for an Investment class

You can see that the error has changed to Investment is not defined. It now asks
for the Investment function. So, create a new Investment.js file in the src folder
and add it to the runner, as shown in the following code:
<!-- include source files here... -->
<script type="text/javascript" src="src/Investment.js"></script>

[ 11 ]

www.it-ebooks.info
Your First Spec

To define Investment, write the following constructor function in the Investment.


js file inside the src folder:

function Investment () {};

This makes the error change. It now complains about the missing stock variable, as
shown in the following screenshot:

This shows a missing stock error

One more time, we feed the code it is asking for into the InvestmentSpec.js file,
as shown in the following code:
describe("Investment", function() {
it("should be of a stock", function() {
var stock = new Stock();
var investment = new Investment();
expect(investment.stock).toBe(stock);
});
});

The error changes again; this time it is about the missing Stock function:

Here the spec asks for a Stock class

Create a new file in the src folder, name it Stock.js, and add it to the runner. Since
the Stock function is going to be a dependency of Investment, we should add it just
before Investment.js:
<!-- include source files here... -->
<script type="text/javascript" src="src/Stock.js"></script>
<script type="text/javascript" src="src/Investment.js"></script>

[ 12 ]

www.it-ebooks.info
Chapter 2

Write the Stock constructor function to the Stock.js file:


function Stock () {};

Finally, the error is about the expectation, as shown in the following screenshot:

The expectation is undefined to be Stock

To fix this and complete this exercise, open the Investment.js file inside the src
folder, and add the reference to the stock parameter:
function Investment (stock) {
this.stock = stock;
};

In the spec file, pass stock as a parameter to the Investment function:


describe("Investment", function() {
it("should be of a stock", function() {
var stock = new Stock();
var investment = new Investment(stock);
expect(investment.stock).toBe(stock);
});
});

Finally, you will have a passing spec:

This shows an Investment spec that passes

This exercise was meticulously conducted to show how a developer works by


feeding the spec with what it wants when doing test-first development.

The drive to write code must come from a spec that has failed. You
must not write code unless its purpose is to fix a failed spec.

[ 13 ]

www.it-ebooks.info
Your First Spec

Setup and teardown


There are three more acceptance criteria to be implemented. The next in the list is
as follows:

"Given an investment, it should have the invested shares' quantity."

Writing it should be as simple as the previous spec was. In the InvestmentSpec.js


file inside the spec folder, you can translate this new criterion into a new spec called
should have the invested shares' quantity, as follows:

describe("Investment", function() {
it("should be of a stock", function() {
var stock = new Stock();
var investment = new Investment({
stock: stock,
shares: 100
});
expect(investment.stock).toBe(stock);
});

it("should have the invested shares' quantity", function() {


var stock = new Stock();
var investment = new Investment({
stock: stock,
shares: 100
});
expect(investment.shares).toEqual(100);
});
});

You can see that apart from having written the new spec, we have also changed the
call to the Investment constructor to support the new shares parameter.

To do so, we used an object as a single parameter in the constructor to simulate


named parameters, a feature JavaScript doesn't have natively.

Implementing this in the Investment function is pretty simple—instead of having


multiple parameters on the function declaration, it has only one, which is expected
to be an object. Then, the function probes each of its expected parameters from this
object, making the proper assignments, as shown here:
function Investment (params) {
this.stock = params.stock;
};

[ 14 ]

www.it-ebooks.info
Chapter 2

The code is now refactored. We can run the tests to see that only the new spec fails,
as shown here:

This shows the failing shares spec

To fix this, change the Investment constructor to make the assignment to the shares
property, as follows:
function Investment (params) {
this.stock = params.stock;
this.shares = params.shares;
};

Finally, everything on your screen is green:

This shows the passing shares spec

But as you can see, the following code, which instantiates Stock and Investment, is
duplicated on both specs:
var stock = new Stock();
var investment = new Investment({
stock: stock,
shares: 100
});

To eliminate this duplication, Jasmine provides another global function called


beforeEach that, as the name states, is executed once before each spec. So, for
these two specs, it will run twice—once before each spec.

[ 15 ]

www.it-ebooks.info
Your First Spec

Refactor the previous specs by extracting the setup code using the beforeEach
function:
describe("Investment", function() {
var stock, investment;

beforeEach(function() {
stock = new Stock();
investment = new Investment({
stock: stock,
shares: 100
});
});

it("should be of a stock", function() {


expect(investment.stock).toBe(stock);
});

it("should have the invested shares quantity", function() {


expect(investment.shares).toEqual(100);
});
});

This looks much cleaner; we not only removed the code duplication, but also
simplified the specs. They became much easier to read and maintain since their
only responsibility now is to fulfill the expectation.

There is also a teardown function (afterEach) that sets the code to be executed after
each spec. It is very useful in situations where a cleanup is required after each spec.
We will see an example of its application in Chapter 6, Light Speed Unit Testing.

To finish the specification of Investment, add the remaining two specs to the
InvestmentSpec.js file, inside the spec folder:

describe("Investment", function() {
var stock;
var investment;

beforeEach(function() {
stock = new Stock();
investment = new Investment({
stock: stock,
shares: 100,
sharePrice: 20

[ 16 ]

www.it-ebooks.info
Chapter 2

});
});

//... other specs

it("should have the share paid price", function() {


expect(investment.sharePrice).toEqual(20);
});

it("should have a cost", function() {


expect(investment.cost).toEqual(2000);
});
});

Run the specs to see them fail, as shown in the following screenshot:

This shows the failing cost and price specs

Add the following code to fix them in the Investment.js file inside the src folder:
function Investment (params) {
this.stock = params.stock;
this.shares = params.shares;
this.sharePrice = params.sharePrice;
this.cost = this.shares * this.sharePrice;
};

[ 17 ]

www.it-ebooks.info
Your First Spec

Run the specs for the last time to see them pass:

This shows all four Investment specs passing

It is important to always see a spec fail before writing the code to fix it;
otherwise, how would you know that you really need to fix it? Imagine
this as a way to test the test.

Nested describes
Nested describes are useful when you want to describe similar behavior between
specs. Suppose we want the following two new acceptance criteria:

• Given an investment, when its stock share price valorizes, it should have
a positive return on investment (ROI)
• Given an investment, when its stock share price valorizes, it should be
a good investment

Both these criteria share the same behavior when the investment's stock share
price valorizes.

To translate this into Jasmine, you can nest a call to the describe function inside the
existing one in the InvestmentSpec.js file (I removed the rest of the code for the
purpose of demonstration; it is still there):
describe("Investment", function()
describe("when its stock share price valorizes", function() {

});
});

It should behave just like the outer one, so you can add specs (it) and use the setup
and teardown functions (beforeEach, afterEach).

[ 18 ]

www.it-ebooks.info
Chapter 2

Setup and teardown


When using the setup and teardown functions, Jasmine respects the outer setup and
teardown functions as well, so that they are run as expected. For each spec (it), the
following actions are performed:

• Jasmine runs all setup functions (beforeEach) from the outside in


• Jasmine runs a spec code (it)
• Jasmine runs all the teardown functions (afterEach) from the inside out

So, we can add a setup function to this new describe function that changes the
share price of the stock, so that it's greater than the share price of the investment:
describe("Investment", function() {
var stock;
var investment;

beforeEach(function() {
stock = new Stock();
investment = new Investment({
stock: stock,
shares: 100,
sharePrice: 20
});
});

describe("when its stock share price valorizes", function() {


beforeEach(function() {
stock.sharePrice = 40;
});
});
});

Coding a spec with shared behavior


Now that we have the shared behavior implemented, we can start coding the
acceptance criteria described earlier. Each is, just as before, a call to the global
Jasmine function it:
describe("Investment", function() {
describe("when its stock share price valorizes", function() {
beforeEach(function() {
stock.sharePrice = 40;
});

[ 19 ]

www.it-ebooks.info
Your First Spec

it("should have a positive return of investment", function() {


expect(investment.roi()).toEqual(1);
});

it("should be a good investment", function() {


expect(investment.isGood()).toEqual(true);
});
});
});

After adding the missing functions to Investment in the Investment.js file:


Investment.prototype.roi = function() {
return (this.stock.sharePrice - this.sharePrice) / this.sharePrice;
};

Investment.prototype.isGood = function() {
return this.roi() > 0;
};

You can run the specs and see that they pass:

This shows the nested describe specs pass

Understanding matchers
By now, you've already seen plenty of usage examples for matchers and probably
can feel how they work.

You have seen how to use the toBe and toEqual matchers. These are the two
base built-in matchers available in Jasmine, but we can extend Jasmine by writing
matchers of our own.

So, to really understand how Jasmine matchers work, we need to create one ourselves.

[ 20 ]

www.it-ebooks.info
Chapter 2

Custom matchers
Consider this expectation from the previous section:
expect(investment.isGood()).toEqual(true);

Although it works, it is not very expressive. Imagine if we could instead rewrite it as:
expect(investment).toBeAGoodInvestment();

This creates a much better relation with the acceptance criterion:

So, here "should be a good investment" becomes "expect investment to be a


good investment".

Implementing it is quite simple. You do so by calling the jasmine.addMatchers


function—ideally inside a setup step (beforeEach).

Although you can put this new matcher definition inside the InvestmentSpec.js
file, Jasmine already has a default place to add custom matchers, the SpecHelper.js
file, inside the spec folder. If you are using Standalone Distribution, it already comes
with a sample custom matcher; delete it and let's start from scratch.

The addMatchers function accepts a single parameter—an object where each


attribute corresponds to a new matcher. So, to add the following new matcher,
change the contents of the SpecHelper.js file to the following:
beforeEach(function() {
jasmine.addMatchers({
toBeAGoodInvestment: function() {}
});
});

The function being defined here is not the matcher itself but a factory function
to build the matcher. Its purpose, once called is to return an object containing a
compare function, as follows:
jasmine.addMatchers({
toBeAGoodInvestment: function () {
return {
compare: function (actual, expected) {
// matcher definition
}
};
}
});

[ 21 ]

www.it-ebooks.info
Random documents with unrelated
content Scribd suggests to you:
RIP VAN WINKLE
A POSTHUMOUS WRITING OF DIEDRICH
KNICKERBOCKER

[From the “Sketch Book,” 1819–1820]

By Woden, God of Saxons,


From whence comes Wensday, that is Wodensday,
Truth is a thing that ever I will keep
Unto thylke day in which I creep into
My sepulchre——
Cartwright.

WHOEVER has made a voyage up the Hudson, must remember the


Kaatskill mountains. They are a dismembered branch of the great
Appalachian family, and are seen away to the west of the river,
swelling up to a noble height, and lording it over the surrounding
country. Every change of season, every change of weather, indeed,
every hour of the day, produces some change in the magical hues
and shapes of these mountains, and they are regarded by all the
good wives, far and near, as perfect barometers. When the weather
is fair and settled, they are clothed in blue and purple, and print their
bold outlines on the clear evening sky; but sometimes, when the rest
of the landscape is cloudless, they will gather a hood of gray vapours
about their summits, which, in the last rays of the setting sun, will
glow and light up like a crown of glory.
At the foot of these fairy mountains, the voyager may have
descried the light smoke curling up from a village, whose shingle
roofs gleam among the trees, just where the blue tints of the upland
melt away into the fresh green of the nearer landscape. It is a little
village of great antiquity, having been founded by some of the Dutch
colonists, in the early times of the province, just about the beginning
of the government of the good Peter Stuyvesant (may he rest in
peace!), and there were some of the houses of the original settlers
standing within a few years with lattice windows, gable fronts
surmounted with weathercocks, and built of small yellow bricks
brought from Holland.
In that same village, and in one of these very houses, (which, to
tell the precise truth, was sadly timeworn and weather-beaten,) there
lived many years since, while the country was yet a province of
Great Britain, a simple goodnatured fellow, of the name of Rip Van
Winkle. He was a descendant of the Van Winkles who figured so
gallantly in the chivalrous days of Peter Stuyvesant, and
accompanied him to the siege of Fort Christina. He inherited,
however, but little of the martial character of his ancestors. I have
observed that he was a simple good-natured man; he was moreover
a kind neighbour, and an obedient, henpecked husband. Indeed, to
the latter circumstance might be owing that meekness of spirit which
gained him such universal popularity; for those men are most apt to
be obsequious and conciliating abroad, who are under the discipline
of shrews at home. Their tempers, doubtless, are rendered pliant
and malleable in the fiery furnace of domestic tribulation, and a
curtain lecture is worth all the sermons in the world for teaching the
virtues of patience and long suffering. A termagant wife may,
therefore, in some respects, be considered a tolerable blessing; and
if so, Rip Van Winkle was thrice blessed.
Certain it is, that he was a great favourite among all the good
wives of the village, who, as usual with the amiable sex, took his part
in all family squabbles, and never failed, whenever they talked those
matters over in their evening gossippings, to lay all the blame on
Dame Van Winkle. The children of the village, too, would shout with
joy whenever he approached. He assisted at their sports, made their
playthings, taught them to fly kites and shoot marbles, and told them
long stories of ghosts, witches, and Indians. Whenever he went
dodging about the village, he was surrounded by a troop of them,
hanging on his skirts, clambering on his back, and playing a
thousand tricks on him with impunity; and not a dog would bark at
him throughout the neighbourhood.
The great error in Rip’s composition was an insuperable aversion
to all kinds of profitable labour. It could not be from the want of
assiduity or perseverance; for he would sit on a wet rock, with a rod
as long and heavy as a Tartar’s lance, and fish all day without a
murmur, even though he should not be encouraged by a single
nibble. He would carry a fowling-piece on his shoulder, for hours
together, trudging through woods and swamps, and up hill and down
dale, to shoot a few squirrels or wild pigeons. He would never even
refuse to assist a neighbour in the roughest toil, and was a foremost
man at all country frolicks for husking Indian corn, or building stone
fences. The women of the village, too, used to employ him to run
their errands, and to do such little odd jobs as their less obliging
husbands would not do for them;—in a word, Rip was ready to
attend to anybody’s business but his own; but as to doing family
duty, and keeping his farm in order, it was impossible.
In fact, he declared it was of no use to work on his farm; it was
the most pestilent little piece of ground in the whole country;
everything about it went wrong, and would go wrong, in spite of him.
His fences were continually falling to pieces; his cow would either go
astray, or get among the cabbages; weeds were sure to grow
quicker in his fields than anywhere else; the rain always made a
point of setting in just as he had some out-door work to do; so that
though his patrimonial estate had dwindled away under his
management, acre by acre, until there was little more left than a
mere patch of Indian corn and potatoes, yet it was the worst
conditioned farm in the neighbourhood.
His children, too, were as ragged and wild as if they belonged to
nobody. His son Rip, an urchin begotten in his own likeness,
promised to inherit the habits, with the old clothes of his father. He
was generally seen trooping like a colt at his mother’s heels,
equipped in a pair of his father’s cast-off galligaskins, which he had
much ado to hold up with one hand, as a fine lady does her train in
bad weather.
Rip Van Winkle, however, was one of those happy mortals, of
foolish, well-oiled dispositions, who take the world easy, eat white
bread or brown, whichever can be got with least thought or trouble,
and would rather starve on a penny than work for a pound. If left to
himself, he would have whistled life away, in perfect contentment;
but his wife kept continually dinning in his ears about his idleness,
his carelessness, and the ruin he was bringing on his family.
Morning, noon, and night, her tongue was incessantly going, and
everything he said or did was sure to produce a torrent of household
eloquence. Rip had but one way of replying to all lectures of the kind,
and that, by frequent use, had grown into a habit. He shrugged his
shoulders, shook his head, cast up his eyes, but said nothing. This,
however, always provoked a fresh volley from his wife, so that he
was fain to draw off his forces, and take to the outside of the house
—the only side which, in truth, belongs to a henpecked husband.
Rip’s sole domestic adherent was his dog Wolf, who was as
much henpecked as his master; for Dame Van Winkle regarded
them as companions in idleness, and even looked upon Wolf with an
evil eye, as the cause of his master’s so often going astray. True it is,
in all points of spirit befitting an honourable dog, he was as
courageous an animal as ever scoured the woods—but what
courage can withstand the ever-during and all-besetting terrors of a
woman’s tongue? The moment Wolf entered the house, his crest fell,
his tail drooped to the ground, or curled between his legs, he
sneaked about with a gallows air, casting many a sidelong glance at
Dame Van Winkle, and at the least flourish of a broomstick or ladle,
would fly to the door with yelping precipitation.
Times grew worse and worse with Rip Van Winkle as years of
matrimony rolled on; a tart temper never mellows with age, and a
sharp tongue is the only edged tool that grows keener by constant
use. For a long while he used to console himself, when driven from
home, by frequenting a kind of perpetual club of the sages,
philosophers, and other idle personages of the village, which held its
sessions on a bench before a small inn, designated by a rubicund
portrait of his majesty George the Third. Here they used to sit in the
shade, of a long lazy summer’s day, talking listlessly over village
gossip, or telling endless sleepy stories about nothing. But it would
have been worth any statesman’s money to have heard the profound
discussions which sometimes took place, when by chance an old
newspaper fell into their hands, from some passing traveller. How
solemnly they would listen to the contents, as drawled out by Derrick
Van Bummel, the schoolmaster, a dapper learned little man, who
was not to be daunted by the most gigantic word in the dictionary;
and how sagely they would deliberate upon public events some
months after they had taken place.
The opinions of this junto were completely controlled by Nicholas
Vedder, a patriarch of the village, and landlord of the inn, at the door
of which he took his seat from morning till night, just moving
sufficiently to avoid the sun, and keep in the shade of a large tree; so
that the neighbours could tell the hour by his movements as
accurately as by a sun dial. It is true, he was rarely heard to speak,
but smoked his pipe incessantly. His adherents, however, (for every
great man has his adherents,) perfectly understood him, and knew
how to gather his opinions. When anything that was read or related
displeased him, he was observed to smoke his pipe vehemently, and
send forth short, frequent, and angry puffs; but when pleased, he
would inhale the smoke slowly and tranquilly, and emit it in light and
placid clouds, and sometimes taking the pipe from his mouth, and
letting the fragrant vapour curl about his nose, would gravely nod his
head in token of perfect approbation.
From even this stronghold the unlucky Rip was at length routed
by his termagant wife, who would suddenly break in upon the
tranquillity of the assemblage, and call the members all to nought;
nor was that august personage, Nicholas Vedder himself, sacred
from the daring tongue of this terrible virago, who charged him
outright with encouraging her husband in habits of idleness.
Poor Rip was at last reduced almost to despair; and his only
alternative to escape from the labour of the farm and clamour of his
wife, was to take gun in hand, and stroll away into the woods. Here
he would sometimes seat himself at the foot of a tree, and share the
contents of his wallet with Wolf, with whom he sympathized as a
fellow sufferer in persecution. “Poor Wolf,” he would say, “thy
mistress leads thee a dog’s life of it; but never mind, my lad, while I
live thou shalt never want a friend to stand by thee!” Wolf would wag
his tail, look wistfully in his master’s face, and if dogs can feel pity, I
verily believe he reciprocated the sentiment with all his heart.
In a long ramble of the kind on a fine autumnal day, Rip had
unconsciously scrambled to one of the highest parts of the Kaatskill
mountains. He was after his favourite sport of squirrel shooting, and
the still solitudes had echoed and re-echoed with the reports of his
gun. Panting and fatigued, he threw himself, late in the afternoon, on
a green knoll, covered with mountain herbage, that crowned the
brow of a precipice. From an opening between the trees, he could
overlook all the lower country for many a mile of rich woodland. He
saw at a distance the lordly Hudson, far, far below him, moving on its
silent but majestic course, the reflection of a purple cloud, or the sail
of a lagging bark, here and there sleeping on its glassy bosom, and
at last losing itself in the blue highlands.
On the other side he looked down into a deep mountain glen,
wild, lonely, and shagged, the bottom filled with fragments from the
impending cliffs, and scarcely lighted by the reflected rays of the
setting sun. For some time Rip lay musing on this scene; evening
was gradually advancing, the mountains began to throw their long,
blue shadows over the valleys, he saw that it would be dark long
before he could reach the village, and he heaved a heavy sigh when
he thought of encountering the terrors of Dame Van Winkle.
As he was about to descend, he heard a voice from a distance,
hallooing, “Rip Van Winkle! Rip Van Winkle!” He looked around, but
could see nothing but a crow winging its solitary flight across the
mountain. He thought his fancy must have deceived him, and turned
again to descend, when he heard the same cry ring through the still
evening air; “Rip Van Winkle! Rip Van Winkle!”—at the same time
Wolf bristled up his back, and giving a low growl, skulked to his
master’s side, looking fearfully down into the glen. Rip now felt a
vague apprehension stealing over him; he looked anxiously in the
same direction, and perceived a strange figure slowly toiling up the
rocks, and bending under the weight of something he carried on his
back. He was surprised to see any human being in this lonely and
unfrequented place, but supposing it to be some one of the
neighbourhood in need of his assistance, he hastened down to yield
it.
On nearer approach, he was still more surprised at the
singularity of the stranger’s appearance. He was a short square built
old fellow, with thick bushy hair, and a grizzled beard. His dress was
of the antique Dutch fashion—a cloth jerkin strapped round the waist
—several pair of breeches, the outer one of ample volume,
decorated with rows of buttons down the sides, and bunches at the
knees. He bore on his shoulders a stout keg, that seemed full of
liquor, and made signs for Rip to approach and assist him with the
load. Though rather shy and distrustful of this new acquaintance, Rip
complied with his usual alacrity, and mutually relieving one another,
they clambered up a narrow gully, apparently the dry bed of a
mountain torrent. As they ascended, Rip every now and then heard
long rolling peals, like distant thunder, that seemed to issue out of a
deep ravine, or rather cleft between lofty rocks, toward which their
rugged path conducted. He paused for an instant, but supposing it to
be the muttering of one of those transient thunder showers which
often take place in mountain heights, he proceeded. Passing through
the ravine, they came to a hollow, like a small amphitheatre,
surrounded by perpendicular precipices, over the brinks of which
impending trees shot their branches, so that you only caught
glimpses of the azure sky, and the bright evening cloud. During the
whole time, Rip and his companion had laboured on in silence; for
though the former marvelled greatly what could be the object of
carrying a keg of liquor up this wild mountain, yet there was
something strange and incomprehensible about the unknown, that
inspired awe, and checked familiarity.
On entering the amphitheatre, new objects of wonder presented
themselves. On a level spot in the centre was a company of odd-
looking personages playing at nine-pins. They were dressed in a
quaint, outlandish fashion: some wore short doublets, others jerkins,
with long knives in their belts, and most had enormous breeches, of
similar style with that of the guide’s. Their visages, too, were
peculiar: one had a large head, broad face, and small piggish eyes;
the face of another seemed to consist entirely of nose, and was
surmounted by a white sugar-loaf hat, set off with a little red cock’s
tail. They all had beards, of various shapes and colours. There was
one who seemed to be the commander. He was a stout old
gentleman, with a weather-beaten countenance; he wore a laced
doublet, broad belt and hanger, high crowned hat and feather, red
stockings, and high heeled shoes, with roses in them. The whole
group reminded Rip of the figures in an old Flemish painting, in the
parlour of Dominie Van Schaick, the village parson, and which had
been brought over from Holland at the time of the settlement.
What seemed particularly odd to Rip, was that though these
folks were evidently amusing themselves, yet they maintained the
gravest faces, the most mysterious silence, and were, withal, the
most melancholy party of pleasure he had ever witnessed. Nothing
interrupted the stillness of the scene, but the noise of the balls,
which, whenever they were rolled, echoed along the mountains like
rumbling peals of thunder.
As Rip and his companion approached them, they suddenly
desisted from their play, and stared at him with such fixed statue-like
gaze, and such strange, uncouth, lacklustre countenances, that his
heart turned within him, and his knees smote together. His
companion now emptied the contents of the keg into large flagons,
and made signs to him to wait upon the company. He obeyed with
fear and trembling; they quaffed the liquor in profound silence, and
then returned to their game.
By degrees, Rip’s awe and apprehension subsided. He even
ventured, when no eye was fixed upon him, to taste the beverage,
which he found had much of the flavour of excellent Hollands. He
was naturally a thirsty soul, and was soon tempted to repeat the
draught. One taste provoked another, and he reiterated his visits to
the flagon so often, that at length his senses were overpowered, his
eyes swam in his head, his head gradually declined, and he fell into
a deep sleep.
On awaking, he found himself on the green knoll from whence
he had first seen the old man of the glen. He rubbed his eyes—it
was a bright sunny morning. The birds were hopping and twittering
among the bushes, and the eagle was wheeling aloft, and breasting
the pure mountain breeze. “Surely,” thought Rip, “I have not slept
here all night.” He recalled the occurrences before he fell asleep.
The strange man with a keg of liquor—the mountain ravine—the wild
retreat among the rocks—the woe-begone party at nine-pins—the
flagon—“Oh! that flagon! that wicked flagon!” thought Rip—“what
excuse shall I make to Dame Van Winkle?”
He looked round for his gun, but in place of the clean well-oiled
fowling-piece, he found an old firelock lying by him, the barrel
encrusted with rust, the lock falling off, and the stock worm-eaten.
He now suspected that the grave roysters of the mountain had put a
trick upon him, and having dosed him with liquor, had robbed him of
his gun. Wolf, too, had disappeared, but he might have strayed away
after a squirrel or partridge. He whistled after him, shouted his name,
but all in vain; the echoes repeated his whistle and shout, but no dog
was to be seen.
He determined to revisit the scene of the last evening’s gambol,
and if he met with any of the party, to demand his dog and gun. As
he rose to walk, he found himself stiff in the joints, and wanting in his
usual activity. “These mountain beds do not agree with me,” thought
Rip, “and if this frolic should lay me up with a fit of the rheumatism, I
shall have a blessed time with Dame Van Winkle.” With some
difficulty he got down into the glen; he found the gully up which he
and his companion had ascended the preceding evening; but to his
astonishment a mountain stream was now foaming down it, leaping
from rock to rock, and filling the glen with babbling murmurs. He,
however, made shift to scramble up its sides, working his toilsome
way through thickets of birch, sassafras, and witch hazle, and
sometimes tripped up or entangled by the wild grape vines that
twisted their coils and tendrils from tree to tree, and spread a kind of
network in his path.
At length he reached to where the ravine had opened through
the cliffs, to the amphitheatre; but no traces of such opening
remained. The rocks presented a high impenetrable wall, over which
the torrent came tumbling in a sheet of feathery foam, and fell into a
broad deep basin, black from the shadows of the surrounding forest.
Here, then, poor Rip was brought to a stand. He again called and
whistled after his dog; he was only answered by the cawing of a flock
of idle crows, sporting high in air about a dry tree that overhung a
sunny precipice; and who, secure in their elevation, seemed to look
down and scoff at the poor man’s perplexities. What was to be
done? the morning was passing away, and Rip felt famished for want
of his breakfast. He grieved to give up his dog and gun; he dreaded
to meet his wife; but it would not do to starve among the mountains.
He shook his head, shouldered the rusty firelock, and, with a heart
full of trouble and anxiety, turned his steps homeward.
As he approached the village, he met a number of people, but
none whom he knew, which somewhat surprised him, for he had
thought himself acquainted with every one in the country round.
Their dress, too, was of a different fashion from that to which he was
accustomed. They all stared at him with equal marks of surprise, and
whenever they cast their eyes upon him, invariably stroked their
chins. The constant recurrence of this gesture induced Rip,
involuntarily, to do the same, when, to his astonishment, he found his
beard had grown a foot long!
He had now entered the skirts of the village. A troop of strange
children ran at his heels, hooting after him, and pointing at his gray
beard. The dogs, too, none of which he recognized for his old
acquaintances, barked at him as he passed. The very village was
altered: it was larger and more populous. There were rows of houses
which he had never seen before, and those which had been his
familiar haunts had disappeared. Strange names were over the
doors—strange faces at the windows—everything was strange. His
mind now began to misgive him; he doubted whether both he and
the world around him were not bewitched. Surely this was his native
village, which he had left but the day before. There stood the
Kaatskill mountains—there ran the silver Hudson at a distance—
there was every hill and dale precisely as it had always been—Rip
was sorely perplexed—“That flagon last night,” thought he, “has
addled my poor head sadly!”
It was with some difficulty he found the way to his own house,
which he approached with silent awe, expecting every moment to
hear the shrill voice of Dame Van Winkle. He found the house gone
to decay—the roof fallen in, the windows shattered, and the doors off
the hinges. A half-starved dog, that looked like Wolf, was skulking
about it. Rip called him by name, but the cur snarled, showed his
teeth, and passed on. This was an unkind cut indeed—“My very
dog,” sighed poor Rip, “has forgotten me!”
He entered the house, which, to tell the truth, Dame Van Winkle
had always kept in neat order. It was empty, forlorn, and apparently
abandoned. This desolateness overcame all his connubial fears—he
called loudly for his wife and children—the lonely chambers rung for
a moment with his voice, and then all again was silence.
He now hurried forth, and hastened to his old resort, the little
village inn—but it too was gone. A large ricketty wooden building
stood in its place, with great gaping windows, some of them broken,
and mended with old hats and petticoats, and over the door was
painted, “The Union Hotel, by Jonathan Doolittle.” Instead of the
great tree which used to shelter the quiet little Dutch inn of yore,
there now was reared a tall naked pole, with something on the top
that looked like a red nightcap, and from it was fluttering a flag, on
which was a singular assemblage of stars and stripes—all this was
strange and incomprehensible. He recognised on the sign, however,
the ruby face of King George, under which he had smoked so many
a peaceful pipe, but even this was singularly metamorphosed. The
red coat was changed for one of blue and buff, a sword was stuck in
the hand instead of a sceptre, the head was decorated with a cocked
hat, and underneath was painted in large characters, General
Washington.
There was, as usual, a crowd of folk about the door, but none
whom Rip recollected. The very character of the people seemed
changed. There was a busy, bustling, disputatious tone about it,
instead of the accustomed phlegm and drowsy tranquillity. He looked
in vain for the sage Nicholas Vedder, with his broad face, double
chin, and fair long pipe, uttering clouds of tobacco smoke instead of
idle speeches; or Van Bummel, the schoolmaster, doling forth the
contents of an ancient newspaper. In place of these, a lean bilious
looking fellow, with his pockets full of hand-bills, was haranguing
vehemently about rights of citizens—election—members of
Congress—liberty—Bunker’s Hill—heroes of ’76—and other words,
that were a perfect Babylonish jargon to the bewildered Van Winkle.
The appearance of Rip, with his long grizzled beard, his rusty
fowling piece, his uncouth dress, and the army of women and
children that had gathered at his heels, soon attracted the attention
of the tavern politicians. They crowded around him, eying him from
head to foot, with great curiosity. The orator bustled up to him, and
drawing him partly aside, inquired “on which side he voted?” Rip
stared in vacant stupidity. Another short but busy little fellow pulled
him by the arm, and raising on tiptoe, inquired in his ear, “whether he
was Federal or Democrat.” Rip was equally at a loss to comprehend
the question; when a knowing, self-important old gentleman, in a
sharp cocked hat, made his way through the crowd, putting them to
the right and left with his elbows as he passed, and planting himself
before Van Winkle, with one arm akimbo, the other resting on his
cane, his keen eyes and sharp hat penetrating, as it were, into his
very soul, demanded, in an austere tone, “what brought him to the
election with a gun on his shoulder, and a mob at his heels, and
whether he meant to breed a riot in the village?” “Alas! gentlemen,”
cried Rip, somewhat dismayed, “I am a poor quiet man, a native of
the place, and a loyal subject of the King, God bless him!”
Here a general shout burst from the bystanders—“A tory! a tory!
a spy! a refugee! hustle him! away with him!” It was with great
difficulty that the self-important man in the cocked hat restored order;
and having assumed a tenfold austerity of brow, demanded again of
the unknown culprit, what he came there for, and whom he was
seeking. The poor man humbly assured him that he meant no harm;
but merely came there in search of some of his neighbours, who
used to keep about the tavern.
“Well—who are they?—name them.”
Rip bethought himself a moment, and inquired, “where’s
Nicholas Vedder?”
There was a silence for a little while, when an old man replied, in
a thin piping voice, “Nicholas Vedder? why he is dead and gone
these eighteen years! There was a wooden tombstone in the
churchyard that used to tell all about him, but that’s rotted and gone
too.”
“Where’s Brom Dutcher?”
“Oh, he went off to the army in the beginning of the war; some
say he was killed at the battle of Stoney Point—others say he was
drowned in a squall, at the foot of Antony’s Nose. I don’t know—he
never came back again.”
“Where’s Van Bummel, the schoolmaster?”
“He went off to the wars too, was a great militia general, and is
now in Congress.”
Rip’s heart died away, at hearing of these sad changes in his
home and friends, and finding himself thus alone in the world. Every
answer puzzled him, too, by treating of such enormous lapses of
time, and of matters which he could not understand: war—Congress
—Stoney Point!—he had no courage to ask after any more friends,
but cried out in despair, “Does nobody here know Rip Van Winkle?”
“Oh, Rip Van Winkle!” exclaimed two or three, “Oh, to be sure!
that’s Rip Van Winkle yonder, leaning against the tree.”
Rip looked, and beheld a precise counterpart of himself, as he
went up the mountain: apparently as lazy, and certainly as ragged.
The poor fellow was now completely confounded. He doubted his
own identity, and whether he was himself or another man. In the
midst of his bewilderment, the man in the cocked hat demanded who
he was, and what was his name?
“God knows,” exclaimed he, at his wit’s end; “I’m not myself—I’m
somebody else—that’s me yonder—no—that’s somebody else, got
into my shoes—I was myself last night, but I fell asleep on the
mountain, and they’ve changed my gun, and everything’s changed,
and I’m changed, and I can’t tell what’s my name, or who I am!”
The bystanders began now to look at each other, nod, wink
significantly, and tap their fingers against their foreheads. There was
a whisper, also, about securing the gun, and keeping the old fellow
from doing mischief; at the very suggestion of which, the self-
important man in the cocked hat retired with some precipitation. At
this critical moment a fresh likely woman pressed through the throng
to get a peep at the graybearded man. She had a chubby child in her
arms, which, frightened at his looks, began to cry. “Hush, Rip,” cried
she, “hush, you little fool, the old man won’t hurt you.” The name of
the child, the air of the mother, the tone of her voice, all awakened a
train of recollections in his mind. “What is your name, my good
woman?” asked he.
“Judith Gardenier.”
“And your father’s name?”
“Ah, poor man, his name was Rip Van Winkle; it’s twenty years
since he went away from home with his gun, and never has been
heard of since—his dog came home without him; but whether he
shot himself, or was carried away by the Indians, nobody can tell. I
was then but a little girl.”
Rip had but one question more to ask; but he put it with a
faltering voice:
“Where’s your mother?”
“Oh, she too had died but a short time since; she broke a blood
vessel in a fit of passion at a New-England peddler.”
There was a drop of comfort, at least, in this intelligence. The
honest man could contain himself no longer.—He caught his
daughter and her child in his arms.—“I am your father!” cried he
—“Young Rip Van Winkle once—old Rip Van Winkle now!—Does
nobody know poor Rip Van Winkle!”
All stood amazed, until an old woman, tottering out from among
the crowd, put her hand to her brow, and peering under it in his face
for a moment, exclaimed, “Sure enough! it is Rip Van Winkle—it is
himself. Welcome home again, old neighbour.—Why, where have
you been these twenty long years?”
Rip’s story was soon told, for the whole twenty years had been to
him but as one night. The neighbours stared when they heard it;
some were seen to wink at each other, and put their tongues in their
cheeks; and the self-important man in the cocked hat, who, when the
alarm was over, had returned to the field, screwed down the corners
of his mouth, and shook his head—upon which there was a general
shaking of the head throughout the assemblage.
It was determined, however, to take the opinion of old Peter
Vanderdonk, who was seen slowly advancing up the road. He was a
descendant of the historian of that name, who wrote one of the
earliest accounts of the province. Peter was the most ancient
inhabitant of the village, and well versed in all the wonderful events
and traditions of the neighbourhood. He recollected Rip at once, and
corroborated his story in the most satisfactory manner. He assured
the company that it was a fact, handed down from his ancestor the
historian, that the Kaatskill mountains had always been haunted by
strange beings. That it was affirmed that the great Hendrick Hudson,
the first discoverer of the river and country, kept a kind of vigil there
every twenty years, with his crew of the Half-moon, being permitted
in this way to revisit the scenes of his enterprize, and keep a
guardian eye upon the river, and the great city called by his name.
That his father had once seen them in their old Dutch dresses
playing at nine-pins in a hollow of the mountain; and that he himself
had heard, one summer afternoon, the sound of their balls, like long
peals of thunder.
To make a long story short, the company broke up, and returned
to the more important concerns of the election. Rip’s daughter took
him home to live with her; she had a snug, well-furnished house, and
a stout cheery farmer for a husband, whom Rip recollected for one of
the urchins that used to climb upon his back. As to Rip’s son and
heir, who was the ditto of himself, seen leaning against the tree, he
was employed to work on the farm; but evinced an hereditary
disposition to attend to anything else but his business.
Rip now resumed his old walks and habits; he soon found many
of his former cronies, though all rather the worse for the wear and
tear of time; and preferred making friends among the rising
generation, with whom he soon grew into great favour.
Having nothing to do at home, and being arrived at that happy
age when a man can do nothing with impunity, he took his place
once more on the bench, at the inn door, and was reverenced as one
of the patriarchs of the village, and a chronicle of the old times
“before the war.” It was some time before he could get into the
regular track of gossip, or could be made to comprehend the strange
events that had taken place during his torpor. How that there had
been a revolutionary war—that the country had thrown off the yoke
of old England—and that, instead of being a subject of his Majesty,
George III., he was now a free citizen of the United States. Rip, in
fact, was no politician; the changes of states and empires made but
little impression on him; but there was one species of despotism
under which he had long groaned, and that was—petticoat
government; happily, that was at an end; he had got his neck out of
the yoke of matrimony, and could go in and out whenever he
pleased, without dreading the tyranny of Dame Van Winkle.
Whenever her name was mentioned, however, he shook his head,
shrugged his shoulders, and cast up his eyes; which might pass
either for an expression of resignation to his fate, or joy at his
deliverance.
He used to tell his story to every stranger that arrived at Mr.
Doolittle’s hotel. He was observed, at first, to vary on some points
every time he told it, which was, doubtless, owing to his having so
recently awaked. It at last settled down precisely to the tale I have
related, and not a man, woman, or child in the neighbourhood but
knew it by heart. Some always pretended to doubt the reality of it,
and insisted that Rip had been out of his head, and that this was one
point on which he always remained flighty. The old Dutch
inhabitants, however, almost universally gave it full credit. Even to
this day they never hear a thunder storm of a summer afternoon,
about the Kaatskill, but they say Hendrick Hudson and his crew are
at their game of nine-pins; and it is a common wish of all henpecked
husbands in the neighbourhood, when life hangs heavy on their
hands, that they might have a quieting draught out of Rip Van
Winkle’s flagon.
NOTE
The foregoing tale, one would suspect, had been suggested to Mr. Knickerbocker
by a little German superstition about the Emperor Frederick and the Kypphauser
mountain; the subjoined note, however, which he had appended to the tale, shows
that it is an absolute fact, narrated with his usual fidelity.
“The story of Rip Van Winkle may seem incredible to many, but nevertheless I
give it my full belief, for I know the vicinity of our old Dutch settlements to have
been very subject to marvellous events and appearances. Indeed, I have heard
many stranger stories than this, in the villages along the Hudson; all of which were
too well authenticated to admit of a doubt. I have even talked with Rip Van Winkle
myself, who, when last I saw him, was a very venerable old man, and so perfectly
rational and consistent on every other point, that I think no conscientious person
could refuse to take this into the bargain; nay, I have seen a certificate on the
subject taken before a country justice and signed with a cross, in the justice’s own
handwriting. The story, therefore, is beyond the possibility of a doubt.
“D. K.”
37
POSTSCRIPT
The following are travelling notes from a memorandum book of Mr. Knickerbocker:
The Kaatsberg, or Catskill Mountains, have always been a region full of fable.
The Indians considered them the abode of spirits, who influenced the weather,
spreading sunshine or clouds over the landscape, and sending good or bad
hunting seasons. They were ruled by an old squaw spirit, said to be their mother.
She dwelt on the highest peak of the Catskills, and had charge of the doors of day
and night to open and shut them at the proper hour. She hung up the new moon in
the skies, and cut up the old ones into stars. In times of drought, if properly
propitiated, she would spin light summer clouds out of cobwebs and morning dew,
and send them off from the crest of the mountain, flake after flake, like flakes of
carded cotton, to float in the air; until, dissolved by the heat of the sun, they would
fall in gentle showers, causing the grass to spring, the fruits to ripen, and the corn
to grow an inch an hour. If displeased, however, she would brew up clouds black
as ink, sitting in the midst of them like a bottle-bellied spider in the midst of its web;
and when these clouds broke, woe betide the valleys!
In old times, say the Indian traditions, there was a kind of Manitou or Spirit,
who kept about the wildest recesses of the Catskill Mountains, and took a
mischievous pleasure in wreaking all kinds of evils and vexations upon the red
men. Sometimes he would assume the form of a bear, a panther, or a deer, lead
the bewildered hunter a weary chase through tangled forests and among ragged
rocks; and then spring off with a loud ho! ho! leaving him aghast on the brink of a
beetling precipice or raging torrent.
The favorite abode of this Manitou is still shown. It is a great rock or cliff on the
loneliest part of the mountains, and, from the flowering vines which clamber about
it, and the wild flowers which abound in its neighborhood, is known by the name of
the Garden Rock. Near the foot of it is a small lake, the haunt of the solitary bittern,
with water-snakes basking in the sun on the leaves of the pond-lilies which lie on
the surface. This place was held in great awe by the Indians, insomuch that the
boldest hunter would not pursue his game within its precincts. Once upon a time,
however, a hunter who had lost his way, penetrated to the Garden Rock, where he
beheld a number of gourds placed in the crotches of trees. One of these he seized
and made off with it, but in the hurry of his retreat he let it fall among the rocks,
when a great stream gushed forth, which washed him away and swept him down
precipices, where he was dashed to pieces, and the stream made its way to the
Hudson, and continues to flow to the present day; being the identical stream
known by the name of the Kaaterskill.
WILLIAM AUSTIN
1778–1841

William Austin was a Boston lawyer of literary tastes. He saw something of the
world in his cruises (1799–1800) on the “Constitution” as chaplain, and of society
during his eighteen months at Lincoln’s Inn. An account of his life and works is
prefixed to the collective edition, now out of print, edited by his son, John Walker
Austin (The Literary Papers of William Austin, Boston, 1890). This also reprints a
large part of Col. T. W. Higginson’s “A Precursor of Hawthorne” (Independent, 29th
March, 1888. A reference will also be found at pages 64 and 68 of Col.
Higginson’s Longfellow). Of his few tales only Peter Rugg has had any currency.
Indeed, the significance of Austin’s narrative art is mainly negative. Even Peter
Rugg shows wherein what might have been a short story failed of its form. For all
its undoubted quality, it is a short story manqué; and in this it is quite typical of its
time. If artistic sense is apparent in the cumulation of foreshadowings, crudity of
mechanism is equally apparent in the management of each through a different
interlocutor. It is artistically right that Rugg should at last be brought home; it is
artistically wrong that the conclusion should be so like a moralising summary. A
conception much like Hawthorne’s is developed as it were by mere accumulation
instead of being focused in a unified progression. (See also pages 10 and 12 of
the Introduction.)
PETER RUGG, THE MISSING MAN
[First part printed in Buckingham’s “New England Galaxy,”
10th September, 1824; several times reprinted entire, e. g., in
the “Boston Book” for 1841; reprinted here from the standard
collection noted above]

From Jonathan Dunwell of New York to Mr. Herman Krauff


SIR,—Agreeably to my promise, I now relate to you all the
particulars of the lost man and child which I have been able to
collect. It is entirely owing to the humane interest you seemed to
take in the report, that I have pursued the inquiry to the following
result.
You may remember that business called me to Boston in the
summer of 1820. I sailed in the packet to Providence, and when I
arrived there I learned that every seat in the stage was engaged. I
was thus obliged either to wait a few hours or accept a seat with the
driver, who civilly offered me that accommodation. Accordingly, I took
my seat by his side, and soon found him intelligent and
communicative. When we had travelled about ten miles, the horses
suddenly threw their ears on their necks, as flat as a hare’s. Said the
driver, “Have you a surtout with you?”
“No,” said I; “why do you ask?”
“You will want one soon,” said he. “Do you observe the ears of all
the horses?”
“Yes; and was just about to ask the reason.”
“They see the storm-breeder, and we shall see him soon.”
At this moment there was not a cloud visible in the firmament.
Soon after, a small speck appeared in the road.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like