jasmine-headless-webkit 0.7.3.2 → 0.8.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +6 -0
  3. data/Rakefile +19 -0
  4. data/bin/jasmine-headless-webkit +2 -22
  5. data/jasmine-headless-webkit.gemspec +5 -4
  6. data/lib/digest/jasmine_test.rb +20 -0
  7. data/lib/jasmine/headless/cacheable_action.rb +1 -3
  8. data/lib/jasmine/headless/coffee_template.rb +30 -0
  9. data/lib/jasmine/headless/command_line.rb +31 -0
  10. data/lib/jasmine/headless/css_template.rb +14 -0
  11. data/lib/jasmine/headless/files_list.rb +251 -0
  12. data/lib/jasmine/headless/js_template.rb +18 -0
  13. data/lib/jasmine/headless/jst_template.rb +10 -0
  14. data/lib/jasmine/headless/options.rb +6 -1
  15. data/lib/jasmine/headless/runner.rb +14 -5
  16. data/lib/jasmine/headless/task.rb +2 -21
  17. data/lib/jasmine/headless/unique_asset_list.rb +14 -0
  18. data/lib/jasmine/headless/version.rb +1 -1
  19. data/lib/jasmine/headless.rb +11 -0
  20. data/lib/jasmine-headless-webkit.rb +4 -4
  21. data/skel/template.html.erb +13 -3
  22. data/spec/integration/randomization_spec.rb +13 -0
  23. data/spec/integration/specify_runner_file_spec.rb +22 -0
  24. data/spec/integration/sprockets_spec.rb +19 -0
  25. data/spec/jasmine/console_log/console_log.yml +1 -1
  26. data/spec/jasmine/runner_out_in_jasmine_yml/jasmine.yml +11 -0
  27. data/spec/jasmine/runner_out_in_jasmine_yml/test.js +2 -0
  28. data/spec/jasmine/runner_out_in_jasmine_yml/test_spec.coffee +4 -0
  29. data/spec/jasmine/with_sprockets_includes/assets/application.js.erb +2 -0
  30. data/spec/jasmine/with_sprockets_includes/assets/things/code.js +6 -0
  31. data/spec/jasmine/with_sprockets_includes/assets/things/required.js +2 -0
  32. data/spec/jasmine/with_sprockets_includes/assets/things/subcode/more_code.js +2 -0
  33. data/spec/jasmine/with_sprockets_includes/assets/things/templates/that.jst.ejs +1 -0
  34. data/spec/jasmine/with_sprockets_includes/assets/things/templates/this.jst +2 -0
  35. data/spec/jasmine/with_sprockets_includes/spec/spec_helper.js +1 -0
  36. data/spec/jasmine/with_sprockets_includes/spec/things/code_spec.js +9 -0
  37. data/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml +12 -0
  38. data/spec/javascripts/console.log_spec.coffee +15 -0
  39. data/spec/javascripts/support/jasmine.yml +4 -1
  40. data/spec/lib/jasmine/headless/cacheable_action_spec.rb +6 -3
  41. data/spec/lib/jasmine/headless/coffee_template_spec.rb +55 -0
  42. data/spec/lib/jasmine/headless/css_template_spec.rb +25 -0
  43. data/spec/lib/jasmine/headless/files_list_spec.rb +203 -0
  44. data/spec/lib/jasmine/headless/js_template_spec.rb +31 -0
  45. data/spec/lib/jasmine/headless/jst_template_spec.rb +21 -0
  46. data/spec/lib/jasmine/headless/options_spec.rb +18 -0
  47. data/spec/lib/jasmine/headless/template_writer_spec.rb +8 -4
  48. data/spec/lib/jasmine/headless/unique_asset_list_spec.rb +22 -0
  49. data/spec/lib/jasmine/headless_spec.rb +2 -0
  50. data/spec/spec_helper.rb +59 -0
  51. data/vendor/assets/coffeescripts/headless_reporter_result.coffee +10 -7
  52. data/vendor/assets/coffeescripts/intense.coffee +1 -0
  53. data/vendor/assets/coffeescripts/jasmine-extensions.coffee +13 -0
  54. data/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee +34 -2
  55. data/vendor/assets/coffeescripts/prolog.coffee +1 -1
  56. data/vendor/assets/javascripts/headless_reporter_result.js +19 -15
  57. data/vendor/assets/javascripts/intense.js +8 -1
  58. data/vendor/assets/javascripts/jasmine-extensions.js +29 -1
  59. data/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js +53 -13
  60. data/vendor/assets/javascripts/prolog.js +6 -4
  61. metadata +83 -20
  62. data/lib/jasmine/files_list.rb +0 -176
  63. data/spec/javascripts/support/jquery-1.6.2.min.js +0 -18
  64. data/spec/lib/jasmine/files_list_spec.rb +0 -248
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,35 @@
1
+ if ENV['COVERAGE']
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+ end
5
+
6
+ if ENV['PROFILE']
7
+ require 'perftools'
8
+ PerfTools::CpuProfiler.start("/tmp/jhw-profile")
9
+ end
10
+
1
11
  require 'jasmine-headless-webkit'
2
12
  require 'fakefs/spec_helpers'
3
13
 
4
14
  RSpec.configure do |c|
5
15
  c.mock_with :mocha
16
+ c.backtrace_clean_patterns = []
6
17
 
7
18
  c.before(:each) do
8
19
  Jasmine::Headless::CacheableAction.enabled = false
20
+ Jasmine::Headless::FilesList.reset!
21
+ end
22
+
23
+ c.before(:each, :type => :integration) do
24
+ let(:report) { 'spec/report.txt' }
25
+
26
+ before do
27
+ FileUtils.rm_f report
28
+ end
29
+
30
+ after do
31
+ FileUtils.rm_f report
32
+ end
9
33
  end
10
34
  end
11
35
 
@@ -17,6 +41,20 @@ if !File.file?(specrunner)
17
41
  end
18
42
  end
19
43
 
44
+ class FakeFS::File
45
+ class << self
46
+ def fnmatch?(pattern, file)
47
+ RealFile.fnmatch?(pattern, file)
48
+ end
49
+ end
50
+
51
+ class Stat
52
+ def file?
53
+ File.file?(@file)
54
+ end
55
+ end
56
+ end
57
+
20
58
  module RSpec::Matchers
21
59
  define :be_a_report_containing do |total, failed, used_console|
22
60
  match do |filename|
@@ -51,4 +89,25 @@ module RSpec::Matchers
51
89
  File.file?(file)
52
90
  end
53
91
  end
92
+
93
+ define :contain_in_order_in_file_list do |*files|
94
+ match do |lines|
95
+ file_list = files.dup
96
+
97
+ lines.each do |line|
98
+ next if !file_list.first
99
+
100
+ if line[file_list.first]
101
+ file_list.shift
102
+ end
103
+ end
104
+
105
+ file_list.length == 0
106
+ end
107
+
108
+ failure_message_for_should do |lines|
109
+ %{expected\n#{lines.join("\n")}\nto contain the following files, in order:\n#{files.join("\n")}}
110
+ end
111
+ end
54
112
  end
113
+
@@ -6,20 +6,21 @@ class window.HeadlessReporterResult
6
6
  addResult: (message) ->
7
7
  @results.push(message)
8
8
 
9
- print: ->
10
- output = @name.foreground('red')
9
+ toString: ->
10
+ output = "\n" + @name.foreground('red')
11
11
  bestChoice = HeadlessReporterResult.findSpecLine(@splitName)
12
12
  output += " (#{bestChoice.file}:#{bestChoice.lineNumber})".foreground('blue') if bestChoice.file
13
13
 
14
- JHW.stdout.puts "\n\n#{output}"
15
14
  for result in @results
16
- output = result.message.foreground('red')
15
+ line = result.message.foreground('red')
17
16
  if result.lineNumber
18
- output += " (line ~#{bestChoice.lineNumber + result.lineNumber})".foreground('red').bright()
19
- JHW.stdout.puts(" " + output)
17
+ line += " (line ~#{bestChoice.lineNumber + result.lineNumber})".foreground('red').bright()
18
+ output += "\n #{line}"
20
19
 
21
20
  if result.line?
22
- JHW.stdout.puts(" #{result.line}".foreground('yellow'))
21
+ output += "\n #{result.line}".foreground('yellow')
22
+
23
+ output
23
24
 
24
25
  @findSpecLine: (splitName) ->
25
26
  bestChoice = { accuracy: 0, file: null, lineNumber: null }
@@ -43,4 +44,6 @@ class window.HeadlessReporterResult
43
44
  if index > bestChoice.accuracy
44
45
  bestChoice = { accuracy: index, file: file, lineNumber: lineNumber }
45
46
 
47
+ break if index == splitName.length
48
+
46
49
  bestChoice
@@ -20,6 +20,7 @@ window.Intense = {
20
20
  else
21
21
  this
22
22
  useColors: true
23
+ moveBack: (count = 1) -> "\033[#{count}D"
23
24
  }
24
25
 
25
26
  for method, code of Intense.methods
@@ -73,7 +73,10 @@ if window.JHW
73
73
 
74
74
  pauseAndRun = (onComplete) ->
75
75
  JHW.timerPause()
76
+ jasmine.getEnv().reporter.reportSpecWaiting()
77
+
76
78
  this._execute ->
79
+ jasmine.getEnv().reporter.reportSpecRunning()
77
80
  JHW.timerDone()
78
81
  onComplete()
79
82
 
@@ -88,3 +91,13 @@ if window.JHW
88
91
  result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString())
89
92
 
90
93
  this.addResult_(result)
94
+
95
+ for method in [ "reportSpecWaiting", "reportSpecRunning" ]
96
+ generator = (method) ->
97
+ (args...) ->
98
+ for reporter in @subReporters_
99
+ if reporter[method]?
100
+ reporter[method](args...)
101
+
102
+ jasmine.MultiReporter.prototype[method] = generator(method)
103
+
@@ -6,6 +6,9 @@ class jasmine.HeadlessConsoleReporter
6
6
  @results = []
7
7
  @failedCount = 0
8
8
  @length = 0
9
+ @timer = null
10
+ @position = 0
11
+ @positions = "|/-\\"
9
12
 
10
13
  reportRunnerResults: (runner) ->
11
14
  return if this.hasError()
@@ -25,7 +28,9 @@ class jasmine.HeadlessConsoleReporter
25
28
  output = "TOTAL||#{@length}||#{@failedCount}||#{runtime}||#{if JHW._hasErrors then "T" else "F"}"
26
29
 
27
30
  JHW.report.puts(output)
28
- result.print() for result in @results
31
+
32
+ for result in @results
33
+ JHW.stdout.puts(result.toString())
29
34
 
30
35
  if window.JHW
31
36
  window.onbeforeunload = null
@@ -34,7 +39,7 @@ class jasmine.HeadlessConsoleReporter
34
39
 
35
40
  reportRunnerStarting: (runner) ->
36
41
  @startTime = new Date()
37
- JHW.stdout.puts("\nRunning Jasmine specs...".bright())
42
+ JHW.stdout.puts("\nRunning Jasmine specs...".bright()) if !this.hasError()
38
43
 
39
44
  reportSpecResults: (spec) ->
40
45
  return if this.hasError()
@@ -67,6 +72,33 @@ class jasmine.HeadlessConsoleReporter
67
72
  spec.finish()
68
73
  spec.suite.finish()
69
74
 
75
+ reportSpecWaiting: ->
76
+ runner = null
77
+
78
+ if !@timer
79
+ @timer = true
80
+ first = true
81
+
82
+ runner = =>
83
+ @timer = setTimeout(
84
+ =>
85
+ if @timer
86
+ JHW.stdout.print(Intense.moveBack()) if !first
87
+ JHW.stdout.print(@positions.substr(@position, 1).foreground('yellow'))
88
+ @position += 1
89
+ @position %= @positions.length
90
+ first = false
91
+ runner()
92
+ , 750
93
+ )
94
+ runner()
95
+
96
+ reportSpecRunning: ->
97
+ if @timer
98
+ clearTimeout(@timer)
99
+ @timer = null
100
+ JHW.stdout.print(Intense.moveBack())
101
+
70
102
  reportSuiteResults: (suite) ->
71
103
  hasError: ->
72
104
  JHW._hasErrors
@@ -2,7 +2,7 @@ if window.JHW
2
2
  window.console =
3
3
  log: (data) ->
4
4
  if typeof(jQuery) != 'undefined' && data instanceof jQuery
5
- JHW.log(style_html($("<div />").append(data).html(), { indent_size: 2 }))
5
+ JHW.log(style_html($("<div />").append(data.clone()).html(), { indent_size: 2 }))
6
6
  else
7
7
  useJsDump = true
8
8
 
@@ -1,34 +1,38 @@
1
- (function() {
1
+
2
2
  window.HeadlessReporterResult = (function() {
3
+
3
4
  function HeadlessReporterResult(name, splitName) {
4
5
  this.name = name;
5
6
  this.splitName = splitName;
6
7
  this.results = [];
7
8
  }
9
+
8
10
  HeadlessReporterResult.prototype.addResult = function(message) {
9
11
  return this.results.push(message);
10
12
  };
11
- HeadlessReporterResult.prototype.print = function() {
12
- var bestChoice, output, result, _i, _len, _ref, _results;
13
- output = this.name.foreground('red');
13
+
14
+ HeadlessReporterResult.prototype.toString = function() {
15
+ var bestChoice, line, output, result, _i, _len, _ref;
16
+ output = "\n" + this.name.foreground('red');
14
17
  bestChoice = HeadlessReporterResult.findSpecLine(this.splitName);
15
18
  if (bestChoice.file) {
16
19
  output += (" (" + bestChoice.file + ":" + bestChoice.lineNumber + ")").foreground('blue');
17
20
  }
18
- JHW.stdout.puts("\n\n" + output);
19
21
  _ref = this.results;
20
- _results = [];
21
22
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
22
23
  result = _ref[_i];
23
- output = result.message.foreground('red');
24
+ line = result.message.foreground('red');
24
25
  if (result.lineNumber) {
25
- output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright();
26
+ line += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright();
27
+ }
28
+ output += "\n " + line;
29
+ if (result.line != null) {
30
+ output += ("\n " + result.line).foreground('yellow');
26
31
  }
27
- JHW.stdout.puts(" " + output);
28
- _results.push(result.line != null ? JHW.stdout.puts((" " + result.line).foreground('yellow')) : void 0);
29
32
  }
30
- return _results;
33
+ return output;
31
34
  };
35
+
32
36
  HeadlessReporterResult.findSpecLine = function(splitName) {
33
37
  var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref;
34
38
  bestChoice = {
@@ -49,9 +53,7 @@
49
53
  for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) {
50
54
  line = newLineNumberInfo[_i];
51
55
  lastLine = line;
52
- if (line > lineNumber) {
53
- break;
54
- }
56
+ if (line > lineNumber) break;
55
57
  }
56
58
  lineNumber = lastLine;
57
59
  }
@@ -64,9 +66,11 @@
64
66
  lineNumber: lineNumber
65
67
  };
66
68
  }
69
+ if (index === splitName.length) break;
67
70
  }
68
71
  return bestChoice;
69
72
  };
73
+
70
74
  return HeadlessReporterResult;
75
+
71
76
  })();
72
- }).call(this);
@@ -1,5 +1,6 @@
1
1
  (function() {
2
2
  var code, method, _ref;
3
+
3
4
  window.Intense = {
4
5
  colors: {
5
6
  black: 0,
@@ -27,11 +28,17 @@
27
28
  }
28
29
  }
29
30
  },
30
- useColors: true
31
+ useColors: true,
32
+ moveBack: function(count) {
33
+ if (count == null) count = 1;
34
+ return "\033[" + count + "D";
35
+ }
31
36
  };
37
+
32
38
  _ref = Intense.methods;
33
39
  for (method in _ref) {
34
40
  code = _ref[method];
35
41
  String.prototype[method] = code;
36
42
  }
43
+
37
44
  }).call(this);
@@ -1,8 +1,11 @@
1
1
  (function() {
2
- var getSplitName, pauseAndRun;
2
+ var generator, getSplitName, method, pauseAndRun, _i, _len, _ref;
3
+ var __slice = Array.prototype.slice;
4
+
3
5
  if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
4
6
  throw new Error("jasmine not laoded!");
5
7
  }
8
+
6
9
  if (window.JHW) {
7
10
  getSplitName = function(parts) {
8
11
  parts.push(String(this.description).replace(/[\n\r]/g, ' '));
@@ -83,7 +86,9 @@
83
86
  jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute;
84
87
  pauseAndRun = function(onComplete) {
85
88
  JHW.timerPause();
89
+ jasmine.getEnv().reporter.reportSpecWaiting();
86
90
  return this._execute(function() {
91
+ jasmine.getEnv().reporter.reportSpecRunning();
87
92
  JHW.timerDone();
88
93
  return onComplete();
89
94
  });
@@ -96,6 +101,29 @@
96
101
  result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString());
97
102
  return this.addResult_(result);
98
103
  };
104
+ _ref = ["reportSpecWaiting", "reportSpecRunning"];
105
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
106
+ method = _ref[_i];
107
+ generator = function(method) {
108
+ return function() {
109
+ var args, reporter, _j, _len2, _ref2, _results;
110
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
111
+ _ref2 = this.subReporters_;
112
+ _results = [];
113
+ for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
114
+ reporter = _ref2[_j];
115
+ if (reporter[method] != null) {
116
+ _results.push(reporter[method].apply(reporter, args));
117
+ } else {
118
+ _results.push(void 0);
119
+ }
120
+ }
121
+ return _results;
122
+ };
123
+ };
124
+ jasmine.MultiReporter.prototype[method] = generator(method);
125
+ }
99
126
  }
100
127
  }
128
+
101
129
  }).call(this);
@@ -1,19 +1,23 @@
1
- (function() {
1
+
2
2
  if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
3
3
  throw new Error("jasmine not loaded!");
4
4
  }
5
+
5
6
  jasmine.HeadlessConsoleReporter = (function() {
7
+
6
8
  function HeadlessConsoleReporter(callback) {
7
9
  this.callback = callback != null ? callback : null;
8
10
  this.results = [];
9
11
  this.failedCount = 0;
10
12
  this.length = 0;
13
+ this.timer = null;
14
+ this.position = 0;
15
+ this.positions = "|/-\\";
11
16
  }
17
+
12
18
  HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) {
13
19
  var output, result, resultLine, runtime, _i, _len, _ref;
14
- if (this.hasError()) {
15
- return;
16
- }
20
+ if (this.hasError()) return;
17
21
  runtime = (new Date() - this.startTime) / 1000.0;
18
22
  JHW.stdout.print("\n");
19
23
  resultLine = this._formatResultLine(runtime);
@@ -28,22 +32,22 @@
28
32
  _ref = this.results;
29
33
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
30
34
  result = _ref[_i];
31
- result.print();
32
- }
33
- if (window.JHW) {
34
- window.onbeforeunload = null;
35
+ JHW.stdout.puts(result.toString());
35
36
  }
37
+ if (window.JHW) window.onbeforeunload = null;
36
38
  return JHW.finishSuite();
37
39
  };
40
+
38
41
  HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) {
39
42
  this.startTime = new Date();
40
- return JHW.stdout.puts("\nRunning Jasmine specs...".bright());
43
+ if (!this.hasError()) {
44
+ return JHW.stdout.puts("\nRunning Jasmine specs...".bright());
45
+ }
41
46
  };
