Test-Driven Rails Development using RSpec and Capybara

Table of Contents

Upcase Test-Driven Rails

Code for this course is here. Keep in mind that this tutorial is based on an old version of Rails and as such I had to make modifications as I went along.

Video 1: Why Test


Business goals

Code goals

Process goals

Red/green refactor

Video 2: setting up the app and initial test

Rails Generate Commands

Issues Resolved

Ran into an error where a gem native extension wouldn’t build on my distro (Ubuntu 18.04). I had already installed Ruby using Snap, and then followed the instructions on the Nokogiri site to finish installing it. I installed the following dependencies.

sudo apt-get install build-essential patch zlib1g-dev liblzma-dev
gem install nokogiri

However, I subsequently removed Ruby installed via snap and started using RVM and as such the above steps might not have been needed. Installing using RVM also fixed issues with Command rails not found and cannot load such file -- rubygems.rb

This issue was fixed by added the lines --require spec_helper and --require rails_helper to .rspec

I missed the need to use visit base_path to navigate to the homepage in the rspec test and thus it was failing

Video 3: creating the first todo

Video 4: signing in and todo ownership

Attempting to add rspec support helpers resulted in this error. It turned out that all that needed to happen was to uncomment the following line from spec/rails_helper.rb:

Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }

Was trying to each over a model collection but it bombed out since before_filter was changed to before_action in Rails 5.

I missed adding :create to the routes.rb resource for session.

When trying to run Rspec tests using Rubymine, I was running into the ExecJS error. To fix it, I uncommented the line, gem 'mini_racer', platforms: :ruby, in the Rails gem file