jasmine-headless-webkit 0.0.1 → 0.0.2

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/.autotest ADDED
@@ -0,0 +1,9 @@
1
+ Autotest.add_hook(:initialize) do |at|
2
+ at.add_mapping(%r{bin/.*}, true) do |filename|
3
+ at.files_matching(%r{spec/bin/.*})
4
+ end
5
+
6
+ at.add_mapping(%r{spec/jasmine/.*}, true) do |filename|
7
+ at.files_matching(%r{spec/bin/.*})
8
+ end
9
+ end
data/.gitignore CHANGED
@@ -2,3 +2,7 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ Makefile
6
+ specrunner.moc
7
+ specrunner.o
8
+ ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -c
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in jasmine-headless-webkit.gemspec
4
4
  gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'autotest'
8
+
data/README.md CHANGED
@@ -2,20 +2,26 @@
2
2
 
3
3
  ## Introduction
4
4
 
5
- This gem works with projects that use the [Jasmine gem](https://github.com/pivotal/jasmine-gem) to
6
- create a `jasmine.yml` file defining what to test. The runner loads that
5
+ This gem works with projects that have used the [Jasmine gem](https://github.com/pivotal/jasmine-gem) to
6
+ create a `jasmine.yml` file that defines what to test. The runner loads that
7
7
  `jasmine.yml` file and executes the
8
- tests in a Qt WebKit widget, displaying the results to the console and setting the exit code to 0 for
9
- success or 1 for failure.
8
+ tests in a Qt WebKit widget, displaying the results to the console and setting the exit code to one
9
+ of the following:
10
+
11
+ * 0 for success
12
+ * 1 for spec run failure
13
+ * 2 for spec run success, but `console.log` was called during the run
10
14
 
11
15
  `console.log` works, too, so you can run your specs side-by-side in a browser if you're so inclined.
12
16
 
17
+ ## Installation
18
+
19
+ `gem install jasmine-headless-webkit` or use Bundler.
20
+
13
21
  ## Usage
14
22
 
15
23
  jasmine-headless-webkit [path to jasmine.yml, defaults to spec/javascripts/support/jasmine.yml]
16
24
 
17
- *This gem is currently as rough as it gets.*
18
-
19
25
  Installation requires Qt 4.7. See [senchalabs/examples](https://github.com/senchalabs/examples) and [my fork
20
26
  of examples](https://github.com/johnbintz/examples) for more information on the QtWebKit runner.
21
27
 
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { 'rspec2' }
@@ -64,7 +64,7 @@ HTML
64
64
 
65
65
  File.open(target = "specrunner.#{$$}.html", 'w') { |fh| fh.print output }
66
66
  system %{#{File.join(gem_dir, 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner')} #{target}}
67
- status = ($? == 0) ? 0 : 1
67
+ status = $?.exitstatus
68
68
  FileUtils.rm_f target
69
69
 
70
70
  exit status
@@ -29,6 +29,20 @@
29
29
  #error Use Qt 4.7 or later version
30
30
  #endif
31
31
 
32
+ class HeadlessSpecRunnerPage: public QWebPage
33
+ {
34
+ Q_OBJECT
35
+ signals:
36
+ void consoleLog(const QString &msg, int lineNumber, const QString &sourceID);
37
+ protected:
38
+ void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
39
+ };
40
+
41
+ void HeadlessSpecRunnerPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID)
42
+ {
43
+ emit consoleLog(message, lineNumber, sourceID);
44
+ }
45
+
32
46
  class HeadlessSpecRunner: public QObject
33
47
  {
34
48
  Q_OBJECT
@@ -40,21 +54,27 @@ public slots:
40
54
  void specLog(int indent, const QString &msg, const QString &clazz);
41
55
  private slots:
42
56
  void watch(bool ok);
57
+ void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
43
58
  protected:
44
59
  bool hasElement(const char *select);
45
60
  void timerEvent(QTimerEvent *event);
46
61
  private:
47
- QWebPage m_page;
62
+ HeadlessSpecRunnerPage m_page;
48
63
  QBasicTimer m_ticker;
49
64
  int m_runs;
65
+ bool hasErrors;
66
+ bool usedConsole;
50
67
  };
51
68
 
52
69
  HeadlessSpecRunner::HeadlessSpecRunner()
53
70
  : QObject()
54
71
  , m_runs(0)
72
+ , hasErrors(false)
73
+ , usedConsole(false)
55
74
  {
56
75
  m_page.settings()->enablePersistentStorage();
57
76
  connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
77
+ connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString)));
58
78
  }
59
79
 
60
80
  void HeadlessSpecRunner::load(const QString &spec)
@@ -81,8 +101,20 @@ bool HeadlessSpecRunner::hasElement(const char *select)
81
101
  return !m_page.mainFrame()->findFirstElement(select).isNull();
82
102
  }
83
103
 
