RSpec Essentials

Develop testable, modular, and maintainable Ruby software for the real world using RSpec
Preview in Mapt

RSpec Essentials

Mani Tadayon

Develop testable, modular, and maintainable Ruby software for the real world using RSpec
Mapt Subscription
FREE
$29.99/m after trial
eBook
$22.40
RRP $31.99
Save 29%
Print + eBook
$39.99
RRP $39.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$22.40
$39.99
$29.99p/m after trial
RRP $31.99
RRP $39.99
Subscription
eBook
Print + eBook
Start 30 Day Trial

Frequently bought together


RSpec Essentials Book Cover
RSpec Essentials
$ 31.99
$ 22.40
Instant RSpec Test-Driven Development How-to Book Cover
Instant RSpec Test-Driven Development How-to
$ 14.99
$ 10.50
Buy 2 for $28.00
Save $18.98
Add to Cart
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 

Book Details

ISBN 139781784395902
Paperback222 pages

Book Description

This book will teach you how to use RSpec to write high-value tests for real-world code. We start with the key concepts of the unit and testability, followed by hands-on exploration of key features. From the beginning, we learn how to integrate tests into the overall development process to help create high-quality code, avoiding the dangers of testing for its own sake.

We build up sample applications and their corresponding tests step by step, from simple beginnings to more sophisticated versions that include databases and external web services. We devote three chapters to web applications with rich JavaScript user interfaces, building one from the ground up using behavior-driven development (BDD) and test-driven development (TDD).

The code examples are detailed enough to be realistic while simple enough to be easily understood. Testing concepts, development methodologies, and engineering tradeoffs are discussed in detail as they arise. This approach is designed to foster the reader’s ability to make well-informed decisions on their own.

Table of Contents

Chapter 1: Exploring Testability from Unit Tests to Behavior-Driven Development
The promise of testing
Testability
Technical assumptions
Running our first spec
Understanding the unit test
Writing specs with RSpec
Test-driven development
Behavior-driven development
Summary
Chapter 2: Specifying Behavior with Examples and Matchers
Structure of a spec file
Using let and context
Matchers
Testing for errors
Summary
Chapter 3: Taking Control of State with Doubles and Hooks
Why mock?
Mocks, stubs, and doubles
Using hooks
Controlling when hooks are executed
Advanced state control with hooks and mocks
Summary
Chapter 4: Setting Up and Cleaning Up
Configuring RSpec with spec_helper.rb
Initialization and configuration of resources
Summary
Chapter 5: Simulating External Services
The importance of external web services
Mock HTTP responses with custom helpers
Using VCR for mock requests
Summary
Chapter 6: Driving a Web Browser with Capybara
Getting started with Capybara and Selenium
Integrating Capybara with RSpec
Why Capybara?
Black-box JavaScript tests with a real browser
Summary
Chapter 7: Building an App from the Outside In with Behavior-Driven Development
Exploring BDD
MMFs by example
Using TodoMVC
Specifying the MMF
Configuring RSpec to run a feature file
The BDD process begins
Building web apps with Rack
Serving static files using Rack middleware
Summary
Chapter 8: Tackling the Challenges of End-to-end Testing
Step 1 – building the view
Step 2 – defining the API
Step 3 – finishing the view
The pros and cons of BDD
Simple Rack authentication middleware
JSON Web Token
Summary
Chapter 9: Configurability
Configuration and testability
File-based configuration management
A better configuration manager
Summary
Chapter 10: Odds and Ends
Reducing duplication with shared example groups
Mocking time
Detecting false negatives and false positives
Testing mixins with dummy containers
Summary

What You Will Learn

  • Identify a unit of software for the purposes of testing
  • Manage test states with hooks, fixtures, and mocks
  • Handle external web services in tests using various techniques
  • Configure RSpec flexibly and cleanly using support code and environment variables
  • Interact with rich web apps in tests using Capybara
  • Build the right feature with behavior-driven development
  • Customize matchers and failure messages
  • Verify correct development and production environments

Authors

Table of Contents

Chapter 1: Exploring Testability from Unit Tests to Behavior-Driven Development
The promise of testing
Testability
Technical assumptions
Running our first spec
Understanding the unit test
Writing specs with RSpec
Test-driven development
Behavior-driven development
Summary
Chapter 2: Specifying Behavior with Examples and Matchers
Structure of a spec file
Using let and context
Matchers
Testing for errors
Summary
Chapter 3: Taking Control of State with Doubles and Hooks
Why mock?
Mocks, stubs, and doubles
Using hooks
Controlling when hooks are executed
Advanced state control with hooks and mocks
Summary
Chapter 4: Setting Up and Cleaning Up
Configuring RSpec with spec_helper.rb
Initialization and configuration of resources
Summary
Chapter 5: Simulating External Services
The importance of external web services
Mock HTTP responses with custom helpers
Using VCR for mock requests
Summary
Chapter 6: Driving a Web Browser with Capybara
Getting started with Capybara and Selenium
Integrating Capybara with RSpec
Why Capybara?
Black-box JavaScript tests with a real browser
Summary
Chapter 7: Building an App from the Outside In with Behavior-Driven Development
Exploring BDD
MMFs by example
Using TodoMVC
Specifying the MMF
Configuring RSpec to run a feature file
The BDD process begins
Building web apps with Rack
Serving static files using Rack middleware
Summary
Chapter 8: Tackling the Challenges of End-to-end Testing
Step 1 – building the view
Step 2 – defining the API
Step 3 – finishing the view
The pros and cons of BDD
Simple Rack authentication middleware
JSON Web Token
Summary
Chapter 9: Configurability
Configuration and testability
File-based configuration management
A better configuration manager
Summary
Chapter 10: Odds and Ends
Reducing duplication with shared example groups
Mocking time
Detecting false negatives and false positives
Testing mixins with dummy containers
Summary

Book Details

ISBN 139781784395902
Paperback222 pages
Read More

Read More Reviews

Recommended for You

Learning Docker Book Cover
Learning Docker
$ 39.99
$ 8.00
Orchestrating Docker Book Cover
Orchestrating Docker
$ 14.99
$ 10.50
Docker Cookbook Book Cover
Docker Cookbook
$ 35.99
$ 25.20
Learning Sinatra Book Cover
Learning Sinatra
$ 23.99
$ 16.80
AngularJS Web Application Development Cookbook Book Cover
AngularJS Web Application Development Cookbook
$ 29.99
$ 6.00
Vagrant Virtual Development Environment Cookbook Book Cover
Vagrant Virtual Development Environment Cookbook
$ 26.99
$ 18.90