-
-
Save nyx/799216 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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