Skip to content

Instantly share code, notes, and snippets.

View pragmaticpat-zz's full-sized avatar

Patrick Sullivan pragmaticpat-zz

  • Near Cleveland Ohio
View GitHub Profile
@pragmaticpat-zz
pragmaticpat-zz / gist:2210413
Created March 26, 2012 22:54
hydrating nokogiri html object from a file in one line. cool!
File.open(source_file_name, "r") { |f| page = Nokogiri::HTML(f.read()) }
@pragmaticpat-zz
pragmaticpat-zz / sample.rb
Created February 25, 2012 15:32
Rails 3.1 STI
class Wod < ActiveRecord::Base
HOST_BOX_NAME = "CrossFit HQ"
def from_html crossfit_hq_source
page = Nokogiri::HTML(crossfit_hq_source)
self.date = Date.parse(page.search("//h3")[0].inner_text.split[1]).to_s
self.details = page.search("//p")[0].inner_text
if(hero_wod || games_wod)
self.details << "\n" << page.search("//p")[1].inner_html.gsub(/<br>/,"\n")
end
@pragmaticpat-zz
pragmaticpat-zz / rspec-given-when-to-start-eval
Created January 14, 2012 19:35
Wondering if it's by design that rspec-given will not evaluate missing methods until "then" is present
require 'concept_im_evolving'
require 'rspec/given'
#Sample1: Run rspec >> No examples found.
describe ConceptImEvolving do
Given (:getter) { ConceptImEvolving.new }
context "when there is a new item" do
When { getter.get_latest_item("some_uri") }
end
@pragmaticpat-zz
pragmaticpat-zz / generic search step
Created October 15, 2011 23:58
A bad way to check for content with cucumber / capybara?
Then /^I should see$/ do |table|
table.hashes.each do |stuff|
stuff.keys.each { |key| page.should have_content stuff[key] }
end
end
@pragmaticpat-zz
pragmaticpat-zz / stuff
Created September 24, 2011 13:59
rental management
1 Feature: Manage rentals
2 In order to optimize my investments
3 As a rental baron
4 I want to be able to manage my rentals
5
6 Scenario Outline: Rental count
7 Given I have <number> rentals
8 When I go to the rentals page
9 Then I should see "<number> rentals found"
10