jstdutil 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog ADDED
@@ -0,0 +1,4 @@
1
+ == 0.2.0 / 2010-06-14
2
+ * HTML output with --html, courtesy of http://github.com/magnars
3
+ * Fix bug where --config option was not automatically added to
4
+ jsautotest --reset
data/README.rdoc CHANGED
@@ -15,4 +15,4 @@ Description goes here.
15
15
 
16
16
  == Copyright
17
17
 
18
- Copyright (c) 2009 Christian Johansen. See LICENSE for details.
18
+ Copyright (c) 2009-2010 Christian Johansen. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/lib/jstdutil/cli.rb CHANGED
@@ -15,8 +15,9 @@ module Jstdutil
15
15
  def self.run(args = [])
16
16
  args = args.join(" ")
17
17
  jar = (args.match(/--jar\s+([^\s]+)/) || [])[1] || Jstdutil.jar
18
-
19
- Jstdutil::RedGreen.format(Jstdutil.run("#{args.sub(/--jar\s+[^\s]+/, '')}", jar))
18
+ format_type = args.match(/--html/) ? Jstdutil::ColorfulHtml : Jstdutil::RedGreen;
19
+ report = Jstdutil.run("#{args.gsub(/(--jar\s+[^\s]+|--html)/, '')}", jar)
20
+ Jstdutil::Formatter.format(report, format_type)
20
21
  end
21
22
  end
22
23
  end
@@ -0,0 +1,20 @@
1
+ module Jstdutil
2
+ class ColorfulHtml
3
+
4
+ module Color
5
+
6
+ def self.method_missing(color_name, *args)
7
+ color(color_name) + args.first + "</span>"
8
+ end
9
+
10
+ def self.color(color)
11
+ "<span class='#{color}'>"
12
+ end
13
+ end
14
+
15
+ def self.wrap_report(report)
16
+ "<style>.red {color: #c00;} .green {color: #0c0;} .yellow {color: #ff0;} </style><pre>#{report}</pre>"
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module Jstdutil
2
+ class Formatter
3
+ #
4
+ # Process report from JsTestDriver and colorize it with beautiful
5
+ # colors. Returns report with encoded colors.
6
+ #
7
+ def self.format(report, type)
8
+ return "" if report.nil?
9
+
10
+ type.wrap_report(report.split("\n").collect do |line|
11
+ if line =~ /Passed: 0; Fails: 0; Errors:? 0/
12
+ type::Color.yellow(line)
13
+ elsif line =~ /Passed: \d+; Fails: (\d+); Errors:? (\d+)/
14
+ type::Color.send($1.to_i + $2.to_i != 0 ? :red : :green, line)
15
+ elsif line =~ /^[\.EF]+$/
16
+ line.gsub(/\./, type::Color.green(".")).gsub(/F/, type::Color.red("F")).gsub("E", type::Color.yellow("E"))
17
+ elsif line =~ /failed/
18
+ type::Color.red(line)
19
+ elsif line =~ /passed/
20
+ type::Color.green(line)
21
+ elsif line =~ /error/
22
+ type::Color.yellow(line)
23
+ else
24
+ line
25
+ end
26
+ end.join("\n"))
27
+ end
28
+ end
29
+ end
@@ -23,30 +23,9 @@ module Jstdutil
23
23
  end
24
24
  end
25
25
 
26
- #
27
- # Process report from JsTestDriver and colorize it with beautiful
28
- # colors. Returns report with encoded colors.
29
- #
30
- def self.format(report)
31
- return "" if report.nil?
32
-
33
- report.split("\n").collect do |line|
34
- if line =~ /Passed: 0; Fails: 0; Errors:? 0/
35
- Color.yellow(line)
36
- elsif line =~ /Passed: \d+; Fails: (\d+); Errors:? (\d+)/
37
- Color.send($1.to_i + $2.to_i != 0 ? :red : :green, line)
38
- elsif line =~ /^[\.EF]+$/
39
- line.gsub(/\./, Color.green(".")).gsub(/F/, Color.red("F")).gsub("E", Color.yellow("E"))
40
- elsif line =~ /failed/
41
- Color.red(line)
42
- elsif line =~ /passed/
43
- Color.green(line)
44
- elsif line =~ /error/
45
- Color.yellow(line)
46
- else
47
- line
48
- end
49
- end.join("\n")
26
+ def self.wrap_report(report)
27
+ report
50
28
  end
29
+
51
30
  end
52
31
  end
@@ -56,7 +56,7 @@ module Jstdutil
56
56
 
57
57
  raise ArgumentError.new("Unable to guess JsTestDriver config file, please name it jstestdriver*.conf or provide the --config option") if config.nil?
58
58
 
59
- @args.sub!(/(--config\s+[^\s]+)?/, "--config #{config}")
59
+ @args.sub!(/(--config\s+[^\s]+)?/, "--config #{config} ")
60
60
 
61
61
  JsTestDriver::Config.new(config)
62
62
  end