104
+ void HeadlessSpecRunner::errorLog(const QString &msg, int lineNumber, const QString &sourceID)
105
+ {
106
+ std::cout << "\033[0;31m" << "[error] " << "\033[m;";
107
+ std::cout << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg);
108
+ std::cout << std::endl;
109
+
110
+ hasErrors = true;
111
+ m_runs = 0;
112
+ m_ticker.start(200, this);
113
+ }
114
+
84
115
  void HeadlessSpecRunner::log(const QString &msg)
85
116
  {
117
+ usedConsole = true;
86
118
  std::cout << "\033[0;32m" << "[console] " << "\033[m";
87
119
  std::cout << qPrintable(msg);
88
120
  std::cout << std::endl;
@@ -116,32 +148,38 @@ void HeadlessSpecRunner::specLog(int indent, const QString &msg, const QString &
116
148
 
117
149
  void HeadlessSpecRunner::timerEvent(QTimerEvent *event)
118
150
  {
119
- if (event->timerId() != m_ticker.timerId())
120
- return;
151
+ ++m_runs;
121
152
 
122
- if (!hasElement(".jasmine_reporter") && !hasElement(".runner.running"))
153
+ if (event->timerId() != m_ticker.timerId())
123
154
  return;
124
155
 
125
- if (hasElement(".runner.passed")) {
126
- QWebElement desc = m_page.mainFrame()->findFirstElement(".description");
127
- std::cout << "\033[0;32m" << "PASS: " << qPrintable(desc.toPlainText()) << "\033[m" << std::endl;
128
- QApplication::instance()->exit(0);
129
- return;
130
- }
131
-
132
- if (hasElement(".runner.failed")) {
133
- QWebElement desc = m_page.mainFrame()->findFirstElement(".description");
134
- std::cout << "\033[0;31m" << "FAIL: " << qPrintable(desc.toPlainText()) << "\033[m" << std::endl;
135
- m_page.mainFrame()->evaluateJavaScript(DUMP_MSG);
136
- //QDesktopServices::openUrl(m_page.mainFrame()->url());
156
+ if (hasErrors && m_runs > 2)
137
157
  QApplication::instance()->exit(1);
138
- return;
139
- }
140
158
 
141
- ++m_runs;
142
- if (m_runs > 20) {
143
- std::cout << "WARNING: too many runs and the test is still not finished!" << std::endl;
144
- QApplication::instance()->exit(1);
159
+ if (!hasErrors) {
160
+ if (!hasElement(".jasmine_reporter") && !hasElement(".runner.running"))
161
+ return;
162
+
163
+ if (hasElement(".runner.passed")) {
164
+ QWebElement desc = m_page.mainFrame()->findFirstElement(".description");
165
+ std::cout << "\033[0;32m" << "PASS: " << qPrintable(desc.toPlainText()) << "\033[m" << std::endl;
166
+ QApplication::instance()->exit(usedConsole ? 2 : 0);
167
+ return;
168
+ }
169
+
170
+ if (hasElement(".runner.failed")) {
171
+ QWebElement desc = m_page.mainFrame()->findFirstElement(".description");
172
+ std::cout << "\033[0;31m" << "FAIL: " << qPrintable(desc.toPlainText()) << "\033[m" << std::endl;
173
+ m_page.mainFrame()->evaluateJavaScript(DUMP_MSG);
174
+ //QDesktopServices::openUrl(m_page.mainFrame()->url());
175
+ QApplication::instance()->exit(1);
176
+ return;
177
+ }
178
+
179
+ if (m_runs > 30) {
180
+ std::cout << "WARNING: too many runs and the test is still not finished!" << std::endl;
181
+ QApplication::instance()->exit(1);
182
+ }
145
183
  }
146
184
  }
147
185
 
@@ -1,7 +1,7 @@
1
1
  module Jasmine
2
2
  module Headless
3
3
  module Webkit
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe "jasmine-headless-webkit" do
4
+ describe 'success' do
5
+ it "should succeed with error code 0" do
6
+ %x{bin/jasmine-headless-webkit spec/jasmine/success/success.yml}
7
+ $?.exitstatus.should == 0
8
+ end
9
+ end
10
+
11
+ describe 'failure' do
12
+ it "should fail with an error code of 1" do
13
+ %x{bin/jasmine-headless-webkit spec/jasmine/failure/failure.yml}
14
+ $?.exitstatus.should == 1
15
+ end
16
+ end
17
+
18
+ describe 'with console.log' do
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}
21
+ $?.exitstatus.should == 2
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1 @@
1
+ var success = 1;
@@ -0,0 +1,10 @@
1
+
2
+ src_files:
3
+ - spec/jasmine/console_log/console_log.js
4
+
5
+ spec_files:
6
+ - spec/jasmine/console_log/console_log_spec.js
7
+
8
+ src_dir: .
9
+ spec_dir: .
10
+
@@ -0,0 +1,7 @@
1
+ describe('console.log', function() {
2
+ it('should succeed, but with a console.log', function() {
3
+ console.log("hello");
4
+ expect(success).toEqual(1);
5
+ });
6
+ });
7
+
@@ -0,0 +1 @@
1
+ var failure = 0;
@@ -0,0 +1,9 @@
1
+ src_files:
2
+ - spec/jasmine/failure/failure.js
3
+
4
+ spec_files:
5
+ - spec/jasmine/failure/failure_spec.js
6
+
7
+ src_dir: .
8
+ spec_dir: .
9
+
@@ -0,0 +1,6 @@
1
+ describe('failure', function() {
2
+ it("should fail with error code of 1", function() {
3
+ expect(failure).toEqual(1);
4
+ });
5
+ });
6
+
@@ -0,0 +1 @@
1
+ var success = 1;
@@ -0,0 +1,9 @@
1
+ src_files:
2
+ - spec/jasmine/success/success.js
3
+
4
+ spec_files:
5
+ - spec/jasmine/success/success_spec.js
6
+
7
+ src_dir: .
8
+ spec_dir: .
9
+
@@ -0,0 +1,6 @@
1
+ describe('success', function() {
2
+ it("should be a success", function() {
3
+ expect(success).toEqual(1);
4
+ });
5
+ });
6
+
@@ -0,0 +1,8 @@
1
+ specrunner = 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner'
2
+
3
+ if !File.file?(specrunner)
4
+ Dir.chdir File.split(specrunner).first do
5
+ system %{ruby extconf.rb}
6
+ end
7
+ end
8
+
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine-headless-webkit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
4
+ prerelease:
5
+ version: 0.0.2
11
6
  platform: ruby
12
7
  authors:
13
8
  - John Bintz
@@ -17,7 +12,7 @@ autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
14
 
20
- date: 2011-04-11 00:00:00 -04:00
15
+ date: 2011-04-13 00:00:00 -04:00
21
16
  default_executable:
22
17
  dependencies:
23
18
  - !ruby/object:Gem::Dependency
@@ -28,9 +23,6 @@ dependencies:
28
23
  requirements:
29
24
  - - ">="
30
25
  - !ruby/object:Gem::Version
31
- hash: 3
32
- segments:
33
- - 0
34
26
  version: "0"
35
27
  type: :runtime
36
28
  version_requirements: *id001
@@ -44,11 +36,14 @@ extensions:
44
36
  extra_rdoc_files: []
45
37
 
46
38
  files:
39
+ - .autotest
47
40
  - .gitignore
48
41
  - .gitmodules
42
+ - .rspec
49
43
  - Gemfile
50
44
  - README.md
51
45
  - Rakefile
46
+ - autotest/discover.rb
52
47
  - bin/jasmine-headless-webkit
53
48
  - ext/jasmine-webkit-specrunner/Info.plist
54
49
  - ext/jasmine-webkit-specrunner/extconf.rb
@@ -57,6 +52,17 @@ files:
57
52
  - jasmine-headless-webkit.gemspec
58
53
  - lib/jasmine-headless-webkit.rb
59
54
  - lib/jasmine-headless-webkit/version.rb
55
+ - spec/bin/jasmine-headless-webkit_spec.rb
56
+ - spec/jasmine/console_log/console_log.js
57
+ - spec/jasmine/console_log/console_log.yml
58
+ - spec/jasmine/console_log/console_log_spec.js
59
+ - spec/jasmine/failure/failure.js
60
+ - spec/jasmine/failure/failure.yml
61
+ - spec/jasmine/failure/failure_spec.js
62
+ - spec/jasmine/success/success.js
63
+ - spec/jasmine/success/success.yml
64
+ - spec/jasmine/success/success_spec.js
65
+ - spec/spec_helper.rb
60
66
  - jasmine/lib/jasmine-html.js
61
67
  - jasmine/lib/jasmine.css
62
68
  - jasmine/lib/jasmine.js
@@ -75,25 +81,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
81
  requirements:
76
82
  - - ">="
77
83
  - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
84
  version: "0"
82
85
  required_rubygems_version: !ruby/object:Gem::Requirement
83
86
  none: false
84
87
  requirements:
85
88
  - - ">="
86
89
  - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
90
  version: "0"
91
91
  requirements: []
92
92
 
93
93
  rubyforge_project: jasmine-headless-webkit
94
- rubygems_version: 1.3.7
94
+ rubygems_version: 1.6.2
95
95
  signing_key:
96
96
  specification_version: 3
97
97
  summary: Run Jasmine specs headlessly in a WebKit browser
98
- test_files: []
99
-
98
+ test_files:
99
+ - spec/bin/jasmine-headless-webkit_spec.rb
100
+ - spec/jasmine/console_log/console_log.js
101
+ - spec/jasmine/console_log/console_log.yml
102
+ - spec/jasmine/console_log/console_log_spec.js
103
+ - spec/jasmine/failure/failure.js
104
+ - spec/jasmine/failure/failure.yml
105
+ - spec/jasmine/failure/failure_spec.js
106
+ - spec/jasmine/success/success.js
107
+ - spec/jasmine/success/success.yml
108
+ - spec/jasmine/success/success_spec.js
109
+ - spec/spec_helper.rb