Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'fileutils'
class TestFinder
attr_reader :prefix
def initialize(prefix)
@prefix = prefix
#!/usr/bin/env ruby
lines = STDIN.readlines
leading_match = lines.first.match(/^\s+/)
leading = leading_match ? leading_match[0] : ''
lines_without_edges = lines.map { |line| line.strip.sub(/^\|/, '').sub(/\|$/, '') }
lines_without_edges.reject! { |line| line.empty? }
table = lines_without_edges.map { |line| line.split('|').map { |cell| cell.strip } }
cell_count = table.first.size
widths = (0...cell_count).map do |index|
table.inject(0) do |result, row|
require 'rubygems'
require 'action_controller'
class StandaloneController < ActionController::Base
def index
render :text => 'Hello'
end
end
# blows up without session config otherwise

Goals:

  • Unify syntax (no more should_* methods if possible)
  • Make matchers less tied to the framework
  • Move towards rspec
  • Remain fully backwards-compatible for now (with deprecation warnings)
  • Remain compatible with Test::Unit for now (no deprecation warnings)
  • Look into deprecating context framework (create separate project)
  • Remove remaining string evals
  • Try and come up with a (hopefully non-invasive) Test::Unit syntax for using matchers
class PathBasedAuth
def initialize(app, opts, &block)
@app = app
@path = opts[:path]
@block = block
@auth = Rack::Auth::Basic.new(app, &block)
end
def call(env)
if path_matches?(env)
class HashWithLazy < Hash
attr_reader :lazy
def initialize(*args, &block)
@lazy = {}
super(*args, &block)
end
def [](key)
if @lazy.key?(key)
// clear inputs with starter values
PrefilledInput = Class.create({
initialize:
function(input) {
this.input = $(input);
this.prefilled_value = input.title;
this.input.title = '';
this.observe();
this.blur();
},
// clear inputs with starter values
new function($) {
$.fn.prefilledInput = function() {
var focus = function () {
$(this).removeClass('prefilled');
if (this.value == this.prefilledValue) {
this.value = '';
}
};
module CollectionMatchers
# Use with any existing matcher
# Example:
# posts.should all.be_published
# # Same as:
# posts.should_not be_empty
# posts.each { |post| post.should be_published }
def all
CollectionMatcher.new(self)
end
module CucumberJavascript
MOCK_XHR = %{
<script type="text/javascript">
var originalXMLHttpRequest = new XMLHttpRequest();
XMLHttpRequest = function() {
this.xml = originalXMLHttpRequest;
return this;
};