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
class TreeNode | |
attr_accessor :nodeType, :value, :children | |
def initialize(nodeType, value, children=[]) | |
raise Exception unless children.is_a?(Array) | |
@nodeType = nodeType | |
@value = value | |
@children = children | |
end | |
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
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })} | |
RSpec::Matchers.define :accept_nested_attributes_for do |association| | |
match do |model| | |
@model = model | |
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym) | |
if @nested_att_present && @reject | |
model.send("#{association}_attributes=".to_sym,[@reject]) | |
@reject_success = model.send("#{association}").empty? | |
end | |
model.send("#{association}").clear |
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 'rack/test' | |
describe SampleMiddleware do | |
include Rack::Test::Methods | |
let(:inner_app) do | |
lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All good!'] } | |
end | |
let(:app) { SampleMiddleware.new(inner_app) } |
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
#!/usr/bin/env python | |
'''\ | |
Usage: cookbookdiff COOKBOOK_NAME COOKBOOK_VER LOCAL_PATH [--nocolor] | |
Diff your LOCAL_PATH against what is on the chef server for a | |
given cookbook and version. | |
--nocolor: don't pipe output through 'colordiff' (in case you want to pipe to something else) | |
Examples: | |
cookbookdiff percona_toolkit 0.0.4 ~/chef-repo/cookbooks/percona_toolkit |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
# Updated for rspec 3.0: | |
module IncludeRecipeHelper | |
def enable_stubbed_include_recipe | |
# Don't worry about external cookbook dependencies | |
allow_any_instance_of(Chef::Cookbook::Metadata).to receive(:depends) | |
# Test each recipe in isolation, regardless of includes | |
@included_recipes = [] | |
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipe?).and_return(false) | |
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe) do |recipe, included_recipe| |