Skip to content

Instantly share code, notes, and snippets.

View mattheworiordan's full-sized avatar
💭
V. busy with Ably, building a great team 🚀

Matthew O'Riordan mattheworiordan

💭
V. busy with Ably, building a great team 🚀
View GitHub Profile
@mattheworiordan
mattheworiordan / features|focus_test.feature
Created August 18, 2011 21:59
Capybara-Webkit focus on an element test that fails
Feature: Capybara Webkit focus test
In order to show that Capybara Webkit does not allow an element to maintain focus
I created this feature
Which anyone can try
@javascript
Scenario: Run demo page
When I am on the capybara demo page
Then I should see a successful result
@mattheworiordan
mattheworiordan / capybara_webkit_screenshot_env.rb
Created August 19, 2011 12:26
Cucumber and Capybara-Webkit automatic screenshots on failure
def screen_shot_and_save_page
require 'capybara/util/save_and_open_page'
path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
Capybara.save_page body, "#{path}.html"
page.driver.render Rails.root.join "#{Capybara.save_and_open_page_path}" "#{path}.png"
end
begin
After do |scenario|
screen_shot_and_save_page if scenario.failed?
@mattheworiordan
mattheworiordan / focus_test.feature
Created August 23, 2011 22:44
:focus pseudo selector fix for Capybara-webkit and or Selenium with Cucumber
Feature: Capybara Webkit and Selenium :focus test
In order to show that Capybara Webkit and Selenium do not allow an element to maintain focus
I created this feature
Which anyone can try
@selenium
Scenario: Run demo page with Selenium
When I am on the capybara demo page
And I fill in "inpt" with "Test snapshot"
Then I should see a successful result
@mattheworiordan
mattheworiordan / jquery.focus.test-fix.js
Created August 23, 2011 22:47
Fix for :focus pseudo selector when browser does not have focus
/**
* JQuery tries to use native CSS selectors instead of the Sizzle selector
* engine for performance reasons.
*
* This causes problems when trying to test intefaces using the
* :focus pseudo selector as unless the web page and browser window
* has the focus, all elements are considered to be without focus.
* Checking for :focus in Selenium or Capybara tests therefore fail if
* using JQuery or Sizzle.
*
@mattheworiordan
mattheworiordan / QUnit.chain
Created September 1, 2011 16:57 — forked from filmaj/QUnit.chain
Tiny QUnit async test helper, eliminates pyramid code in async tests with multiple assertions, each requiring its own delay.
/**
* testAsyncStepsWithPause
* Executes any number of async Qunit tests with a pause between each step
*
* Author: Matthew O'Riordan, http://mattheworiordan.com
*
* Params:
* @timeToWait: milliseconds between running method and running tests
* @methods: 1+ function arguments passed in the format:
* function() {
@mattheworiordan
mattheworiordan / Gemfile
Created September 7, 2011 12:06
Test PDF within Cucumber and Capybara
# normal Gem dependancy declarations
# ...
group :test, :cucumber do
gem 'pdf-reader'
end
<p>
An alert box with Hello should have displayed
</p>
@mattheworiordan
mattheworiordan / compile.rb
Created February 15, 2012 19:39
Rails assets compilation using the correct RAILS_ENV into a Git branch
#!/usr/bin/env ruby
##
# Compile script for Rails assets that puts the assets into their [environment] branch
# thus not polluting the master branch with the files in public/assets that only
# apply to that environment. See https://github.com/rails/sass-rails/issues/93#issuecomment-3982582
#
# Usage: ./compile [environment]
# supported environments
@mattheworiordan
mattheworiordan / transport.py
Created February 23, 2012 13:57
paramiko fix for bees with machine guns
# Copyright (C) 2003-2007 Robey Pointer <robeypointer@gmail.com>
#
# This file is part of paramiko.
#
# Paramiko is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY
@mattheworiordan
mattheworiordan / loadspeed.js
Created October 24, 2012 10:13
PhantomJS working example
var page = require('webpage').create(),
system = require('system'),
t, address;
if (system.args.length === 1) {
console.log('Usage: loadspeed.js <some URL>');
phantom.exit();
}
t = Date.now();