Makers Academy — Week 3

Learning MVC, Sinatra and Capybara

Capybara Sinatra

We spent two weeks learning and refining our unit tests in RSpec and we are onto Week 3, introduction to the web!

It’s a busy week as we are introduced to many things in five days. We were introduced to Sinatra, a framework which is dependent on the Rack web server interface. Next was web feature testing with Capybara along with introduction to HTML and CSS. Frankly, it was an intensive week to make sense all of it however our cohort worked very hard and most of us managed to finish the challenge during the week.

MVC 🌐

We were introduced to MVC (Model View Controller), a useful and popular design pattern for deploying web application. In Week 3, the framework we are going to use is Sinatra and I recommend this article, by Tom Dalling to understand what goes under the hood.

In a nutshell:

  • The model is the central component of the pattern. It directly manages the data, logic and rules of the application.
  • A view can be any output representation of information, it’s often the HTML page that displays the dynamic content based on the model.
  • The third part, the controller, accepts input and converts it to commands for the model or view.
Model View Controller

Sinatra 🎙️

Sinatra is a free and open sourced framework which focuses on quickly creating web-applications in Ruby with minimal effort. It’s a great way for us to understand how web applications work in a nutshell without diving too deep and it was great to start learning about the web.

The syntax for Sinatra was easy to get on board and quick to setup. Within a short moment our web app was running and another thing I love about it is the stack trace messages are easy to interpret so debugging the production code turns into an relatively enjoyable task 😁.

Reading up on the ‘GET’ and ‘POST’ request in the controller was very useful to wrap my head around routing in the controller, it took some experimentation and some further reading outside of the week’s challenge. Here is a video which I found useful:

Capybara 🐹

I enjoyed using Capybara as a web feature testing tool, the syntax is easy to use and by sticking true to TDD, I can write feature tests without hassle and ensure that my web application is bug free to a certain degree. Below is an snippet of Capybara wrote by myself and my pair partner.

feature ‘Creating links’ do
scenario “Add the site’s address and title to bookmark manager” do
visit(‘/links/new’)
fill_in(‘title’, with: “Makers Academy”)
fill_in(‘url’, with: “http://www.makersacademy.com")
click_button(‘submit’)
expect(current_path).to eq ‘/links’
within ‘ul#links’ do
expect(page).to have_content(“Makers Academy”)
expect(page).to have_content(“http://www.makersacademy.com")
end
end
end

I did come into some installation issues around the drivers for Capybara, and the driver which worked for me is Poltergeist which was a delight to install and deploy on MAC OSX.

Next week we will tackle databases which will extends our knowledge on the model component. I cannot wait!