Skip to content

Instantly share code, notes, and snippets.

@bfaloona
bfaloona / gist:158796
Created July 30, 2009 17:30
watircraft page, step definition, and method to call should assertion on a page object using gherkin text
#
# detail_reports_page.rb
#
class DetailReportsPage < ::Taza::Page
element(:add_report) {browser.link(:href, 'javascript:createReport();')}
field(:level_dropdown) {browser.select_list(:name, 'Level')}
end
#
# steps.rb
@bfaloona
bfaloona / formatter_html_spec_embed.rb
Created December 21, 2009 21:14
cucumber formatter html embed spec and patch
# spec/cucumber/formatter/html_spec.rb
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/spec_helper'
require 'cucumber/formatter/html'
require 'nokogiri'
require 'cucumber/rb_support/rb_language'
module Cucumber
module Formatter
@bfaloona
bfaloona / screenshot_from_watir.rb
Created December 28, 2009 08:18
screenshot of active window from watir
require 'watir/screen_capture'
include Watir::ScreenCapture
# http://wtr.rubyforge.org/rdoc/classes/Watir/ScreenCapture.html
screen_capture('screenshot.jpg', true)
@bfaloona
bfaloona / cucumber.yml
Created December 28, 2009 17:58
cucumber profiles that require code and load other profiles
##
# cucumber profiles that define settings and require code (including a common support/env.rb file)
default: --require features/support/ --require features/step_definitions --format html --out report.html
# this profile includes another profile
verbose: --verbose --require features/support2/ --profile pretty
# sets one option
pretty: --format pretty
>> require 'drb'
=> true
>> client = DRbObject.new( nil, 'druby://:1234')
=> #<DRb::DRbObject:0x1016c8c78 @ref=nil, @uri="druby://:1234">
>> client.connection
=> 1
>> client.cookbook do
?> return true
>> end
DRb::DRbConnError: DRb::DRbServerNotFound
require 'uwchat'
module UWChat
class ServerCommand
# ...
end
end
# bug 672 repros when cucumber is called with line number on feature below, e.g.:
$ cucumber features/failing_before_hook_in_background.feature:4
# env.rb
Before('@bug672') do |scenario|
raise Exception, "Exception from before hook tagged @bug672"
end
# features/failing_before_hook_in_background.feature
@bfaloona
bfaloona / gist:710107
Created November 22, 2010 15:26
Access to WatirCraft Methods from WatirCraft page classes
# lib/methods/versions.rb
module MyProject
module Methods
def app_version
browser.url.match(/\/myproject\/([0-9]{2})\//)[1].to_i
end
end
end
@bfaloona
bfaloona / gist:834214
Created February 18, 2011 19:07
Cucumber bug 701
# features/bug701_rerun_scenario_outline.feature
#
# To repro bug 701, run:
# cucumber features/bug701_rerun_scenario_outline.feature -f rerun -o rerun.txt
# then:
# cat rerun.txt
# I expect the file to have two failing references, but the scenario outline is NOT referenced at all.
#
Feature: Bug701 - Rerun formatter does not include failures that occur in scenario outline examples
@bfaloona
bfaloona / fast_source
Created February 27, 2012 06:38
Simple binary search on a faux logfile
class FastSource
def open(string)
Struct.new("Line", :id, :msg)
@data = []
string.each do |line|
id, msg = line.split(',')
@data << Struct::Line.new(id.strip.to_i, msg.chomp)
end
@data
end