This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |