Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add leftright gem and clean up styles and application layout

  • Loading branch information...
commit bd7c646d078b1902af784156b2df4147a3189f23 1 parent 12779ff
@joshuaclayton authored
View
1  .gitignore
@@ -6,3 +6,4 @@ public/system
*.swp
*.swo
coverage/*
+rerun.txt
View
1  app/views/layouts/application.html.erb
@@ -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>
View
1  config/environments/test.rb
@@ -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"
View
6 public/stylesheets/screen.css
@@ -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 }
View
63 vendor/gems/leftright-0.0.3/.specification
@@ -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: []
+
View
19 vendor/gems/leftright-0.0.3/MIT-LICENSE
@@ -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.
View
45 vendor/gems/leftright-0.0.3/README.rdoc
@@ -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
View
11 vendor/gems/leftright-0.0.3/WHATSNEW
@@ -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.
View
31 vendor/gems/leftright-0.0.3/leftright.gemspec
@@ -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
View
175 vendor/gems/leftright-0.0.3/lib/leftright.rb
@@ -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
View
12 vendor/gems/leftright-0.0.3/lib/leftright/autorun.rb
@@ -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
View
28 vendor/gems/leftright-0.0.3/lib/leftright/color.rb
@@ -0,0 +1,28 @@
+# This is just here to avoid depending on Term::ANSIColor and such, since
+# we need so little, and need it to transparently do nothing when
+# STDOUT is not a terminal.
+
+module LeftRight
+ module C
+ if STDOUT.tty?
+ def self.color(args)
+ name, code = args.keys.first, args.values.first
+
+ eval %' def self.#{name}(string = nil)
+ string.nil? ? "\e[#{code}m" : "\e[#{code}m" + string + "\e[0m"
+ end ', binding, __FILE__, __LINE__
+ end
+
+ color :red => 31
+ color :green => 32
+ color :yellow => 33
+ color :cyan => 36
+ color :reset => 0
+ color :bold => 1
+ else
+ def self.method_missing(color, *args)
+ args.first.nil? ? '' : args.first
+ end
+ end
+ end
+end
View
113 vendor/gems/leftright-0.0.3/lib/leftright/runner.rb
@@ -0,0 +1,113 @@
+# This is the replacement for Test::Unit::UI::Console::TestRunner
+
+module LeftRight
+ class Runner < Test::Unit::UI::Console::TestRunner
+ # Access to the LeftRight module from the Runner instance. Hopefully to
+ # reduce the likelyhood of future name clashes.
+ #
+ def lr
+ LeftRight
+ end
+
+ # We intercept this to be able to set some pertinent state.
+ #
+ def test_started(test_name)
+ name = lr.extract_class_name test_name
+ lr.state.class = lr.testcase_classes.detect { |c| c.name == name }
+
+ super
+ end
+
+ # We intercept this to be able to set some pertinent state, as well as
+ # change all remaining test methods in the current class to just skip,
+ # since we already failed once at this point.
+ #
+ def add_fault(fault)
+ lr.state.fault = fault
+ lr.skip_testing_class lr.state.class
+
+ super
+ end
+
+ # Test::Unit uses this method to print '.', 'F', 'E', and possibly
+ # others. We do most of the work here, using the state saved in
+ # 'add_fault' and 'test_finished'.
+ #
+ def output_single(captured, *etc)
+ # Make sure we are printing a test result
+ return super unless %w[ . F E ].include? captured
+
+ # Do nothing if the method was a skipper
+ return if lr.state.skip && '.' == captured
+
+ output = case captured
+ when '.' then lr.P
+ when 'F' then lr.F
+ when 'E' then lr.E
+ end
+
+ if lr.state.last_class_printed != lr.state.class
+ # If we're here, we need to print a new class name on the left side
+ lr.state.last_class_printed = lr.state.class
+ lr.state.dots = 0
+ @io.write "\n"
+ @io.write lr.justify_left_side(
+ lr.format_class_name(lr.state.class.name))
+ elsif captured != '.'
+ # This handles the edge case when the first test for a class fails
+ @io.write "\n"
+ @io.write lr.justify_left_side
+ end
+
+ # Justify all lines but first:
+ output.gsub! "\n", "\n" + lr.justify_left_side
+
+ @io.write output
+ ensure # reset all of the nasty state stuff
+ @io.flush
+ lr.state.previous_failed = captured != '.'
+ lr.state.skip = false
+ end
+
+ # This prints the final summary at the end of all tests.
+ #
+ def finished(elapsed_time)
+ passed_count = @result.run_count -
+ @result.failure_count -
+ @result.error_count - lr.state.skipped_count
+
+ total = { :passed => passed_count,
+ :failed => @result.failure_count,
+ :errors => @result.error_count,
+ :tests => @result.run_count,
+ :skipped => lr.state.skipped_count }
+
+ results = []
+
+ unless passed_count.zero?
+ total[:passed] = 'all' if passed_count == @result.run_count
+ results << lr::C.green("#{total[:passed]} passed")
+ end
+
+ unless lr.state.skipped_count.zero?
+ results << lr::C.cyan("#{total[:skipped]} skipped")
+ end
+
+ unless @result.failure_count.zero?
+ results << lr::C.red("#{total[:failed]} failed")
+ end
+
+ unless @result.error_count.zero?
+ plural = @result.error_count > 1 ? 'errors' : 'error'
+ results << lr::C.yellow("#{total[:errors]} #{plural}")
+ end
+
+ @io.write "\n"
+ @io.write "\n" unless lr.state.previous_failed
+ @io.write "#{total[:tests]} test#{'s' if @result.run_count > 1}: "
+ @io.write results.join(', ').reverse.sub(',', 'dna ').reverse # :(
+ @io.write "\n" + "\n"
+ @io.puts "(#{elapsed_time} seconds)"
+ end
+ end
+end
View
3  vendor/gems/leftright-0.0.3/lib/leftright/version.rb
@@ -0,0 +1,3 @@
+module LeftRight
+ VERSION = '0.0.3'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.