Skip to content

Instantly share code, notes, and snippets.

module HarmonyHelpers
def haromeny_page
anchor = URI.parse(root_url).merge(current_url).fragment
Harmony::AnchoredPage.new(current_page_body, anchor)
end
end
module Harmony
class Page
module Window
module Cucumber
module Ast
class StepInvocation
def accept_with_logging(visitor)
if defined?(::Rails)
::Rails.logger.debug "*** Starting Cucumber Step: #{name} ***"
end
accept_without_logging(visitor)
if defined?(::Rails)
::Rails.logger.debug "*** Done With Cucumber Step: #{name} ***"
// clear inputs with starter values
new function($) {
$.fn.prefilledInput = function() {
var focus = function () {
$(this).removeClass('prefilled');
if (this.value == this.prefilledValue) {
this.value = '';
}
};
When %{I follow "$link_text" closest to "$reference_text"} do |link_text, reference_text|
link_element = closest_to(reference_text, %{.//a[contains(., "#{link_text}")]})
link = Webrat::Link.load(webrat_session, link_element)
link.click
end
module ClosestTo
def closest_to(reference_text, selector)
elements = current_dom.search("h1, h2, h3, h4, h5, h6, td, li, p")
reference_element = elements_directly_containing(reference_text).first
notify_deploy_environments = %w(staging production)
notify_deploy_roles = %w(solo app_master)
if notify_deploy_environments.include?(@configuration[:environment]) && notify_deploy_roles.include?(node['instance_role'])
# Notify Hoptoad of deploy
run "cd #{release_path} && rake hoptoad:deploy TO=#{@configuration[:environment]} REVISION=#{@configuration[:revision]} REPO=#{@configuration[:repository]}"
end
Factory.define :post do |post_factory|
post_factory.user { Factory.build(:user) }
end
describe Topic, "newest ordered by creation" do
factory :first_topic, :topic, :created_at => 3.days.ago
factory :second_topic, :topic, :created_at => 2.days.ago
factory :third_topic, :topic, :created_at => 1.day.ago
factory :fourth_topic, :topic, :created_at => 1.day.ago
it "should be able to find the newest topics" do
Topic.newest.map.should == [fourth_topic,
third_topic,
second_topic,
Before do
Capybara.current_session.driver.rack_mock_session.after_request do
body = Capybara.current_session.driver.response.body
if match = body.match(%r{<\w+(?:\s+\w+\s*=\s*"[^&]+")*\s*/?>})
puts "WARNING: escaped tag: " +
match[0].gsub("&lt;", "<").gsub("&gt;", ">").gsub("&quot;", '"')
end
if match = body.match(%r{&amp;(\w+);})
@jferris
jferris / new.rb
Created November 5, 2010 18:23
New FactoryGirl definition syntax
FactoryGirl.define do
sequence :email do |n|
"user#{n}@example.com"
end
factory :user do
email
password "test"
aliased_as :author
end
@jferris
jferris / new.rb
Created November 5, 2010 18:27
factory_girl_rspec_integration.rb
describe Message do
create :account, :name => "My Account" do
create :user
create :project
with :project, :user => :author do
create :message
end
end