#Mentoring
Some people say you should read the HTTP RFC if you're serious about web development. I might, some day.
Just browsing through the table of contents however will show you a lot of things that you've already encountered. Among them the HTTP verbs currently supported by rails: GET
, POST
, PUT
, DELETE
(PATCH
is fairly new in rails).
RSpec is my go-to testing framework, there's nothing wrong with Test::Unit or Minispec, just personal preference.
There is a fair share of meta programming magic going on in those tests, which make them easy to read, but hard to understand what is going on.
After all the tests are just ruby code, so with the right parentheses something like customer.should have_key :name
is actually customer.should(have_key(:name))
.
Another magic thing they do is add methods with names that fit the english language grammar.
In the above example customer
responds to the method has_key?(key)
, RSpec adds the corresponding have_key
expectation.
Similar pairs are empty?
and be_empty
.
This also works for methods that you defined that fit that pattern, try it out!
RSpec recently switched from the should
to the expect
syntax, which requires less meta programming and is less likely to fail in unexpected ways.
I recommend reading betterspecs.org for a good guideline on how to write RSpec tests.
I didn't want to switch from my usual setup, so I have some explaining to do.
tmux
A 'terminal multiplexer', not really necessary but it's fairly deep ingrained in my workflow. You'll see in the videos that I can split my terminal, tmux enables that.take folder
=mkdir folder && cd folder
(Create the folder and cd into it)rvm list
shows me all ruby versions currently installed on my system. You don't have to uservm
but I would suggest it. When yougem install
something without using a rvm gemset then it will install that gem on your system, so if you have two apps that use the different versions of the same gem, say rails 3.2 and rails 4.1 you're going to have a problem. Rvm alleviates that pain by separating gems on a project basis. An alternative to rvm is rbenv, which supposedly is less bloated.bundle init
creates the Gemfile. Nice if you can't remember what goes into a Gemfile despite working with one for years.git-email-personal
an alias that I defined forgit config user.email "sebastian.geiger@gmail.com"
. I don't have a global user.email defined because I want my company commits to use a different email then my personal ones.echo "something" >> some_file
a fast way to append "something" to some_file.cat some_file
displays the contents of the filetail some_file
shows the last few lines of a file, if you dotail -F some_file
the command does not return but keeps on monitoring the file. Pressctrl + c
to get out.man some_command
gives you the manual for some_command, handy if you forget what the command is doing or how to invoke it correctlycurl some_url
sends a GET request to some_url and displays the response. It has a ton of switches such as-d
which sends a POST request instead of a GET request.curl
is able to do most of the things that you can do with your browser.- Dash not a command but a Mac application. Let's you quickly lookup documentation, not only for ruby but a lot of other languages. I believe they have an unlimited trial which is only asking you to purchase from time to time.