Skip to content

Instantly share code, notes, and snippets.

@wrecked
Created March 1, 2009 01:50
Show Gist options
  • Save wrecked/72171 to your computer and use it in GitHub Desktop.
Save wrecked/72171 to your computer and use it in GitHub Desktop.
# Bradley Taylor - railsmachine.com
# Collect Cucumber metrics for a given path and send them to Dash.
module Dash::Sensor::Plugins
class Cucumber
include SensorPlugin
register :cucumber, :url => 'http://dash.fiveruns.com' do |recipe|
recipe.absolute :scenarios do
stats[:scenarios]
end
steps = %w{passed failed skipped pending}
[:passed, :failed, :skipped, :pending].each do |step|
recipe.absolute step, "Steps #{step.to_s}" do
stats[step]
end
end
end
def configure(options)
@path = options[:path]
end
private
def self.stats
if !@time || @time < Time.now - 55
@old_stats = @stats || Hash.new(0)
logger.debug "Fetching status at #{Time.now}"
@stats = instance.send(:stats_data)
@time = Time.now
end
@stats
end
def self.old_stats
@old_stats
end
def stats_data
begin
output = `cucumber #{@path}/features`
results = Hash.new(0)
if output =~ /(\d+) scenario/
results[:scenarios] = $1.to_i
end
[:passed, :failed, :skipped, :pending].each do |s|
if output =~ /(\d+) step[s]* #{s.to_s}/
results[s] = $1.to_i
end
end
results
rescue Exception => e
logger.error "Error running #{@path}"
logger.error "#{e.class.name}: #{e.message}"
Hash.new(0)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment