Skip to content

Instantly share code, notes, and snippets.

@nyx
Forked from unicornrainbow/bookmark.rb
Created January 27, 2011 20:41
Show Gist options
  • Save nyx/799216 to your computer and use it in GitHub Desktop.
Save nyx/799216 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require 'yaml'
require 'term/ansicolor'
include Term::ANSIColor
# Usage:
# > rake test | bookmark # => Bookmark test output
# > bookmark 1 # => Open first failing test.
# > bookmark 2 # => Open second failing test.
if ARGV[0]
bookmark = ARGV[0].to_i - 1
bookmarks = YAML.load(File.open('.bookmarks'))
`mate #{bookmarks[bookmark][:path]} -l #{bookmarks[bookmark][:line_number]}`
else
i = 0
bookmarks = []
ARGF.each do |line|
failure = line.match(/(.*)\((.*)\).*\[(.*):(\d*)\]/)
if failure
test_case, test, path, line_number = *failure[1..4]
bookmarks[i] = {test_case: test_case, test: test, path: path, line_number: line_number}
i += 1
puts "#{red(test_case)}(#{test}) [#{bold(path)}:#{line_number}]"
else
puts line
end
end
# Write the bookmarks to disk.
File.open('.bookmarks', "w") {|file| file.puts(bookmarks.to_yaml) }
end
# Ignore the .bookmark file
echo .bookmarks >> ~/.gitignore
# Optionally run output from rake through bookmark for auto bookmarking. Beware: may have strange side-effects.
rake(){
command rake "$@" | bookmark
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment