Skip to content

Instantly share code, notes, and snippets.

View akiellor's full-sized avatar

Andrew Kiellor akiellor

View GitHub Profile
@akiellor
akiellor / document_spec.rb
Created January 2, 2012 05:20
XPath matcher using nokogiri.
require 'nokogiri'
RSpec::Matchers.define :have_xpath do |*paths|
match do |doc|
!doc.xpath(*paths).empty?
end
end
def within *paths, &block
describe "within #{paths.inspect}" do
@akiellor
akiellor / step_invocation.rb
Created April 7, 2012 23:08
Platform sniffing...grrrr
class Cucumber::Ast::StepInvocation
def failed(configuration, e, clear_backtrace)
if Cucumber::JRUBY && e.class.name == 'NativeException'
# JRuby's NativeException ignores #set_backtrace.
# We're fixing it.
e.instance_eval do
def set_backtrace(backtrace)
@backtrace = backtrace
end
@akiellor
akiellor / build.gradle
Created July 25, 2012 07:39
Sample Gradle Project using GemJars
repositories {
ivy {
ivyPattern "http://repository.gemjars.org/ivys/[organisation]/ivy-[module]-[revision].xml"
artifactPattern "http://repository.gemjars.org/jars/[organisation]/[module]-[revision].jar"
}
}
configurations {
rspec.extendsFrom runtime
}
@akiellor
akiellor / gist:3288126
Created August 7, 2012 18:33
WebDriver Traffic
POST /session HTTP/1.1
GET /session/ad69c299769a6a219f10173073210387 HTTP/1.1
POST /session/ad69c299769a6a219f10173073210387/element/:wdc:1344363770883/elements HTTP/1.1
POST /session/ad69c299769a6a219f10173073210387/elements HTTP/1.1
GET /session/ad69c299769a6a219f10173073210387/element/:wdc:1344363775379/displayed HTTP/1.1
POST /session/ad69c299769a6a219f10173073210387/elements HTTP/1.1
GET /session/ad69c299769a6a219f10173073210387/element/:wdc:1344363775380/displayed HTTP/1.1
POST /session/ad69c299769a6a219f10173073210387/element/:wdc:1344363775380/elements HTTP/1.1
GET /session/ad69c299769a6a219f10173073210387/element/:wdc:1344363775381/displayed HTTP/1.1
GET /session/ad69c299769a6a219f10173073210387/element/:wdc:1344363775381/selected HTTP/1.1
YAML.add_builtin_type('yes_no') {|type, value| value == 'Y'}
YAML.load("blah: !yes_no 'Y'") == {'blah' => true}
import math
class Calculator:
def plus(self, first, second):
return first + second
def pi(self):
return math.pi
class Blah
def to_ary
[1, 2, 3]
end
end
blah = Blah.new
one, two, three = blah
class Foo
def self.with_bar
Foo.new(Bar.new)
end
def initiatize bar
@bar = bar
end
def something_fun
@akiellor
akiellor / Main.java
Last active December 20, 2015 08:49
Maven + JRuby + Pry Example
package com.example.pry;
import org.jruby.embed.ScriptingContainer;
public class Main {
public static void main(String... args){
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet("require 'pry'; binding.pry");
}
}
@akiellor
akiellor / gist:12db63d9b578447b9aed
Created February 6, 2015 03:46
Mocha/Promise error detection.
var falafel = require('falafel');
var fs = require('fs');
var file = process.argv[2];
var src = fs.readFileSync(file).toString();
var output = falafel(src, {loc: true}, function (node) {
if (node.type === 'Identifier' && node.name === "it") {
var testBody = node.parent.arguments[1].body.body
var lastStatement = testBody[testBody.length - 1];