Book Image

RSpec Essentials

By : Mani Tadayon
Book Image

RSpec Essentials

By: Mani Tadayon

Overview of this book

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 (17 chapters)
RSpec Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Index

A

  • AngularJS
    • home page link / Step 1 – building the view
  • application code
    • improving / Improving application code
  • automated tests / The promise of testing

B

  • BDD
    • pros / The pros and cons of BDD
    • cons / The pros and cons of BDD
  • behavior-driven development (BDD) / Behavior-driven development
    • exploring / Exploring BDD
    • running / The BDD process begins
  • black-box JavaScript tests
    • using, with real browser / Black-box JavaScript tests with a real browser
  • built-in matchers
    • about / Built-in matchers
    • reference link / Built-in matchers
  • Bundler
    • reference link / Configuring RSpec to run a feature file
    • about / A better configuration manager

C

  • Capybara
    • starting with / Getting started with Capybara and Selenium
    • integrating, with RSpec / Integrating Capybara with RSpec
    • need for / Why Capybara?
  • configuration
    • about / Configuration and testability
    • examples / Configuration and testability
    • importance / What is so important about configuration?
  • configuration manager
    • about / A better configuration manager
  • context
    • using / Using let and context
  • continuous integration (CI) / A case study of test simplicity with an external service
  • Cucumber example / Behavior-driven development
  • custom helpers
    • used, for mocking HTTP responses / Mock HTTP responses with custom helpers
  • custom matchers / Custom matchers

D

  • Data, Context and Interaction (DCI)
    • reference link / Improving application code
  • double / Mocks, stubs, and doubles
  • dummy containers
    • used, for testing mixins / Testing mixins with dummy containers
  • duplication
    • reducing, with shared example groups / Reducing duplication with shared example groups

E

  • end-to-end (e2e) tests / Using real-world requests for mock responses
  • errors
    • testing for / Testing for errors
    • reference link / Testing for errors
  • executable documentation / Behavior-driven development
  • external web services
    • importance / The importance of external web services

F

  • fake / Mocks, stubs, and doubles
  • false negatives
    • detecting / Detecting false negatives and false positives
  • false positives
    • detecting / Detecting false negatives and false positives
  • feature file
    • running, with RSpec configuration / Configuring RSpec to run a feature file
  • features, Capybara
    • Capybara.visit / Getting started with Capybara and Selenium
    • Capybara.fill_in / Getting started with Capybara and Selenium
    • Capybara.find_button / Getting started with Capybara and Selenium
    • Element.click / Getting started with Capybara and Selenium
    • Capybara.has_content? / Getting started with Capybara and Selenium
    • Capybara.has_selector / Getting started with Capybara and Selenium
    • Capybara.find / Getting started with Capybara and Selenium
  • file-based configuration management
    • about / File-based configuration management
  • first spec
    • running / Running our first spec

G

  • good custom error message
    • creating / Creating a good custom error message

H

  • hooks
    • using / Using hooks
    • execution, controlling / Controlling when hooks are executed
    • advanced state control / Advanced state control with hooks and mocks
  • HTTP endpoints / Step 2 – defining the API
  • HTTP responses
    • mocking, with custom helpers / Mock HTTP responses with custom helpers

J

  • Jenkins / Step 3 – finishing the view
  • JSON Web Token (JWT)
    • reference link / JSON Web Token
    • using, for authentication / JSON Web Token

L

  • let helper
    • using / Using let and context

M

  • matchers
    • about / Matchers
    • built-in matchers / Built-in matchers
    • custom matchers / Custom matchers
    • enhanced context, in output / Enhanced context in matcher output
    • good custom error message, creating / Creating a good custom error message
    • application code, improving / Improving application code
  • memoization / Using hooks
  • mixins
    • testing, dummy containers / Testing mixins with dummy containers
  • MMF
    • developing / MMFs by example
    • example / MMFs by example
    • specifying / Specifying the MMF
  • mock
    • need for / Why mock?
    • about / Mocks, stubs, and doubles
    • advanced state control / Advanced state control with hooks and mocks
  • mock HTTP requests
    • WebMock, using / Using WebMock for mock HTTP requests
  • mocking time / Mocking time
  • mock requests
    • VCR, using / Using VCR for mock requests
  • mock responses
    • real-world requests, using / Using real-world requests for mock responses

