Coding as a Craft Bootcamp Prep - v2.0
  • Introduction
  • Week 1 - Programming Basics - Ruby
    • Understanding the problem statement
    • User stories
    • Pair programming
    • The ATM challenge
      • Step 1 - Setting the stage
      • Step 2 - The core functionality
      • Step 3 - Interacting with objects
      • Step 4 - Refactoring
      • Step 5 - Testing the sad path
      • Step 6 - Cash is King
      • Step 7 - The Account
      • Step 8 - The Person
      • Step 9 - Making it all work together
    • Library Challenge
      • Important Topics
    • Extras
    • RSpec
      • RSpec introduction
      • Install and configure
      • RSpec Basics
      • How to write specs
      • So many Expectations...
      • Matchers
  • Week 2 -Programming Basics - JavaScript
  • Week 3 - TypeScript and Angular
  • Week 4 - Ruby on Rails Basics
  • Week 5 - Working With Legacy Code
  • Week 6 - Midcourse Project
  • Week 7 - Going Mobile
  • Week 8 & 9 - Advanced SaaS Applications
  • Week 10 - Expose and Consume API's
  • Configuring RSpec
Powered by GitBook
On this page
  • What is Rspec?
  • So what is a spec anyway?
  • Why should we test?
  1. Week 1 - Programming Basics - Ruby
  2. RSpec

RSpec introduction

What is Rspec?

A testing framework used for automated tests. It stands for Ruby Specifications. We will use Rspec for unit test in this bootcamp, even though there is a possibility to use Rspec for acceptance tests as well. RSpec is written in Ruby but it also uses a DSL (domain-specific language) This means that even though we are using Ruby when writing specs there are also built in methods in RSpec that does things their own way.

So what is a spec anyway?

The definition is as following:

A Spec (also called test/example) is a executable example that tests whether a portion of code exhibits the expected behavior in a controlled context. In simpler terms this means:

Given some context,

When some event occurs,

Then I should expect some outcome.

Given-When-Then

Do take note that this structure isverysimilar to the structure of user stories.

Coincidence? I think not!

Why should we test?

There are multiple reasons for this but the most important reasons are:

  • Find bugs in the code

  • Increases your critical thinking (forces you to think about the code you are writing)

  • Cover edge cases (like unexpected use of other languages, numbers etc)

  • Increases your confidence (deploying code, adding features, adding gems)

There are also some occasions when testing is not recommended or unnecessary.

You should not test basic ruby. This means that you are testing built in ruby methods. There are some other instances where testing is unnecessary, and I encourage you to think about what situations there are where testing is unnecessary.

PreviousRSpecNextInstall and configure

Last updated 7 years ago