Permalink
Browse files

Add leftright gem and clean up styles and application layout

  • Loading branch information...
1 parent 12779ff commit bd7c646d078b1902af784156b2df4147a3189f23 @joshuaclayton committed Jan 18, 2010
View
@@ -6,3 +6,4 @@ public/system
*.swp
*.swo
coverage/*
+rerun.txt
@@ -3,7 +3,6 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Peas</title>
- <%= yield :head %>
<%= stylesheet_link_tag "screen" %>
</head>
<body>
@@ -16,3 +16,4 @@
config.gem "database_cleaner", :version => ">=0.2.3"
config.gem "rspec", :version => ">= 1.3.0", :lib => false
config.gem "rspec-rails", :version => ">= 1.3.2", :lib => false
+config.gem "leftright", :version => ">= 0.0.3"
@@ -19,13 +19,7 @@ ul, li { margin: 0 0 7px 10px; padding: 0; }
ul li label { font-weight: bold; font-family: Monaco, Courier, mono-spaced; font-size: 18px; }
ul li em { font-style: normal; font-size: 11px; color: #555; }
ul li ul, ul li ul li ul { list-style-type: disc; }
-.numbered { list-style-type: decimal; }
-hr.space { visibility: hidden }
-.right { text-align: right; width: 670px; }
-.bottom { position: absolute; bottom: 10px; width: 670px; }
span { display: block; margin: 16px 0 0; font-size: 9px; color: #999; }
-span code { font-size: 10px; }
-span.fancy { font-size:12px; color:#333; font-style: italic; display: inline; font-family: Baskerville, "Warnock Pro", "Goudy Old Style", "Palatino", "Book Antiqua", Georgia, serif; }
#pea_long_url { width:555px; }
#result { width:100%; }
a { text-decoration: none; color: #333 }
@@ -0,0 +1,63 @@
+--- !ruby/object:Gem::Specification
+name: leftright
+version: !ruby/object:Gem::Version
+ version: 0.0.3
+platform: ruby
+authors:
+- Jordi Bunster
+autorequire:
+bindir: bin
+cert_chain: []
+
+date: 2009-11-06 00:00:00 -05:00
+default_executable:
+dependencies: []
+
+description: leftright is kind of like the redgreen gem. It makes passing tests look green, exceptions yellow, and failures red. It also has a few features that make your workflow a bit faster (see README).
+email: jordi@bunster.org
+executables: []
+
+extensions: []
+
+extra_rdoc_files: []
+
+files:
+- MIT-LICENSE
+- README.rdoc
+- WHATSNEW
+- leftright.gemspec
+- lib/leftright.rb
+- lib/leftright/autorun.rb
+- lib/leftright/color.rb
+- lib/leftright/runner.rb
+- lib/leftright/version.rb
+has_rdoc: true
+homepage:
+licenses: []
+
+post_install_message:
+rdoc_options: []
+
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+requirements: []
+
+rubyforge_project:
+rubygems_version: 1.3.5
+signing_key:
+specification_version: 3
+summary: Cool replacement for Test::Unit's TestRunner
+test_files: []
+
@@ -0,0 +1,19 @@
+Copyright (c) 2009 Jordi Bunster <jordi@bunster.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,45 @@
+= leftright
+
+leftright is kind of like the redgreen gem. It makes passing tests look
+green, exceptions yellow, and failures red. But then there's more:
+
+ * It lets you know which TestCase class is being tested
+ * It shows you the full text of failures and exceptions as they happen
+ * It skips all remaining tests for a TestCase class if one fails
+
+== Dependencies
+
+Right now this is pretty heavily dependent on Test::Unit, so it won't work
+in Ruby 1.9+ using MiniTest. Support is planned as soon as I find myself
+using the Ruby 1.9 + Rails 3 combo day to day.
+
+== Installation instructions
+
+From Rubyforge's gem server (might not be there):
+
+ gem install leftright
+
+From Gemcutter:
+
+ gem install leftright --source http://gemcutter.org
+
+Both are the same, and are loaded the same way:
+
+ require 'leftright'
+
+== Example usage
+
+ require 'leftright'
+
+ class SomeTest < Test::Unit::TestCase
+ def test_that_true_is_indeed_true
+ assert_equal true, true
+ end
+ end
+
+Then run the file with ruby. Mind you, it gets a lot more exciting with
+your own tests, specially if they fail. :)
+
+== Legal
+
+Copyright (c) 2009 Jordi Bunster, released under the MIT license
@@ -0,0 +1,11 @@
+* 0.0.3 (2009-11-03):
+ - Removed 'XMLOBJECT_GEMSPEC' from gemspec (copy & paste gone wrong) :(
+ - Changed the TestCase collector to work like Test::Unit's.
+
+* 0.0.2 (2009-10-28):
+ - Added this file. :)
+ - Fixed http://github.com/jordi/leftright/issues/#issue/1 which prevented
+ this from working in 1.8.6 (thanks technoweenie).
+
+* 0.0.1 (2009-10-28):
+ - First release.
@@ -0,0 +1,31 @@
+require 'lib/leftright/version'
+
+Gem::Specification.new do |gem|
+ gem.name = 'leftright'
+ gem.version = LeftRight::VERSION
+
+ gem.author, gem.email = 'Jordi Bunster', 'jordi@bunster.org'
+
+ gem.summary = "Cool replacement for Test::Unit's TestRunner"
+ gem.description = %{ leftright is kind of like the redgreen gem. It makes
+ passing tests look green, exceptions yellow, and failures red. It also
+ has a few features that make your workflow a bit faster (see README).
+ }.strip!.gsub! /\s+/, ' '
+
+ gem.has_rdoc = false
+
+ gem.date = Date.today
+ gem.files = %w[
+ MIT-LICENSE
+ README.rdoc
+ WHATSNEW
+ leftright.gemspec
+ lib
+ lib/leftright.rb
+ lib/leftright
+ lib/leftright/autorun.rb
+ lib/leftright/color.rb
+ lib/leftright/runner.rb
+ lib/leftright/version.rb
+ ]
+end
@@ -0,0 +1,175 @@
+require 'test/unit'
+require 'test/unit/ui/console/testrunner'
+
+require 'leftright/version' # to open the module
+
+require 'leftright/color'
+require 'leftright/runner'
+require 'leftright/autorun'
+
+module LeftRight
+ # In counts of ' ':
+ MID_SEPARATOR = 1
+ RIGHT_MARGIN = 1
+ LEFT_MARGIN = 1
+
+ # This whole thing is fairly gnarly, needing to keep state across multiple
+ # parts of the crazyness that is Test::Unit, so we keep it all here.
+ #
+ def self.state
+ @state ||= begin
+ fields = [
+ :dots, # the number of dots ('.') printed on this line
+ :class, # the TestCase-extending class being tested
+ :fault, # the current Test::Unit Failure/Error object
+ :last_class_printed, # last class printed on the left side
+ :previous_failed, # true if the previous test failed/exceptioned
+ :skip, # true if the current test was a skip
+ :skipped_count # total number of skipped tests so far
+ ]
+
+ state = Struct.new(*fields).new
+ state.skipped_count = 0
+ state.dots = 0
+ state
+ end
+ end
+
+ # Gets all descendants of Class that also descend from Test::Unit::TestCase
+ #
+ def self.testcase_classes
+ @testcase_classes ||= begin
+ found = []
+
+ ObjectSpace.each_object(Class) do |klass|
+ found << klass if Test::Unit::TestCase > klass
+ end
+
+ found
+ end
+ end
+
+ # Replaces all instance methods beginning with 'test' in the given class
+ # with stubs that skip testing.
+ #
+ def self.skip_testing_class(klass)
+ klass.instance_methods.each do |m|
+ if 'test' == m.to_s[0,4]
+ klass.send :define_method, m.to_sym do
+ ::LeftRight.state.skip = true
+ ::LeftRight.state.skipped_count += 1
+ end
+ end
+ end
+ end
+
+ # Formats a class name to display on the left side.
+ #
+ def self.format_class_name(class_name)
+ class_name.chomp 'Test'
+ end
+
+ # Tries to get the terminal width in columns.
+ #
+ def self.terminal_width
+ @terminal_width ||= STDOUT.tty? ? `stty size`.split[-1].to_i : 0 rescue 0
+ end
+
+ # Tries to get the left side width in columns.
+ #
+ def self.left_side_width
+ @left_side_width ||= begin
+ testcase_classes.map do |c|
+ format_class_name(c.name).size + LEFT_MARGIN
+ end.max
+ end
+ end
+
+ # Tries to get the right side width in columns.
+ #
+ def self.right_side_width
+ terminal_width - left_side_width
+ end
+
+ # Returns the given string, right-justified onto the left side.
+ #
+ def self.justify_left_side(str = '')
+ str.to_s.rjust(left_side_width) + (' ' * MID_SEPARATOR)
+ end
+
+ # This gets the class name from the 'test_name' method on a
+ # Test::Unit Failure or Error. They look like test_method_name(TestCase),
+ #
+ def self.extract_class_name(test_name)
+ test_name.scan(/\(([^(|)]+)\)/x).flatten.last
+ end
+
+ # Wraps the given lines at word boundaries. Ripped right out of
+ # http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
+ #
+ def self.wrap(line)
+ return line unless STDOUT.tty?
+ width = right_side_width - MID_SEPARATOR - RIGHT_MARGIN
+ line.gsub /(.{1,#{width}})( +|$)\n?|(.{#{width}})/, "\\1\\3\n"
+ end
+
+ # Returns the current fault as a formatted failure message.
+ #
+ def self.F(color = C.red)
+ # First, we wrap each line individually, to keep existing line breaks:
+ lines = state.fault.long_display.split("\n")
+
+ # Drop the redundant "Failure: ", "test: " (shoulda), "test_", etc
+ lines.shift if lines.first.match /Failure:|Error:/
+ lines.first.sub! /^test[\ |:|_]?/i, ''
+
+ # Drop the class name in () from the test method name
+ lines.first.sub! /\(#{state.class}\)/, ''
+
+ # shoulda puts '. :' at the end of method names
+ lines.first.sub! /\.\ :\s?/, ':'
+
+ # Wrap lines before coloring, since the wrapping would get confused
+ # by non-printables.
+ buffer = lines.map { |line| wrap line.strip }.join.strip
+
+ # We make interesting parts of the failure message bold:
+ [ /(`[^']+')/m, # Stuff in `quotes'
+ /("[^"]+")/m, # Stuff in "quotes"
+ /([^\/|\[]+\.rb:\d+)/, # Filenames with line numbers (without [box])
+ /(\s+undefined\s+)/ ].each do |interesting|
+ buffer.gsub! interesting, ( C.bold + '\0' + C.reset + color )
+ end
+
+ # These are great for assert_equal and similar:
+ buffer.sub! /(<)(.*)(>\s+expected)/,
+ '\1' + C.bold + '\2' + C.reset + color + '\3'
+ buffer.sub! /(but\s+was\s+<)(.*)(>\.)/,
+ '\1' + C.bold + '\2' + C.reset + color + '\3'
+
+ color + buffer + C.reset + "\n"
+ end
+
+ # Returns the current fault as a formatted error message.
+ #
+ def self.E
+ F C.yellow
+ end
+
+ # Returns a passing dot, aware of how many to print per-line.
+ #
+ def self.P
+ return '.' unless STDOUT.tty?
+
+ state.dots += 1
+
+ max_dots = right_side_width - RIGHT_MARGIN - MID_SEPARATOR
+
+ if state.dots >= max_dots
+ state.dots = 1
+ "\n" + C.green('.')
+ else
+ C.green '.'
+ end
+ end
+end
@@ -0,0 +1,12 @@
+# This is the only monkeypatching we do in LeftRight, since
+# Test::Unit::AutoRunner has no API for changing which runner to use. In
+# fact, it has a hardcoded list of runners.
+
+class Test::Unit::AutoRunner
+ alias :initialize_without_leftright :initialize
+
+ def initialize(*args)
+ initialize_without_leftright *args
+ @runner = lambda { |r| LeftRight::Runner }
+ end
+end
Oops, something went wrong.

0 comments on commit bd7c646

Please sign in to comment.