SSH to the vagrant OS command line.
Terminal $> vagrant ssh
Login to postgres database as vagrant user with the psql client:
vagrant@rails-dev-box: psql -U vagrant postgres
require 'rails_helper' | |
RSpec.describe TodosController, :type => :controller do | |
describe "GET #index" do | |
#describe "POST #create" do | |
#describe "GET #show" do | |
#describe "PATCH #update" do (or PUT #update) | |
#describe "DELETE #destroy" do | |
#describe "GET #new" do |
SSH to the vagrant OS command line.
Terminal $> vagrant ssh
Login to postgres database as vagrant user with the psql client:
vagrant@rails-dev-box: psql -U vagrant postgres
rspec-stackprof
is "empty"stackprof
is written as a replacement for perftools.rb
stackprof.rb
to your spec/support
folder, which is loaded on rails_helper.rb
text
(String, Regexp)
— Only find elements which contain this text or match this regexpvisible
(Boolean, Symbol)
— Only find elements with the specified visibility:
true
- only finds visible elements.false
- finds invisible and visible elements.:all
- same as false
; finds visible and invisible elements.:hidden
- only finds invisible elements.:visible
- same as true
; only finds visible elements.count
(Integer)
— Exact number of matches that are expected to be found// Wrap in anonymous function to avoid adding variables to global scope needlessly. | |
(function($) { // $ is jQuery | |
function addTodoToDOM(data) { // 'data' is object built from response JSON | |
// id will be needed when adding delete functionality dynamically. | |
// var todoId = data.todo.id; | |
// Add HTML for new todo to document | |
var tableRow = '<tr><td>' + data.todo.description + '</td></tr>'; |
Rails changed the default behavior for WEBrick somewhere around version 4. Instead of binding to 0.0.0.0
, it will now default to localhost
.
This makes life difficult when you're running Rails inside a VM like Vagrant, mostly because it won't work. ;)
Fortunately, you can force Rails back into the old universal address with the following snippet
# config/boot.rb
# ... end of existing file
require 'openssl' | |
class MessageEncryptor | |
class << self | |
include OpenSSL | |
def delivering_email(message) | |
encrypted_message = sign_and_encrypt(message.encoded, message.to) | |
overwrite_body(message, encrypted_message) | |
overwrite_headers(message, encrypted_message) |
## From Lynda.com course 'RSpec Testing Framework with Ruby' | |
describe 'Expectation Matchers' do | |
describe 'equivalence matchers' do | |
it 'will match loose equality with #eq' do | |
a = "2 cats" | |
b = "2 cats" | |
expect(a).to eq(b) |
It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time
class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime
steps in:
>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000