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
lass Foo | |
include Multidispatch | |
def bar | |
"bar" | |
end | |
def bar(a, n=1) | |
"#{a} bar #{n}" | |
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
module ::Kernel | |
@@default_values = {} | |
def initialize | |
@@default_values.each_pair do |attr_name, value| | |
variable = :"@#{attr_name}" | |
instance_variable_set variable, value | |
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
class MyStruct | |
def self.new(*attributes, &block) | |
Class.new do | |
attributes.each do |attr| | |
attr_accessor attr | |
end | |
define_method :initialize do |*values| | |
values.each_with_index do |value, index| | |
attribute = attributes[index] |
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
function RegistrationPageObject(container) { | |
this.container = container; | |
this.elements = { | |
age: this.container.querySelector("input[id=age]"), | |
agree: this.container.querySelector("input[id=agree]"), | |
female: this.container.querySelector("input[id=female]"), | |
gender: this.container.querySelectorAll("input[name=gender]"), | |
male: this.container.querySelector("input[id=male]"), | |
name: this.container.querySelector("input[id=name]"), |
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
// Looks like this does not work: | |
// this.container.querySelector("input[id=name]").value = "John A."; | |
function simulateChange(element) { | |
var evt; | |
if ("createEvent" in document) { | |
evt = document.createEvent("HTMLEvents"); | |
evt.initEvent("change", false, true); | |
element.dispatchEvent(evt); |
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
describe("form field: age", function () { | |
before(function () { | |
this.input = this.page.elements.age; | |
this.field = this.input.parentElement; | |
this.label = this.field.querySelector("label"); | |
}); | |
it("should have label marked valid", function () { | |
this.label.className.should.not.match(/invalid/); | |
}); |
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
var script = document.createElement("SCRIPT"); | |
script.src = "/path/to/mocha.js"; | |
script.onload = function () { /* … */ }; | |
script.onerror = function () { /* … */ }; | |
var head = document.getElementsByTagName("head")[0]; | |
head.appendChild(script); |
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
describe("survey app", function () { | |
describe_registration_form(function () { | |
when_fields_are_empty(function () { | |
after_submit(function () { | |
validation_suite_for_registration({ | |
name: false, | |
age: false, | |
gender: false, | |
agree: false | |
}); |
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
function waitForCondition(condition, timeout, rejectReason) { | |
timeout = timeout || 5000; // 5 secs by default | |
rejectReason = "waited for " + timeout + "ms " + | |
"until " + (rejectReason || "something to happen"); | |
return new Promise(function (resolve, reject) { | |
var result = condition(), | |
timerId, | |
pollId; |
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
function naiveWait(condition, callback) { | |
var pollId = setInterval(function () { | |
if (condition()) { | |
clearInterval(pollId); | |
resolve(result); | |
} | |
}, 10); | |
} |
OlderNewer