data/lib/jstdutil.rb CHANGED
@@ -1,4 +1,6 @@
1
+ require "jstdutil/formatter"
1
2
  require "jstdutil/redgreen"
3
+ require "jstdutil/colorful_html"
2
4
  #require "jstdutil/autotest"
3
5
 
4
6
  module Jstdutil
data/test/cli_test.rb CHANGED
@@ -8,7 +8,7 @@ class JstdutilCliTest < Test::Unit::TestCase
8
8
  jar = "path/to.jar"
9
9
  result = "REPORT"
10
10
  Jstdutil.expects(:run).with("--tests all ", jar).returns(result)
11
- Jstdutil::RedGreen.expects(:format).with(result).returns(result * 2)
11
+ Jstdutil::Formatter.expects(:format).with(result, Jstdutil::RedGreen).returns(result * 2)
12
12
 
13
13
  assert_equal result * 2, Jstdutil::Cli.run("--tests all --jar #{jar}".split(" "))
14
14
  end
@@ -18,9 +18,19 @@ class JstdutilCliTest < Test::Unit::TestCase
18
18
  result = "REPORT"
19
19
  Jstdutil.expects(:jar).returns(jar)
20
20
  Jstdutil.expects(:run).with("--tests all", jar).returns(result)
21
- Jstdutil::RedGreen.expects(:format).with(result).returns(result * 2)
21
+ Jstdutil::Formatter.expects(:format).with(result, Jstdutil::RedGreen).returns(result * 2)
22
22
 
23
23
  assert_equal result * 2, Jstdutil::Cli.run("--tests all".split(" "))
24
24
  end
25
+
26
+ should "run jstestdriver command through JsColorfulHtml with --html" do
27
+ jar = "path/to.jar"
28
+ result = "REPORT"
29
+ Jstdutil.expects(:jar).returns(jar)
30
+ Jstdutil.expects(:run).with("--tests all ", jar).returns(result)
31
+ Jstdutil::Formatter.expects(:format).with(result, Jstdutil::ColorfulHtml).returns(result * 2)
32
+
33
+ assert_equal result * 2, Jstdutil::Cli.run("--tests all --html".split(" "))
34
+ end
25
35
  end
26
36
  end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ class ColorfulHtmlTest < Test::Unit::TestCase
4
+ context "adding pretty colors" do
5
+
6
+ should "wrap in green" do
7
+ assert_equal "<span class='green'>trees</span>", Jstdutil::ColorfulHtml::Color.green("trees")
8
+ end
9
+
10
+ should "wrap in red" do
11
+ assert_equal "<span class='red'>dress</span>", Jstdutil::ColorfulHtml::Color.red("dress")
12
+ end
13
+
14
+ end
15
+
16
+ context "wrapping report" do
17
+
18
+ should "add styles and pre" do
19
+ assert_equal "<style>.red {color: #c00;} .green {color: #0c0;} .yellow {color: #ff0;} </style><pre>present</pre>",
20
+ Jstdutil::ColorfulHtml.wrap_report("present")
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,48 @@
1
+ require "test_helper"
2
+
3
+ class FormatterTest < Test::Unit::TestCase
4
+ context "formatting report" do
5
+ setup do
6
+ @report = <<-REPORT
7
+ .FE
8
+ Total 3 tests (Passed: 1; Fails: 1; Errors: 1) (2.00 ms)
9
+ Mozilla 1.9.1.2: Run 3 tests (Passed: 1; Fails: 1; Errors 1) (2.00 ms)
10
+ GreeterTest.testSomethingElse failed (1.00 ms): expected "1" but was "2"
11
+ ()@http://localhost:4224/test/test/greeter_test.js:10
12
+ [LOG] UH!
13
+ GreeterTest.testSomethingElseFails error (1.00 ms): assertEqual is not defined
14
+ ()@http://localhost:4224/test/test/greeter_test.js:14
15
+ REPORT
16
+ end
17
+
18
+ should "add pretty colors for both RedGreen and ColorfulHtml" do
19
+ verify_pretty_colors(Jstdutil::RedGreen)
20
+ verify_pretty_colors(Jstdutil::ColorfulHtml)
21
+ end
22
+
23
+ end
24
+
25
+ def verify_pretty_colors(type)
26
+ report = Jstdutil::Formatter.format(@report, type)
27
+
28
+ lines = @report.split("\n")
29
+
30
+ expected = type::Color.green(".") +
31
+ type::Color.red("F") +
32
+ type::Color.yellow("E") + "\n"
33
+ expected << type::Color.red(lines[1]) + "\n"
34
+ expected << type::Color.red(lines[2]) + "\n"
35
+ expected << type::Color.red(lines[3]) + "\n"
36
+ expected << lines[4] + "\n"
37
+ expected << lines[5] + "\n"
38
+ expected << type::Color.yellow(lines[6]) + "\n"
39
+ expected << lines[7]
40
+
41
+ expected = type.wrap_report(expected)
42
+
43
+ expected.split("\n").size.times {|i|
44
+ assert_equal expected.split("\n")[i], report.split("\n")[i]
45
+ }
46
+ assert_equal expected, report
47
+ end
48
+ end
@@ -1,45 +1,23 @@
1
1
  require "test_helper"
