Skip to content

Instantly share code, notes, and snippets.

View gmcnaughton's full-sized avatar

Gordon McNaughton gmcnaughton

View GitHub Profile
require 'uri'
require 'net/http'
require 'openssl'
class UrlResolver
def self.resolve(uri_str, agent = 'curl/7.43.0', max_attempts = 10, timeout = 10)
attempts = 0
cookie = nil
until attempts >= max_attempts
@gmcnaughton
gmcnaughton / month.rb
Created November 18, 2015 14:59 — forked from henrik/month.rb
Ruby Month class.
require "attr_extras" # gem
class Month
vattr_initialize :year, :month_number
def self.from(object)
case object
when Month then object
else new(object.year, object.month)
end
@gmcnaughton
gmcnaughton / capybara_node_matchers.rb
Created October 29, 2012 20:22
Add support to Capybara for selectors matching the current node
# spec/support/capybara_node_matchers.rb
# Monkey-patches Capybara to add ```match_css?```, and ```match_selector?``` matchers.
module Capybara::Node::Matchers
# Returns whether this node matches the given selector.
def match_selector?(*args)
result = parent_element.all(*args)
# NOTE: In 1.1.2, ```page.find("#foo") != page.find("#foo")``` (seriously??)
# Instead, check whether the node's native representations match.
# See https://github.com/jnicklas/capybara/issues/542