Preface

RSpec is one of the reasons why the Ruby programming language has become so popular. There is a strong emphasis on testing, documentation, and iterative development in the Ruby community. With RSpec, it is easy to create excellent tests that specify behavior and improve the development process.

In this book, we'll learn how to use RSpec in a real-world setting. We'll also learn about the concept of testability, which relates to our application code as well as to our tests. Throughout, we'll focus on writing tests that are valuable and stay away from testing for its own sake.

RSpec offers a variety of tools for creating test scenarios, assertions, and error messages. We can create the tests we need and get the exact output we want using RSpec without having to do too much work. RSpec has been under development for almost 10 years, so it has evolved significantly. Many ways of writing tests have developed due to the flexibility of RSpec and the underlying Ruby language. Some of these are clever but some others are too clever. We'll learn about a solid subset of RSpec's features that are reliable and avoid some of the trickier features.

Today, professional software development must include automated testing. However, testing presents many challenges in the real world. There is a danger of learning about testing tools without knowing how to use them effectively. In this book, we will always keep an eye on the real world, even in our simple examples. We'll cover a range of application types, from libraries to rich web UIs, and a range of approaches to testing, from unit tests to behavior-driven development. Along the way, we'll discuss potential pitfalls and develop production-grade solutions to avoid them.

As you progress through this book, you will learn about many RSpec features, my recommended approach to using them, and their relation to testability. I hope that you can use this book both as a handbook for simple tasks and as a guide to developing a sophisticated understanding of automated software testing.

What this book covers

Chapter 1, Exploring Testability from Unit Tests to Behavior-Driven Development, defines the basic concepts of unit, test, and testability, and puts them in context.

Chapter 2, Specifying Behavior with Examples and Matchers, shows how RSpec's basic features implement units and assertions.

Chapter 3, Taking Control of State with Doubles and Hooks, discusses how RSpec implements mocks and hooks to allow us to set up a test scenario.

Chapter 4, Setting Up and Cleaning Up, delves further into how we can simulate external resources such as databases and web servers while keeping our test environment clean using RSpec support code.

Chapter 5, Simulating External Services, extends our discussion of handling external web services by using the VCR gem.

Chapter 6, Driving a Web Browser with Capybara, introduces the Capybara library, and shows how to use it to test rich web UIs.

Chapter 7, Building an App from the Outside In with Behavior-Driven Development, explains BDD and how RSpec can be used to define high-level features.

Chapter 8, Tackling the Challenges of End-to-end Testing, continues with the development of the app built in the previous chapter, focusing on common testing pain points, such as authentication.

Chapter 9, Configurability, introduces a concept that is related to testability and an implementation of a real-world configuration system.

Chapter 10, Odds and Ends, wraps up the book by covering a few advanced topics that didn't quite fit into the previous chapters, but which were too important to leave out.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset