Skip to content

Instantly share code, notes, and snippets.

View gsmendoza's full-sized avatar

George Mendoza gsmendoza

View GitHub Profile
@gsmendoza
gsmendoza / starbuzz_coffee.rb
Created June 16, 2016 23:18
Head First Design Patterns - Decorator - Starbuzz
require 'attr_extras'
module StarbuzzCoffee
class Beverage
attr_reader :description
def initialize
@description = "Unknown Beverage"
end
@gsmendoza
gsmendoza / weather_monitoring_app.rb
Created June 10, 2016 01:59
Ruby implementation of weather monitoring app from Head First Design Patterns, Chapter 2: The Observer Pattern
require "observer"
require 'attr_extras'
module WeatherMonitoringApp
module HeatIndex
# rubocop:disable Metrics/AbcSize
def self.calculate(t, rh)
(
16.923 +
(0.185212 * t) +
@gsmendoza
gsmendoza / Guardfile
Last active August 29, 2015 14:08
Run specs modified since master commit.
guard 'rspec' do
watch(%r{^(app|config|lib|spec/support)/}) do
`git diff --name-only master`.split("\n").select do |path|
path =~ %r{spec/.*_spec.rb}
end
end
end
@gsmendoza
gsmendoza / pre-commit
Created October 5, 2013 07:13
Git pre-commit hook for image optimization.
#!/usr/bin/env ruby
require 'image_optim'
staged_files = `git diff --cached --name-only --diff-filter=ACM`.split("\n")
staged_files.select! { |f| f =~ %r{/images/} }
if staged_files.any?
image_optim = ImageOptim.new(pngout: false)

PageObject + SimpleDelegator = Awesome Capybara Helpers

I've always liked using the Page Object pattern to write concise, namespaced, and composeable capybara helpers:

When /^I register as a new user$/ do
  NewUserPage.new(self).tap do |page|
    page.visit!
    page.form.fill

page.form.submit!

@gsmendoza
gsmendoza / 2012-08-24-isolated-cucumber-tests-with-local-steps.markdown
Created August 8, 2012 06:16
A workaround for isolated tests with local steps in Cucumber

A workaround for isolated tests with local steps in Cucumber

I've always wanted to write tests using Spinach. Unlike Cucumber, steps in Spinach are local to the feature they are defined. Therefore, they do not conflict with step definitions in other features.

However, we're using Cucumber in our project. The Cucumber way doesn't allow steps local to a scenario. In fact, it even considers it an anti-pattern.

Last week though, I had an idea: why not stamp each step with a scenario ID so that the step is local to the scenario? Using the spinach example, I ended with something like this:

features/1_greetings.feature

@gsmendoza
gsmendoza / gist:1292230
Created October 17, 2011 08:57
RestClient request when putting a page to unfuddle's notebooks
#<RestClient::Request:0xb72c53a0
@args=
{:password=>"********",
:method=>:put,
:payload=>
{:page=>
{:message=>"Minor fixes",
:title=>"title",
:body=>
"body"}},
Feature: Google Apps authentication
As a user I want to be able to register baweb account using my google account.
@selenium
Scenario: An customer creates account using GoogleID # features/307_google_apps_authentication.feature:5
Given I am anonymous # features/step_definitions/user_steps.rb:1
When I go to the signup page # features/step_definitions/web_steps.rb:23
And I follow "Sign up with your Google Apps Account" # features/step_definitions/web_steps.rb:33
And I fill in "Google Apps Domain:" with "gmail.com" # features/step_definitions/web_steps.rb:39
WARNING: making https request to https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&ltmplcache=2 without verifying server certificate; no CA path was specified.
@gsmendoza
gsmendoza / Rakefile
Created March 1, 2011 03:08
Rakefile
# require 'rake'
require 'bundler'
Bundler::GemHelper.install_tasks
dir = File.dirname(File.expand_path(__FILE__))
# $LOAD_PATH.unshift dir + '/lib/fcg-service-servers'
require 'lib/fcg-service-servers/version'
require 'rspec/core/rake_task'
@gsmendoza
gsmendoza / Leo Kottke - Standing on the Outside
Created October 24, 2010 05:44
This is a simplified version of Eric Lugosch's interpretation of the song, which you can find at http://www.youtube.com/watch?v=DIlFKw0oxUs.
Intro
E-|---------------------------------|-10--12--14------12--10----------|---------------------0-----------|-------------0---2-------0-------|-
B-|---------------------------------|-10----------------------10------|---------0-----------------------|---------3-------------------3---|-
G-|---------------------------------|-11------------------------------|---------0---6-------------------|---------2-----------------------|-
D-|---------------------------------|---------------------------------|-----0-------7-----------0-------|-----0---------------0-----------|-
A-|---------------------------------|---------------------------------|-------------7-------------------|---------------------------------|-
D-|---------------------------------|---------------------------------|-3s5-------------0---------------|-0-------------------------------|-