leftright 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,10 @@ Both are the same, and are loaded the same way:
27
27
 
28
28
  require 'leftright'
29
29
 
30
+ If you're on JRuby, you'll need to install ffi-ncurses to format properly:
31
+
32
+ jruby -S gem install ffi-ncurses
33
+
30
34
  == Example usage
31
35
 
32
36
  require 'leftright'
data/WHATSNEW CHANGED
@@ -1,3 +1,9 @@
1
+ * 0.0.?
2
+ - Ignoring certain testcases (like ActionController::IntegrationTest) when
3
+ calculating the left margin. Does not break if Rails is not present.
4
+ - Added support for JRuby (using ffi-ncurses instead of stty (Zach Holman))
5
+ - Added (very basic) tests
6
+
1
7
  * 0.0.3 (2009-11-03):
2
8
  - Removed 'XMLOBJECT_GEMSPEC' from gemspec (copy & paste gone wrong) :(
3
9
  - Changed the TestCase collector to work like Test::Unit's.
@@ -26,6 +26,8 @@ Gem::Specification.new do |gem|
26
26
  lib/leftright/autorun.rb
27
27
  lib/leftright/color.rb
28
28
  lib/leftright/runner.rb
29
+ lib/leftright/tty.rb
29
30
  lib/leftright/version.rb
31
+ lib/leftright/force_tty.rb
30
32
  ]
31
33
  end
@@ -3,6 +3,7 @@ require 'test/unit/ui/console/testrunner'
3
3
 
4
4
  require 'leftright/version' # to open the module
5
5
 
6
+ require 'leftright/tty'
6
7
  require 'leftright/color'
7
8
  require 'leftright/runner'
8
9
  require 'leftright/autorun'
@@ -45,6 +46,14 @@ module LeftRight
45
46
  found << klass if Test::Unit::TestCase > klass
46
47
  end
47
48
 
49
+ # Rails 2.3.5 defines these, and they cramp up my style.
50
+ found.reject! { |k| k.to_s == 'ActiveRecord::TestCase' }
51
+ found.reject! { |k| k.to_s == 'ActionMailer::TestCase' }
52
+ found.reject! { |k| k.to_s == 'ActionView::TestCase' }
53
+ found.reject! { |k| k.to_s == 'ActionController::TestCase' }
54
+ found.reject! { |k| k.to_s == 'ActionController::IntegrationTest' }
55
+ found.reject! { |k| k.to_s == 'ActiveSupport::TestCase' }
56
+
48
57
  found
49
58
  end
50
59
  end
@@ -72,7 +81,37 @@ module LeftRight
72
81
  # Tries to get the terminal width in columns.
73
82
  #
74
83
  def self.terminal_width
75
- @terminal_width ||= STDOUT.tty? ? `stty size`.split[-1].to_i : 0 rescue 0
84
+ @terminal_width ||= if RUBY_ENGINE.match 'jruby'
85
+ ncurses_terminal_width
86
+ else
87
+ stty_terminal_width
88
+ end
89
+ end
90
+
91
+ # Uses stty to determine terminal width
92
+ def self.stty_terminal_width
93
+ `stty size`.split[-1].to_i
94
+ rescue
95
+ 0
96
+ end
97
+
98
+ # Uses ffi-ncurses to determine terminal width
99
+ #
100
+ def self.ncurses_terminal_width
101
+ require 'ffi-ncurses'
102
+
103
+ begin
104
+ FFI::NCurses.initscr
105
+ FFI::NCurses.getmaxyx(FFI::NCurses._initscr).reverse.first.to_i
106
+ rescue
107
+ 0
108
+ ensure
109
+ FFI::NCurses.endwin
110
+ end
111
+ rescue LoadError
112
+ puts %{ Under JRuby, you need to install the 'ffi-ncurses' gem,
113
+ since `stty` is not available. }.strip.gsub /\s+/, ' '
114
+ exit 1
76
115
  end
77
116
 
78
117
  # Tries to get the left side width in columns.
@@ -108,7 +147,7 @@ module LeftRight
108
147
  # http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
109
148
  #
110
149
  def self.wrap(line)
111
- return line unless STDOUT.tty?
150
+ return line unless tty?
112
151
  width = right_side_width - MID_SEPARATOR - RIGHT_MARGIN
113
152
  line.gsub /(.{1,#{width}})( +|$)\n?|(.{#{width}})/, "\\1\\3\n"
114
153
  end
@@ -159,7 +198,7 @@ module LeftRight
159
198
  # Returns a passing dot, aware of how many to print per-line.
160
199
  #
161
200
  def self.P
162
- return '.' unless STDOUT.tty?
201
+ return '.' unless tty?
163
202
 
164
203
  state.dots += 1
165
204
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  module LeftRight
6
6
  module C
7
- if STDOUT.tty?
7
+ if ::LeftRight::tty?
8
8
  def self.color(args)
9
9
  name, code = args.keys.first, args.values.first
10
10
 
@@ -0,0 +1,6 @@
1
+ module LeftRight
2
+ # Are we running under a terminal? YES.
3
+ def self.tty?
4
+ true
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module LeftRight
2
+ # Are we running under a terminal?
3
+ def self.tty?
4
+ STDOUT.tty?
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module LeftRight
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leftright
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
5
11
  platform: ruby
6
12
  authors:
7
13
  - Jordi Bunster
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-06 00:00:00 -05:00
18
+ date: 2010-07-31 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -30,7 +36,9 @@ files:
30
36
  - lib/leftright/autorun.rb
31
37
  - lib/leftright/color.rb
32
38
  - lib/leftright/runner.rb
39
+ - lib/leftright/tty.rb
33
40
  - lib/leftright/version.rb
41
+ - lib/leftright/force_tty.rb
34
42
  has_rdoc: true
35
43
  homepage:
36
44
  licenses: []
@@ -41,21 +49,27 @@ rdoc_options: []
41
49
  require_paths:
42
50
  - lib
43
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
44
53
  requirements:
45
54
  - - ">="
46
55
  - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
47
59
  version: "0"
48
- version:
49
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
50
62
  requirements:
51
63
  - - ">="
52
64
  - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
53
68
  version: "0"
54
- version:
55
69
  requirements: []
56
70
 
57
71
  rubyforge_project:
58
- rubygems_version: 1.3.5
72
+ rubygems_version: 1.3.7
59
73
  signing_key:
60
74
  specification_version: 3
61
75
  summary: Cool replacement for Test::Unit's TestRunner