Skip to content

Instantly share code, notes, and snippets.

@tpope
tpope / env.rb
Created September 2, 2009 21:27
# Enable Webrat's Selenium mode if one or more scenarios is tagged @selenium
Webrat.configure do |config|
config.mode = :rails
ObjectSpace.each_object(Cucumber::Ast::Features) do |features|
config.mode = :selenium if features.tag_count('selenium').nonzero?
end
end
When /^(.*) in the "([^\"]*)" section$/ do |action, title|
within "//*[(h1|h2|h3|h4|h5|h6|legend|caption)/descendant-or-self::*[contains(text(), '#{title}')]]" do
When action
end
end
When /^(.*) in the "([^\"]*)" row$/ do |action, title|
within "//*[(th|td)/descendant-or-self::*[contains(text(), '#{title}')]]" do
When action
end
def mask _;_[6..-5]='*'.*_.size-10;_;end
def luhn?n;s=0;n.size.times{|i|x=n[-i-1,1].to_i*(i%2+1);s+=x>9?x+1:x};s%10==0;end
def fibsum _;_<3?_:1+fibsum(_-1)+fibsum(_-2)end
def ccexp?d;d[-2,2].to_i<=10&&d[0,2].to_i<7 end
def morse s;26.times{|i|s.gsub!(/#{(97+i).chr}/i,"$be5 J8G#T6P'&9Sl/,!-H0cfk".split('').map{|x|(x[0]-31).to_s(3).tr('12','.-')}[i])};s;end
def ccexp?d;d[-2,2].to_i<=10&&d[0,2].to_i<7 end
def ccexp?d;m=d[-2,2].to_i;m<10||m==10&&d[0,2].to_i<7;end
@tpope
tpope / morse.rb
Created June 11, 2010 03:50 — forked from ryanb/morse.rb
def morse s;s.upcase.gsub(/\S/){|x|("CF+(514M )DGL"[x[0]-65]).to_s(3).tr("12",".-")};end