Created
January 1, 2009 01:28
-
-
Save xaviershay/42170 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/vendor/expectations-1.0.0/lib/expectations/suite_results.rb b/vendor/expectations-1.0.0/lib/expectations/suite_results.rb | |
index 2beb638..34d45e0 100644 | |
--- a/vendor/expectations-1.0.0/lib/expectations/suite_results.rb | |
+++ b/vendor/expectations-1.0.0/lib/expectations/suite_results.rb | |
@@ -3,11 +3,11 @@ class Expectations::SuiteResults | |
def initialize(out) | |
self.out, self.expectations = out, [] | |
- out.print "Expectations " | |
+ out.print "Expectations " unless ENV["FORMAT"] == "yaml" | |
end | |
def <<(expectation_result) | |
- out.print expectation_result.char | |
+ out.print expectation_result.char unless ENV["FORMAT"] == "yaml" | |
self.expectations << expectation_result | |
self | |
end | |
@@ -31,11 +31,29 @@ class Expectations::SuiteResults | |
def print_results(benchmark) | |
run_time = benchmark.real | |
run_time = 0.001 if run_time < 0.001 | |
- out.puts "\nFinished in #{run_time.to_s.gsub(/(\d*)\.(\d{0,5}).*/,'\1.\2')} seconds" | |
- if succeeded? | |
- print_success | |
+ if ENV["FORMAT"] == "yaml" | |
+ out.puts({ | |
+ :run_time => run_time, | |
+ :successes => | |
+ fulfilled.collect {|result| | |
+ [:file, :line].inject({}) {|a, v| a.update(v => result.send(v)) } | |
+ }, | |
+ :errors => | |
+ errors.collect {|error| | |
+ [:file, :line].inject({:message => error.exception.message}) {|a, v| a.update(v => error.send(v)) } | |
+ }, | |
+ :failures => | |
+ failures.collect {|error| | |
+ [:file, :line, :message].inject({}) {|a, v| a.update(v => error.send(v)) } | |
+ } | |
+ }.to_yaml) | |
else | |
- print_fail | |
+ out.puts "\nFinished in #{run_time.to_s.gsub(/(\d*)\.(\d{0,5}).*/,'\1.\2')} seconds" | |
+ if succeeded? | |
+ print_success | |
+ else | |
+ print_fail | |
+ end | |
end | |
end | |
@@ -99,4 +117,4 @@ class Expectations::SuiteResults | |
"\n #{line}" | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end |
This file contains 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
# Inline expectations for VIM | |
# http://flickr.com/photos/18919286@N08/2574758795/ | |
# | |
# To run on the current buffer: | |
# :rubyf inline-expectations.rb | |
# | |
# I have no idea if this still works, YMMV | |
# | |
# For extra speed use ruby_fork (this code does, you could modify to just use ruby) | |
# http://blog.segment7.net/articles/2006/04/08/speeding-up-test-runs-with-fork | |
# | |
# You'll need to patch expectations as well | |
require 'yaml' | |
file_name = VIM::evaluate("expand('%:p')") | |
highlight_errors = true | |
VIM::command("match none") | |
VIM::command("2match none") | |
VIM::command("highlight StatusLine guifg=black guibg=grey") | |
#if file_name =~ %r{app/models/(.*).rb$} | |
# expect_file = "expectations/models/#{$1}_expect.rb" | |
# highlight_errors = false | |
# file_name = file_name.gsub(%r{app/models/(.*).rb$}, '') + expect_file | |
#end | |
if File.open(file_name).grep(/^\s*Expectations/).empty? | |
print "Not an expectations file" | |
else | |
results = `ruby_fork_client -r '#{file_name}'` | |
y = YAML.load(results) | |
VIM::command("highlight TestError guibg=Brown") | |
VIM::command("highlight TestException guibg=DarkRed") | |
i = nil | |
if highlight_errors | |
{ | |
:failures => 'TestError', | |
:errors => 'TestException', | |
:successes => '' | |
}.each_pair do |type, matchClass| | |
if (y[type] || []).empty? | |
VIM::command("#{i}match none") | |
else | |
y[type].each do |result| | |
b = VIM::Buffer.current | |
line = b[result[:line]] | |
line.gsub!(/ # =>.*$/, '') | |
new_line = line + (result[:message] ? " # => #{result[:message]}" : '') | |
b[result[:line]] = new_line unless b[result[:line]] == new_line | |
end | |
fail_lines = y[type].collect {|line| "\\%#{line[:line]}l" }.join('\|') | |
unless matchClass.empty? | |
VIM::command("#{i}match #{matchClass} /#{fail_lines}/") | |
i = 2 | |
end | |
end | |
end | |
end | |
VIM::set_option(("statusline=%<%f\ %h%m%r%=" + "%i Succeeded, %i Failed, %i Errored (%.3fs)" % ([:successes, :failures, :errors].collect {|type| y[type].length} << y[:run_time])).gsub(' ', '\ ')) | |
unless (y[:failures] + y[:errors]).empty? | |
VIM::command("highlight StatusLine guibg=Brown") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment