jasmine-headless-webkit 0.1.0 → 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.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 0.2.0
2
+
3
+ * Add a Rake task and a default task for Rails
4
+ * Global runner configuration via ~/.jasmine-headless-webkit
5
+ * Custom Jasmine reporter for better user feedback
6
+ * Specify the specs to be run, instead of always running them all
7
+ * Move README to gh-pages site
8
+
data/README.md CHANGED
@@ -2,98 +2,8 @@
2
2
 
3
3
  Run your specs at sonic boom speed! No pesky reload button or page rendering slowdowns!
4
4
 
5
- ## Introduction
6
-
7
- This gem works with projects that have used the [Jasmine gem](https://github.com/pivotal/jasmine-gem) to
8
- create a `jasmine.yml` file that defines what to test. The runner loads that
9
- `jasmine.yml` file and executes the tests defined within in a Qt WebKit widget, displaying the results
10
- to the console and setting the exit code to one of the following:
11
-
12
- * 0 for success
13
- * 1 for spec run failure
14
- * 2 for spec run success, but `console.log` was called during the run
15
-
16
- `console.log` works, too, so you can run your specs side-by-side in a browser if you're so inclined. It
17
- serializes whatever you're passing in as as JSON string, so objects that are cyclical in nature will not
18
- serialize. If anyone has a good solution for this, please suggest and/or fork'n'fix.
19
-
20
- ## Installation
21
-
22
- `gem install jasmine-headless-webkit` or use Bundler.
23
-
24
- Installation requires Qt 4.7. See [senchalabs/examples](https://github.com/senchalabs/examples) and [my fork
25
- of examples](https://github.com/johnbintz/examples) for more information on the QtWebKit runner.
26
-
27
- Tested in the following environments:
28
-
29
- * Mac OS X 10.6, with MacPorts Qt and Nokia Qt.mpkg
30
- * Kubuntu 10.10
31
-
32
- Let me know via a message or in the Issues section if it works on your setup and it's not listed!
33
-
34
- ## Usage
35
-
36
- jasmine-headless-webkit [options] [path to jasmine.yml, defaults to spec/javascripts/support/jasmine.yml]
37
-
38
- Current supported options:
39
-
40
- * `-c`/`--colors` enables color output
41
- * `--no-colors` disables color output
42
- * `--keep` preserves the temporary HTML document if an error occurs in testing
43
-
44
- These options can also be placed into a `.jasmine-headless-webkit` file in your project root.
45
-
46
- ### CoffeeScript Support
47
-
48
- `jasmine-headless-webkit` brings in the `coffee-script` gem and compiles & injects all CoffeeScript into the
49
- generated HTML page. All you need to do is configure your `jasmine.yml` file to look for .coffee files:
50
-
51
- src_files:
52
- - app/assets/javascripts/**/*.coffee
53
- spec_files:
54
- - **/*[sS]pec.coffee
55
-
56
- *(This will probably make it difficult to test your code in an official Jasmine server for now. You can try
57
- [a technique like this](https://github.com/jbaudanza/rack-asset-compiler/blob/master/examples/jasmine_config.rb) for compiling CoffeeScript when it's requested from the server
58
- or use [this fork of jasmine-gem](https://github.com/johnbintz/jasmine-gem/tree/coffeescript-inline-support) which
59
- is thoroughly untested.)*
60
-
61
- You will get line numbers on compile errors, but not logic errors. This is a CoffeeScript thing, and they're working on it. :)
62
-
63
- ### JavaScript Dialogs
64
-
65
- You can call `alert()` and `confirm()` in your code. `alert()` will print the message to the console, and
66
- `confirm()` will always return true. There's no way right now to respond to `confirm()`, so it's best to
67
- mock that call:
68
-
69
- spyOn(window, 'confirm').andReturn(false);
70
-
71
- ### Autotest Integration
72
-
73
- `jasmine-headless-webkit` can integrate with Autotest. Your `jasmine.yml` file needs to be in the default
74
- path, and you have to be ready to use a very alpha implementation of the feature. If used with RSpec 2,
75
- Jasmine tests run after RSpec tests.
76
-
77
- You need to create a `.jasmine-headless-webkit` file in your project root for this integration
78
- to work.
79
-
80
- `jasmine-headless-webkit` provides two new hooks: `:run_jasmine` and `:ran_jasmine` for before and after the
81
- Jasmine specs have run. This is a good place to do things like re-package all your assets using
82
- [Jammit](http://documentcloud.github.com/jammit/):
83
-
84
- Autotest.add_hook(:run_jasmine) do |at|
85
- system %{jammit}
86
- end
87
-
88
- ### Server Interaction
89
-
90
- `jasmine-headless-webkit` works the same as if you create an HTML file, manually load the Jasmine library and
91
- your code & tests into the page, and open that page in a browser. Because of this, there's no way to handle
92
- server interaction with your application or with a Jasmine server. If you need to test server interaction,
93
- do one of the following:
94
-
95
- * Stub your server responses using [Sinon.JS](http://sinonjs.org/)
96
- * Use [PhantomJS](http://www.phantomjs.org/) against a running copy of a Jasmine server, instead of this project
5
+ http://johnbintz.github.com/jasmine-headless-webkit/ has the most up-to-date information on using
6
+ this project. You can see the source of that site on the gh-pages branch.
97
7
 
98
8
  ## License
99
9
 
@@ -9,10 +9,6 @@ require 'yaml'
9
9
  require 'fileutils'
10
10
  require 'getoptlong'
11
11
 
12
- gem 'jasmine'
13
- gem 'coffee-script'
14
- gem 'rainbow'
15
-
16
12
  require 'jasmine'
17
13
  require 'coffee-script'
18
14
  require 'rainbow'
@@ -20,16 +16,27 @@ require 'rainbow'
20
16
  require 'jasmine/cli'
21
17
  include Jasmine::CLI
22
18
 
19
+ if !File.file?(File.join(gem_dir, RUNNER))
20
+ puts "The Qt WebKit widget is not compiled! Try re-installing this gem."
21
+ exit 1
22
+ end
23
+
23
24
  opts = GetoptLong.new(
24
25
  [ '--colors', '-c', GetoptLong::NO_ARGUMENT ],
25
26
  [ '--no-colors', GetoptLong::NO_ARGUMENT ],
26
- [ '--keep', GetoptLong::NO_ARGUMENT ]
27
+ [ '--keep', GetoptLong::NO_ARGUMENT ],
28
+ [ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ]
27
29
  )
28
30
 
29
- options = { :colors => false, :remove_html_file => true }
31
+ options = {
32
+ :colors => false,
33
+ :remove_html_file => true,
34
+ :jasmine_config => 'spec/javascripts/support/jasmine.yml'
35
+ }
30
36
 
31
37
  @process_options = lambda { |*args|
32
- opt = args.flatten.shift
38
+ opt, arg = args.flatten[0..1]
39
+
33
40
  case opt
34
41
  when '--colors', '-c'
35
42
  options[:colors] = true
@@ -37,37 +44,39 @@ options = { :colors => false, :remove_html_file => true }
37
44
  options[:colors] = false
38
45
  when '--keep', '-k'
39
46
  options[:remove_html_file] = false
47
+ when '--jasmine-config', '-j'
48
+ options[:jasmine_config] = arg
40
49
  end
41
50
  }
42
51
 
43
- read_defaults_file if defaults_file?
52
+ read_defaults_files!
44
53
  opts.each(&@process_options)
54
+ @spec_filter = ARGV.dup
45
55
 
46
- data = YAML.load_file(ARGV.shift || 'spec/javascripts/support/jasmine.yml')
47
-
48
- if !File.file?(File.join(gem_dir, RUNNER))
49
- puts "The Qt WebKit widget is not compiled! Try re-installing this gem."
50
- exit 1
51
- end
56
+ data = YAML.load_file(options[:jasmine_config])
52
57
 
53
58
  puts "Running Jasmine specs..."
54
59
 
55
60
  files = %w{jasmine jasmine-html}.collect { |name| File.join(Jasmine.root, "lib/#{name}.js") }
61
+ files << File.join(gem_dir, 'jasmine/jasmine.headless-reporter.js')
56
62
 
57
- files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].collect do |searches, root|
58
- data[searches] ||= DEFAULTS[searches]
59
- data[root] ||= DEFAULTS[root]
63
+ [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].each do |searches, root|
64
+ if data[searches] ||= DEFAULTS[searches]
65
+ data[root] ||= DEFAULTS[root]
60
66
 
61
- if data[searches]
62
67
  data[searches].collect do |search|
63
68
  path = search
64
69
  path = File.join(data[root], path) if data[root]
65
- Dir[path]
70
+ found_files = Dir[path]
71
+ if searches == 'spec_files'
72
+ found_files = found_files.find_all { |file| use_spec?(file) }
73
+ end
74
+ files += found_files
66
75
  end
67
76
  end
68
77
  end
69
78
 
70
- files = files.flatten.compact.collect { |file|
79
+ files = files.collect { |file|
71
80
  case File.extname(file)
72
81
  when '.js'
73
82
  %{<script type="text/javascript" src="#{file}"></script>}
@@ -75,7 +84,7 @@ files = files.flatten.compact.collect { |file|
75
84
  begin
76
85
  %{<script type="text/javascript">#{CoffeeScript.compile(fh = File.open(file))}</script>}
77
86
  rescue CoffeeScript::CompilationError => e
78
- puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), e.message.color(:white) ]
87
+ puts "[%s] %s: %s" % [ 'coffeescript'.color(:red), file.color(:yellow), e.message.to_s.color(:white) ]
79
88
  exit 1
80
89
  ensure
81
90
  fh.close
data/coffee.watchr ADDED
@@ -0,0 +1,18 @@
1
+ require 'coffee-script'
2
+
3
+ FILE = 'jasmine/jasmine.headless-reporter.coffee' if !self.class.const_defined?(:FILE)
4
+ TARGET = FILE.gsub('.coffee', '.js') if !self.class.const_defined?(:TARGET)
5
+
6
+ watch(FILE) { coffee }
7
+
8
+ def coffee
9
+ begin
10
+ File.open(TARGET, 'w') { |fh| fh.print CoffeeScript.compile File.open(FILE) }
11
+ puts "Wrote #{TARGET}"
12
+ rescue Exception => e
13
+ puts e.message
14
+ end
15
+ end
16
+
17
+ coffee
18
+
@@ -66,7 +66,11 @@ public:
66
66
  void setColors(bool colors);
67
67
  public slots:
68
68
  void log(const QString &msg);
69
- void specLog(int indent, const QString &msg, const QString &clazz);
69
+ void specPassed();
70
+ void specFailed();
71
+ void printName(const QString &name);
72
+ void printResult(const QString &result);
73
+ void finishSuite(const QString &duration, const QString &total, const QString& failed);
70
74
  private slots:
71
75
  void watch(bool ok);
72
76
  void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
@@ -81,6 +85,9 @@ private:
81
85
  bool hasErrors;
82
86
  bool usedConsole;
83
87
  bool showColors;
88
+ bool isFinished;
89
+ bool didFail;
90
+ bool consoleNotUsedThisRun;
84
91
 
85
92
  void red();
86
93
  void green();
@@ -94,6 +101,9 @@ HeadlessSpecRunner::HeadlessSpecRunner()
94
101
  , hasErrors(false)
95
102
  , usedConsole(false)
96
103
  , showColors(false)
104
+ , isFinished(false)
105
+ , didFail(false)
106
+ , consoleNotUsedThisRun(false)
97
107
  {
98
108
  m_page.settings()->enablePersistentStorage();
99
109
  connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
@@ -104,7 +114,7 @@ HeadlessSpecRunner::HeadlessSpecRunner()
104
114
  void HeadlessSpecRunner::load(const QString &spec)
105
115
  {
106
116
  m_ticker.stop();
107
- m_page.mainFrame()->addToJavaScriptWindowObject("debug", this);
117
+ m_page.mainFrame()->addToJavaScriptWindowObject("JHW", this);
108
118
  m_page.mainFrame()->load(spec);
109
119
  m_page.setPreferredContentsSize(QSize(1024, 600));
110
120
  }
@@ -152,6 +162,25 @@ void HeadlessSpecRunner::clear()
152
162
  if (showColors) std::cout << "\033[m";
153
163
  }
154
164
 
165
+ void HeadlessSpecRunner::specPassed()
166
+ {
167
+ consoleNotUsedThisRun = true;
168
+ green();
169
+ std::cout << '.';
170
+ clear();
171
+ fflush(stdout);
172
+ }
173
+
174
+ void HeadlessSpecRunner::specFailed()
175
+ {
176
+ consoleNotUsedThisRun = true;
177
+ didFail = true;
178
+ red();
179
+ std::cout << 'F';
180
+ clear();
181
+ fflush(stdout);
182
+ }
183
+
155
184
  void HeadlessSpecRunner::errorLog(const QString &msg, int lineNumber, const QString &sourceID)
156
185
  {
157
186
  red();
@@ -177,39 +206,48 @@ void HeadlessSpecRunner::log(const QString &msg)
177
206
  {
178
207
  usedConsole = true;
179
208
  green();
209
+ if (consoleNotUsedThisRun) {
210
+ std::cout << std::endl;
211
+ consoleNotUsedThisRun = false;
212
+ }
180
213
  std::cout << "[console] ";
181
214
  clear();
182
215
  std::cout << qPrintable(msg);
183
216
  std::cout << std::endl;
184
217
  }
185
218
 
186
- void HeadlessSpecRunner::specLog(int indent, const QString &msg, const QString &clazz)
219
+ void HeadlessSpecRunner::printName(const QString &name)
187
220
  {
188
- for (int i = 0; i < indent; ++i)
189
- std::cout << " ";
190
- if ( clazz.endsWith("fail") ) {
191
- red();
192
- } else {
193
- yellow();
194
- }
195
- std::cout << qPrintable(msg);
196
- clear();
197
- std::cout << std::endl;
221
+ std::cout << std::endl << std::endl;
222
+ red();
223
+ std::cout << qPrintable(name) << std::endl;
224
+ clear();
198
225
  }
199
226
 
200
- #define DUMP_MSG "(function(n, i) { \
201
- if (n.toString() === '[object NodeList]') { \
202
- for (var c = 0; c < n.length; ++c) arguments.callee(n[c], i); return \
203
- }\
204
- if (n.className === 'description' || n.className == 'resultMessage fail') {\
205
- debug.specLog(i, n.textContent, n.className);\
206
- }\
207
- var e = n.firstElementChild;\
208
- while (e) {\
209
- arguments.callee(e, i + 1); e = e.nextElementSibling; \
210
- }\
211
- n.className = '';\
212
- })(document.getElementsByClassName('suite failed'), 0);"
227
+ void HeadlessSpecRunner::printResult(const QString &result)
228
+ {
229
+ red();
230
+ std::cout << " " << qPrintable(result) << std::endl;
231
+ clear();
232
+ }
233
+
234
+ void HeadlessSpecRunner::finishSuite(const QString &duration, const QString &total, const QString& failed)
235
+ {
236
+ std::cout << std::endl;
237
+ if (didFail) {
238
+ red();
239
+ std::cout << "FAIL: ";
240
+ } else {
241
+ green();
242
+ std::cout << "PASS: ";
243
+ }
244
+
245
+ std::cout << qPrintable(total) << " tests, " << qPrintable(failed) << " failures, " << qPrintable(duration) << " secs.";
246
+ clear();
247
+ std::cout << std::endl;
248
+
249
+ isFinished = true;
250
+ }
213
251
 
214
252
  void HeadlessSpecRunner::timerEvent(QTimerEvent *event)
215
253
  {
@@ -222,28 +260,17 @@ void HeadlessSpecRunner::timerEvent(QTimerEvent *event)
222
260
  QApplication::instance()->exit(1);
223
261
 
224
262
  if (!hasErrors) {
225
- if (!hasElement(".jasmine_reporter") && !hasElement(".runner.running"))
226
- return;
227
-
228
- if (hasElement(".runner.passed")) {
229
- QWebElement desc = m_page.mainFrame()->findFirstElement(".description");
230
- green();
231
- std::cout << "PASS: " << qPrintable(desc.toPlainText());
232
- clear();
233
- std::cout << std::endl;
234
- QApplication::instance()->exit(usedConsole ? 2 : 0);
235
- return;
236
- }
237
-
238
- if (hasElement(".runner.failed")) {
239
- QWebElement desc = m_page.mainFrame()->findFirstElement(".description");
240
- red();
241
- std::cout << "FAIL: " << qPrintable(desc.toPlainText());
242
- clear();
243
- std::cout << std::endl;
244
- m_page.mainFrame()->evaluateJavaScript(DUMP_MSG);
245
- QApplication::instance()->exit(1);
246
- return;
263
+ if (isFinished) {
264
+ int exitCode = 0;
265
+ if (didFail) {
266
+ exitCode = 1;
267
+ } else {
268
+ if (usedConsole) {
269
+ exitCode = 2;
270
+ }
271
+ }
272
+
273
+ QApplication::instance()->exit(exitCode);
247
274
  }
248
275
 
249
276
  if (m_runs > 30) {
@@ -0,0 +1,44 @@
1
+ if !jasmine?
2
+ throw new Exception("jasmine not laoded!")
3
+
4
+ class HeadlessReporterResult
5
+ constructor: (name) ->
6
+ @name = name
7
+ @results = []
8
+ addResult: (message) ->
9
+ @results.push(message)
10
+ print: ->
11
+ JHW.printName(@name)
12
+ for result in @results
13
+ do (result) =>
14
+ JHW.printResult(result)
15
+
16
+ class jasmine.HeadlessReporter
17
+ constructor: ->
18
+ @results = []
19
+ @failedCount = 0
20
+ @length = 0
21
+ reportRunnerResults: (runner) ->
22
+ for result in @results
23
+ do (result) =>
24
+ result.print()
25
+
26
+ JHW.finishSuite((new Date() - @startTime) / 1000.0, @length, @failedCount)
27
+ reportRunnerStarting: (runner) ->
28
+ @startTime = new Date()
29
+ reportSpecResults: (spec) ->
30
+ results = spec.results()
31
+ if results.passed()
32
+ JHW.specPassed()
33
+ else
34
+ JHW.specFailed()
35
+ failureResult = new HeadlessReporterResult(spec.getFullName())
36
+ for result in results.getItems()
37
+ do (result) =>
38
+ if result.type == 'expect' and !result.passed_
39
+ @failedCount += 1
40
+ failureResult.addResult(result.message)
41
+ @results.push(failureResult)
42
+ reportSpecStarting: (spec) ->
43
+ reportSuiteResults: (suite) ->
44
+ @length += suite.specs().length
@@ -0,0 +1,79 @@
1
+ (function() {
2
+ var HeadlessReporterResult;
3
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
4
+ if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
5
+ throw new Exception("jasmine not laoded!");
6
+ }
7
+ HeadlessReporterResult = (function() {
8
+ function HeadlessReporterResult(name) {
9
+ this.name = name;
10
+ this.results = [];
11
+ }
12
+ HeadlessReporterResult.prototype.addResult = function(message) {
13
+ return this.results.push(message);
14
+ };
15
+ HeadlessReporterResult.prototype.print = function() {
16
+ var result, _i, _len, _ref, _results;
17
+ JHW.printName(this.name);
18
+ _ref = this.results;
19
+ _results = [];
20
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
21
+ result = _ref[_i];
22
+ _results.push(__bind(function(result) {
23
+ return JHW.printResult(result);
24
+ }, this)(result));
25
+ }
26
+ return _results;
27
+ };
28
+ return HeadlessReporterResult;
29
+ })();
30
+ jasmine.HeadlessReporter = (function() {
31
+ function HeadlessReporter() {
32
+ this.results = [];
33
+ this.failedCount = 0;
34
+ this.length = 0;
35
+ }
36
+ HeadlessReporter.prototype.reportRunnerResults = function(runner) {
37
+ var result, _fn, _i, _len, _ref;
38
+ _ref = this.results;
39
+ _fn = __bind(function(result) {
40
+ return result.print();
41
+ }, this);
42
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
43
+ result = _ref[_i];
44
+ _fn(result);
45
+ }
46
+ return JHW.finishSuite((new Date() - this.startTime) / 1000.0, this.length, this.failedCount);
47
+ };
48
+ HeadlessReporter.prototype.reportRunnerStarting = function(runner) {
49
+ return this.startTime = new Date();
50
+ };
51
+ HeadlessReporter.prototype.reportSpecResults = function(spec) {
52
+ var failureResult, result, results, _fn, _i, _len, _ref;
53
+ results = spec.results();
54
+ if (results.passed()) {
55
+ return JHW.specPassed();
56
+ } else {
57
+ JHW.specFailed();
58
+ failureResult = new HeadlessReporterResult(spec.getFullName());
59
+ _ref = results.getItems();
60
+ _fn = __bind(function(result) {
61
+ if (result.type === 'expect' && !result.passed_) {
62
+ this.failedCount += 1;
63
+ return failureResult.addResult(result.message);
64
+ }
65
+ }, this);
66
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
67
+ result = _ref[_i];
68
+ _fn(result);
69
+ }
70
+ return this.results.push(failureResult);
71
+ }
72
+ };
73
+ HeadlessReporter.prototype.reportSpecStarting = function(spec) {};
74
+ HeadlessReporter.prototype.reportSuiteResults = function(suite) {
75
+ return this.length += suite.specs().length;
76
+ };
77
+ return HeadlessReporter;
78
+ })();
79
+ }).call(this);
@@ -87,7 +87,8 @@ module JasmineMixin
87
87
  end
88
88
 
89
89
  def make_jasmine_cmd
90
- "#{JASMINE_PROGRAM}"
90
+ self.files_to_test.empty? ? '' :
91
+ %{#{JASMINE_PROGRAM} #{self.files_to_test.keys.collect { |key| %{'#{key}'} }.join(' ')}}.tap { |o| p o }
91
92
  end
92
93
 
93
94
  def setup_jasmine_project_mappings
data/lib/jasmine/cli.rb CHANGED
@@ -11,17 +11,22 @@ module Jasmine
11
11
 
12
12
  RUNNER = 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'
13
13
  DEFAULTS_FILE = '.jasmine-headless-webkit'
14
+ GLOBAL_DEFAULTS_FILE = File.expand_path("~/#{DEFAULTS_FILE}")
14
15
 
15
16
  def process_jasmine_config(overrides = {})
16
17
  DEFAULTS.merge(overrides)
17
18
  end
18
19
 
19
- def read_defaults_file
20
- File.readlines(DEFAULTS_FILE).collect { |line| line.strip.split(' ', 2) }.each(&@process_options)
20
+ def read_defaults_files!
21
+ [ GLOBAL_DEFAULTS_FILE, DEFAULTS_FILE ].each do |file|
22
+ if File.file?(file)
23
+ File.readlines(file).collect { |line| line.strip.split(' ', 2) }.each(&@process_options)
24
+ end
25
+ end
21
26
  end
22
27
 
23
- def defaults_file?
24
- File.file?(DEFAULTS_FILE)
28
+ def use_spec?(file)
29
+ @spec_filter.empty? || @spec_filter.include?(file)
25
30
  end
26
31
 
27
32
  def jasmine_html_template(files)
@@ -31,14 +36,14 @@ module Jasmine
31
36
  <head>
32
37
  <title>Jasmine Test Runner</title>
33
38
  <script type="text/javascript">
34
- window.console = { log: function(data) { debug.log(JSON.stringify(data)); } };
39
+ window.console = { log: function(data) { JHW.log(JSON.stringify(data)); } };
35
40
  </script>
36
- #{files.join("\n")}
41
+ #{files.join("\n")}
37
42
  </head>
38
43
  <body>
39
44
 
40
45
  <script type="text/javascript">
41
- jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
46
+ jasmine.getEnv().addReporter(new jasmine.HeadlessReporter());
42
47
  jasmine.getEnv().execute();
43
48
  </script>
44
49
 
@@ -46,6 +51,11 @@ module Jasmine
46
51
  </html>
47
52
  HTML
48
53
  end
54
+
55
+ private
56
+ def read_config_file(file)
57
+
58
+ end
49
59
  end
50
60
  end
51
61
 
@@ -0,0 +1,14 @@
1
+ require 'jasmine/headless/task'
2
+
3
+ module Jasmine
4
+ module Headless
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ Jasmine::Headless::Task.new do |t|
8
+ t.colors = true
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,20 @@
1
+ module Jasmine
2
+ module Headless
3
+ class Task
4
+ attr_accessor :colors, :keep_on_error, :jasmine_config
5
+
6
+ def initialize(name = 'jasmine:headless')
7
+ @colors = false
8
+ @keep_on_error = false
9
+ @jasmine_config = nil
10
+
11
+ yield self if block_given?
12
+
13
+ desc 'Run Jasmine specs headlessly'
14
+ task name do
15
+ system %{jasmine-headless-webkit #{@colors ? "-c" : "--no-colors"} #{@keep_on_error ? "--keep" : ""} #{@jasmine_config ? "-j #{@jasmine_config}" : ""}}
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,7 +1,7 @@
1
1
  module Jasmine
2
2
  module Headless
3
3
  module Webkit
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,9 @@
1
1
  module Jasmine
2
2
  module Headless
3
3
  module Webkit
4
- # Your code goes here...
5
4
  end
6
5
  end
7
6
  end
7
+
8
+ require 'jasmine/headless/railtie' if defined?(Rails)
9
+
@@ -3,21 +3,21 @@ require 'spec_helper'
3
3
  describe "jasmine-headless-webkit" do
4
4
  describe 'success' do
5
5
  it "should succeed with error code 0" do
6
- %x{bin/jasmine-headless-webkit spec/jasmine/success/success.yml}
6
+ %x{bin/jasmine-headless-webkit -j spec/jasmine/success/success.yml}
7
7
  $?.exitstatus.should == 0
8
8
  end
9
9
  end
10
10
 
11
11
  describe 'failure' do
12
12
  it "should fail with an error code of 1" do
13
- %x{bin/jasmine-headless-webkit spec/jasmine/failure/failure.yml}
13
+ %x{bin/jasmine-headless-webkit -j spec/jasmine/failure/failure.yml}
14
14
  $?.exitstatus.should == 1
15
15
  end
16
16
  end
17
17
 
18
18
  describe 'with console.log' do
19
19
  it "should succeed, but has a console.log so an error code of 2" do
20
- %x{bin/jasmine-headless-webkit spec/jasmine/console_log/console_log.yml}
20
+ %x{bin/jasmine-headless-webkit -j spec/jasmine/console_log/console_log.yml}
21
21
  $?.exitstatus.should == 2
22
22
  end
23
23
  end
@@ -41,22 +41,49 @@ describe Jasmine::CLI do
41
41
  end
42
42
 
43
43
  describe '#read_defaults_file' do
44
- let(:test_data) { %w{first second} }
44
+ let(:global_test_data) { %w{first second} }
45
+ let(:test_data) { %w{third fourth} }
45
46
 
46
47
  before do
48
+ File.open(GLOBAL_DEFAULTS_FILE, 'w') { |fh| fh.puts global_test_data.join(' ') }
47
49
  File.open(DEFAULTS_FILE, 'w') { |fh| fh.puts test_data.join(' ') }
48
50
  end
49
51
 
50
52
  it "should read the options" do
51
- found = false
53
+ all_data = []
54
+ @process_options = lambda { |*args| all_data << args.flatten }
52
55
 
53
- @process_options = lambda { |*args|
54
- found = true if args.flatten == test_data
55
- }
56
+ read_defaults_files!
57
+
58
+ all_data.should == [ global_test_data, test_data ]
59
+ end
60
+ end
61
+
62
+ describe '#use_spec?' do
63
+ let(:spec_file) { 'my/spec.js' }
64
+
65
+ context 'no filter provided' do
66
+ before do
67
+ @spec_filter = []
68
+ end
56
69
 
57
- read_defaults_file
70
+ it "should allow the spec" do
71
+ use_spec?(spec_file).should be_true
72
+ end
73
+ end
74
+
75
+ context 'filter provided' do
76
+ before do
77
+ @spec_filter = [ spec_file ]
78
+ end
58
79
 
59
- found.should be_true
80
+ it "should use the spec" do
81
+ use_spec?(spec_file).should be_true
82
+ end
83
+
84
+ it "should not use the spec" do
85
+ use_spec?('other/file').should be_false
86
+ end
60
87
  end
61
88
  end
62
89
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jasmine-headless-webkit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bintz
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2011-05-10 00:00:00 -04:00
15
+ date: 2011-05-17 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -61,15 +61,19 @@ files:
61
61
  - .autotest
62
62
  - .gitignore
63
63
  - .rspec
64
+ - CHANGELOG.md
64
65
  - Gemfile
65
66
  - README.md
66
67
  - Rakefile
67
68
  - bin/jasmine-headless-webkit
69
+ - coffee.watchr
68
70
  - ext/jasmine-webkit-specrunner/Info.plist
69
71
  - ext/jasmine-webkit-specrunner/extconf.rb
70
72
  - ext/jasmine-webkit-specrunner/specrunner.cpp
71
73
  - ext/jasmine-webkit-specrunner/specrunner.pro
72
74
  - jasmine-headless-webkit.gemspec
75
+ - jasmine/jasmine.headless-reporter.coffee
76
+ - jasmine/jasmine.headless-reporter.js
73
77
  - lib/autotest/discover.rb
74
78
  - lib/autotest/jasmine.rb
75
79
  - lib/autotest/jasmine_mixin.rb
@@ -77,6 +81,8 @@ files:
77
81
  - lib/jasmine-headless-webkit.rb
78
82
  - lib/jasmine-headless-webkit/version.rb
79
83
  - lib/jasmine/cli.rb
84
+ - lib/jasmine/headless/railtie.rb
85
+ - lib/jasmine/headless/task.rb
80
86
  - spec/bin/jasmine-headless-webkit_spec.rb
81
87
  - spec/jasmine/console_log/console_log.js
82
88
  - spec/jasmine/console_log/console_log.yml