47
+
42
48
  HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) {
43
49
  var failureResult, foundLine, result, results, testCount, _i, _len, _ref;
44
- if (this.hasError()) {
45
- return;
46
- }
50
+ if (this.hasError()) return;
47
51
  JHW.ping();
48
52
  results = spec.results();
49
53
  this.length++;
@@ -70,16 +74,51 @@
70
74
  return this.results.push(failureResult);
71
75
  }
72
76
  };
77
+
73
78
  HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) {
74
79
  if (this.hasError()) {
75
80
  spec.finish();
76
81
  return spec.suite.finish();
77
82
  }
78
83
  };
84
+
85
+ HeadlessConsoleReporter.prototype.reportSpecWaiting = function() {
86
+ var first, runner;
87
+ var _this = this;
88
+ runner = null;
89
+ if (!this.timer) {
90
+ this.timer = true;
91
+ first = true;
92
+ runner = function() {
93
+ return _this.timer = setTimeout(function() {
94
+ if (_this.timer) {
95
+ if (!first) JHW.stdout.print(Intense.moveBack());
96
+ JHW.stdout.print(_this.positions.substr(_this.position, 1).foreground('yellow'));
97
+ _this.position += 1;
98
+ _this.position %= _this.positions.length;
99
+ first = false;
100
+ return runner();
101
+ }
102
+ }, 750);
103
+ };
104
+ return runner();
105
+ }
106
+ };
107
+
108
+ HeadlessConsoleReporter.prototype.reportSpecRunning = function() {
109
+ if (this.timer) {
110
+ clearTimeout(this.timer);
111
+ this.timer = null;
112
+ return JHW.stdout.print(Intense.moveBack());
113
+ }
114
+ };
115
+
79
116
  HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {};
117
+
80
118
  HeadlessConsoleReporter.prototype.hasError = function() {
81
119
  return JHW._hasErrors;
82
120
  };
121
+
83
122
  HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) {
84
123
  var line;
85
124
  line = [];
@@ -91,6 +130,7 @@
91
130
  line.push((runtime === 1.0 ? "sec" : "secs") + '.');
92
131
  return line.join(' ');
93
132
  };
133
+
94
134
  return HeadlessConsoleReporter;
135
+
95
136
  })();
96
- }).call(this);
@@ -1,11 +1,12 @@
1
1
  (function() {
2
2
  var createHandle, handle, _i, _len, _ref;
3
+
3
4
  if (window.JHW) {
4
5
  window.console = {
5
6
  log: function(data) {
6
7
  var dump, useJsDump;
7
8
  if (typeof jQuery !== 'undefined' && data instanceof jQuery) {
8
- return JHW.log(style_html($("<div />").append(data).html(), {
9
+ return JHW.log(style_html($("<div />").append(data.clone()).html(), {
9
10
  indent_size: 2
10
11
  }));
11
12
  } else {
@@ -40,9 +41,7 @@
40
41
  e = e || window.event;
41
42
  JHW.hasError();
42
43
  JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.');
43
- if (e) {
44
- e.returnValue = 'string';
45
- }
44
+ if (e) e.returnValue = 'string';
46
45
  return 'string';
47
46
  };
48
47
  window.confirm = function(message) {
@@ -84,6 +83,9 @@
84
83
  return JHW.stdout.puts(msg);
85
84
  };
86
85
  }
86
+
87
87
  window.CoffeeScriptToFilename = {};
88
+
88
89
  window.CSTF = window.CoffeeScriptToFilename;
90
+
89
91
  }).call(this);