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
  • Update your Gemfile
  • Setup RSpec
  • Feature specs

Configuring RSpec

The following assumes that you've generated a middleman project using the its CLI middleman init your_project_name

Update your Gemfile

Add the following gems to your Gemfile and run bundle install

group :development, :test do
  gem 'capybara'
  gem 'pry'
  gem 'pry-byebug'
  gem 'rspec'
end

Setup RSpec

From your terminal, navigate to your project directory and initialize RSpec config files for your project with the following command

rspec --init

Update the .rspec file to have the following code

--format documentation
--color
--require spec_helper

Then remove all content in spec/spec_helper.rb and replace with the following

require 'rspec'
require 'capybara/rspec'

require 'middleman-core'
require 'middleman-core/rack'
require 'middleman-autoprefixer'
require 'middleman-livereload'

middleman_app = ::Middleman::Application.new

Capybara.app = ::Middleman::Rack.new(middleman_app).to_app do
  set :root, File.expand_path(File.join(File.dirname(FILE), '..'))
  set :environment, :development
  set :show_exceptions, false
end

With this in place we should now be ready to write our first spec

Feature specs

Most of the specs you'll be writing for a middleman app will be feature specs that test for certain things to be visible on the page. Below is a sample feature spec that checks if projects are listed on the index page

describe 'Index Page', type: :feature do
  it 'displays project list' do
    expect(page).to have_css '.projects'

    within '.projects' do
      expect(page).to have_content 'My First Website'
      expect(page).to have_content 'FizzBuzz'
    end
  end
end
PreviousWeek 10 - Expose and Consume API's

Last updated 7 years ago