2
2
 
3
3
  class RedGreenTest < Test::Unit::TestCase
4
- context "formatting report" do
5
- setup do
6
- @report = <<-REPORT
7
- .FE
8
- Total 3 tests (Passed: 1; Fails: 1; Errors: 1) (2.00 ms)
9
- Mozilla 1.9.1.2: Run 3 tests (Passed: 1; Fails: 1; Errors 1) (2.00 ms)
10
- GreeterTest.testSomethingElse failed (1.00 ms): expected "1" but was "2"
11
- ()@http://localhost:4224/test/test/greeter_test.js:10
12
- [LOG] UH!
13
- GreeterTest.testSomethingElseFails error (1.00 ms): assertEqual is not defined
14
- ()@http://localhost:4224/test/test/greeter_test.js:14
15
- REPORT
16
- end
4
+ context "adding pretty colors" do
17
5
 
18
- should "add pretty colors" do
19
- report = Jstdutil::RedGreen.format(@report)
6
+ should "wrap in green" do
7
+ assert_equal "\e[32mtrees\e[0m", Jstdutil::RedGreen::Color.green("trees")
8
+ end
20
9
 
21
- lines = @report.split("\n")
10
+ should "wrap in red" do
11
+ assert_equal "\e[31mdress\e[0m", Jstdutil::RedGreen::Color.red("dress")
12
+ end
22
13
 
23
- expected = Jstdutil::RedGreen::Color.green(".") +
24
- Jstdutil::RedGreen::Color.red("F") +
25
- Jstdutil::RedGreen::Color.yellow("E") + "\n"
26
- expected << Jstdutil::RedGreen::Color.red(lines[1]) + "\n"
27
- expected << Jstdutil::RedGreen::Color.red(lines[2]) + "\n"
28
- expected << Jstdutil::RedGreen::Color.red(lines[3]) + "\n"
29
- expected << lines[4] + "\n"
30
- expected << lines[5] + "\n"
31
- expected << Jstdutil::RedGreen::Color.yellow(lines[6]) + "\n"
32
- expected << lines[7]
14
+ end
15
+
16
+ context "wrapping report" do
33
17
 
34
- assert_equal expected.split("\n")[0], report.split("\n")[0]
35
- assert_equal expected.split("\n")[1], report.split("\n")[1]
36
- assert_equal expected.split("\n")[2], report.split("\n")[2]
37
- assert_equal expected.split("\n")[3], report.split("\n")[3]
38
- assert_equal expected.split("\n")[4], report.split("\n")[4]
39
- assert_equal expected.split("\n")[5], report.split("\n")[5]
40
- assert_equal expected.split("\n")[6], report.split("\n")[6]
41
- assert_equal expected.split("\n")[7], report.split("\n")[7]
42
- assert_equal expected, report
18
+ should "add nothing" do
19
+ assert_equal "bare", Jstdutil::RedGreen.wrap_report("bare")
43
20
  end
21
+
44
22
  end
45
23
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Christian Johansen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-08 00:00:00 +02:00
17
+ date: 2010-06-14 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,7 @@ extra_rdoc_files:
64
64
  - LICENSE
65
65
  - README.rdoc
66
66
  files:
67
+ - Changelog
67
68
  - LICENSE
68
69
  - README.rdoc
69
70
  - Rakefile
@@ -74,6 +75,8 @@ files:
74
75
  - lib/jstdutil.rb
75
76
  - lib/jstdutil/autotest.rb
76
77
  - lib/jstdutil/cli.rb
78
+ - lib/jstdutil/colorful_html.rb
79
+ - lib/jstdutil/formatter.rb
77
80
  - lib/jstdutil/hooks.rb
78
81
  - lib/jstdutil/jstestdriver/config.rb
79
82
  - lib/jstdutil/jstestdriver/server.rb
@@ -82,6 +85,8 @@ files:
82
85
  - lib/jstdutil/test_runner.rb
83
86
  - lib/watchr_script
84
87
  - test/cli_test.rb
88
+ - test/colorful_html_test.rb
89
+ - test/formatter_test.rb
85
90
  - test/jstdutil_test.rb
86
91
  - test/jstestdriver_config_test.rb
87
92
  - test/jstestdriver_test.rb
@@ -119,6 +124,7 @@ signing_key:
119
124
  specification_version: 3
120
125
  summary: Thin wrapper over Google's JsTestDriver that adds colors and autotest
121
126
  test_files:
127
+ - test/formatter_test.rb
122
128
  - test/jstestdriver_test.rb
123
129
  - test/cli_test.rb
124
130
  - test/test_file_test.rb
@@ -126,3 +132,4 @@ test_files:
126
132
  - test/test_helper.rb
127
133
  - test/jstdutil_test.rb
128
134
  - test/jstestdriver_config_test.rb
135
+ - test/colorful_html_test.rb