N

  • Nginx / Building web apps with Rack

O

  • outside-in coding
    • view, building / Step 1 – building the view
    • API, defining / Step 2 – defining the API
    • view, finishing / Step 3 – finishing the view

P

  • Portable Operating System Interface (POSIX) / Running our first spec
  • production faithfulness case study
    • test resource instance, using / A case study of production faithfulness with a test resource instance

R

  • Rack
    • used, for running web apps / Building web apps with Rack
    • reference link / Building web apps with Rack
  • Rack authentication middleware / Simple Rack authentication middleware
  • Rack middleware
    • used, for serving static files / Serving static files using Rack middleware
  • real-world requests
    • used, for mock responses / Using real-world requests for mock responses
  • Redis
    • reference link / A case study of production faithfulness with a test resource instance
  • Redis Ruby client
    • installation link / A case study of production faithfulness with a test resource instance
  • resources
    • initialization / Initialization and configuration of resources
    • configuration / Initialization and configuration of resources
  • RFC 2396
    • reference link / Using real-world requests for mock responses
  • RFC 3986
    • reference link / Using real-world requests for mock responses
  • RSpec
    • documentation link / The promise of testing
    • used, for writing specs / Writing specs with RSpec
    • reference link / Test-driven development
    • about / Test-driven development
    • configuring, with spec_helper.rb / Configuring RSpec with spec_helper.rb
    • Capybara, integrating with / Integrating Capybara with RSpec
    • configuration, for running feature file / Configuring RSpec to run a feature file
  • Ruby code / Technical assumptions
  • Rubygems
    • about / A better configuration manager

S

  • Selenium/WebDriver
    • starting with / Getting started with Capybara and Selenium
  • shared example groups
    • used, for reducing duplication / Reducing duplication with shared example groups
  • Sinatra
    • reference link / Step 2 – defining the API
  • Smithsonian Institution
    • website link / Getting started with Capybara and Selenium
  • spec file
    • structure / Structure of a spec file
  • specification by Example (SBE) / Behavior-driven development
  • specs
    • writing, with RSpec / Writing specs with RSpec
  • spec_helper.rb
    • used, for configuring RSpec / Configuring RSpec with spec_helper.rb
  • static files
    • serving, Rack middleware used / Serving static files using Rack middleware
  • stub / Mocks, stubs, and doubles

T

  • technical assumptions / Technical assumptions
  • test
    • writing, issue / The promise of testing
    • about / Understanding the unit test
  • test-driven development (TDD) / Test-driven development
  • testability / Testability
    • examples / Configuration and testability
  • testing
    • about / The promise of testing
  • tests
    • about / What does all this have to do with testing?
  • test simplicity case study
    • external service, using / A case study of test simplicity with an external service
  • Timecop gem
    • reference link / Mocking time
  • Todo**TodoList model
    • methods / Step 2 – defining the API
  • todo list manager app / MMFs by example
  • TodoMVC
    • using / Using TodoMVC
    • reference link / Using TodoMVC
  • Travis CI / Step 3 – finishing the view

U

  • unit
    • about / Understanding the unit test
  • unit test
    • about / Understanding the unit test

V

  • VCR
    • used, for mock requests / Using VCR for mock requests

W

  • weather query (WQ) / A case study of production faithfulness with a test resource instance
  • web apps
    • building, Rack used / Building web apps with Rack
  • WebMock
    • reference link / A case study of test simplicity with an external service
    • used, for mock HTTP requests / Using WebMock for mock HTTP requests