js_spec 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGES +6 -0
  2. data/README +23 -1
  3. data/Rakefile +5 -3
  4. data/bin/js_spec +1 -5
  5. data/bin/js_spec_server +0 -0
  6. data/core/JSSpecExtensions.js +70 -25
  7. data/core/jquery.js +2992 -0
  8. data/init.rb +0 -0
  9. data/lib/js_spec/client.rb +50 -0
  10. data/lib/js_spec/rack/response.rb +5 -0
  11. data/lib/js_spec/rails_server.rb +3 -3
  12. data/lib/js_spec/resources/dir.rb +43 -43
  13. data/lib/js_spec/resources/file.rb +16 -16
  14. data/lib/js_spec/resources/runners/firefox1_runner.rb +8 -0
  15. data/lib/js_spec/resources/runners/firefox_runner.rb +49 -72
  16. data/lib/js_spec/resources/runners.rb +6 -7
  17. data/lib/js_spec/resources/spec_dir_runner.rb +7 -7
  18. data/lib/js_spec/resources/spec_file_runner.rb +7 -7
  19. data/lib/js_spec/resources/spec_runner.rb +16 -11
  20. data/lib/js_spec/resources/suite.rb +14 -14
  21. data/lib/js_spec/resources/suite_finish.rb +12 -12
  22. data/lib/js_spec/server.rb +29 -17
  23. data/lib/js_spec/thin/backends/js_spec_server.rb +9 -0
  24. data/lib/js_spec/thin/js_spec_connection.rb +43 -0
  25. data/lib/js_spec.rb +14 -2
  26. data/spec/integration/integration_spec.rb +14 -0
  27. data/spec/integration/integration_spec_helper.rb +52 -0
  28. data/spec/integration_suite.rb +10 -0
  29. data/spec/spec_suite.rb +1 -0
  30. data/spec/unit/js_spec/client_spec.rb +137 -0
  31. data/spec/unit/{rails_server_spec.rb → js_spec/rails_server_spec.rb} +8 -7
  32. data/spec/unit/{resources → js_spec/resources}/dir_spec.rb +1 -1
  33. data/spec/unit/{resources → js_spec/resources}/file_spec.rb +9 -6
  34. data/spec/unit/js_spec/resources/runner_spec.rb +24 -0
  35. data/spec/unit/js_spec/resources/runners/firefox_runner_spec.rb +152 -0
  36. data/spec/unit/js_spec/resources/spec_dir_runner_spec.rb +48 -0
  37. data/spec/unit/{resources → js_spec/resources}/spec_file_runner_spec.rb +1 -1
  38. data/spec/unit/{resources → js_spec/resources}/suite_finish_spec.rb +5 -5
  39. data/spec/unit/{resources → js_spec/resources}/suite_spec.rb +1 -1
  40. data/spec/unit/{resources → js_spec/resources}/web_root_spec.rb +1 -1
  41. data/spec/unit/{server_spec.rb → js_spec/server_spec.rb} +29 -92
  42. data/spec/unit/rack/response_spec.rb +30 -0
  43. data/spec/unit/thin/js_spec_connection_spec.rb +50 -0
  44. data/spec/unit/unit_spec_helper.rb +40 -5
  45. metadata +107 -60
  46. data/spec/unit/resources/runner_spec.rb +0 -24
  47. data/spec/unit/resources/runners/firefox_runner_spec.rb +0 -87
  48. data/spec/unit/resources/spec_dir_runner_spec.rb +0 -43
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ 0.2.0
2
+ - Using Thin as the server
3
+ - Using Selenium to run the browsers
4
+ - Added instructions to run JsSpec on CI
5
+ - Added js_spec as an executable
6
+
1
7
  0.1.0
2
8
  - Added RailsServer
3
9
  - Better namespacing
data/README CHANGED
@@ -4,6 +4,28 @@ The JsSpec ruby library is a server runner for the JsSpec javascript library.
4
4
  http://code.google.com/p/jsspec/
5
5
  http://jania.pe.kr/aw/moin.cgi/JSSpec
6
6
 
7
+ == Installing JsSpec
8
+ You can use JsSpec as a gem or as a Rails plugin.
9
+ To install the gem, run:
10
+ sudo gem install js_spec
11
+
12
+ To install the plugin, run:
13
+ script/plugin install svn://rubyforge.org/var/svn/pivotalrb/js_spec/trunk
14
+
15
+ The Rails plugin gives you generators when using JsSpec in a Rails environment.
16
+
7
17
  == Using JsSpec
8
18
  js_spec_server /path/to/your/javascript/spec/files /path/to/your/javascript/implementation/files
9
- Open your browser to http://localhost:8080/specs
19
+
20
+ Open your browser to http://localhost:8080/specs or run selenium and then run js_spec
21
+
22
+ == JsSpec on CI
23
+ JS spec uses the Selenium gem to automatically control browsers on different machines.
24
+
25
+ To use JsSpec in a CI environment,
26
+ * Install and run the selenium RC server on the machine that you want to run the browsers by using the command:
27
+ selenium
28
+ * Run the js_spec_server on the machine that has the files.
29
+ script/js_spec_server
30
+ * Run the js_spec client. The js_spec client has --selenium_host, --selenium_port, and --spec_url arguments to specify
31
+ where the Selenium server is relative to the js_spec server, and where the js_spec server is relative to the browser.
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ def run_suite
26
26
  end
27
27
 
28
28
  PKG_NAME = "js_spec"
29
- PKG_VERSION = "0.1.0"
29
+ PKG_VERSION = "0.2.0"
30
30
  PKG_FILES = FileList[
31
31
  '[A-Z]*',
32
32
  '*.rb',
@@ -45,7 +45,7 @@ spec = Gem::Specification.new do |s|
45
45
 
46
46
  s.files = PKG_FILES.to_a
47
47
  s.require_path = 'lib'
48
- s.executables = ['js_spec_server']
48
+ s.executables = ['js_spec', 'js_spec_server']
49
49
 
50
50
  s.has_rdoc = true
51
51
  s.extra_rdoc_files = [ "README", "CHANGES" ]
@@ -53,11 +53,13 @@ spec = Gem::Specification.new do |s|
53
53
 
54
54
  s.test_files = Dir.glob('spec/*_spec.rb')
55
55
  s.require_path = 'lib'
56
- s.autorequire = 'js_spec'
57
56
  s.author = "Brian Takita & Nathan Sobo"
58
57
  s.email = "brian@pivotallabs.com"
59
58
  s.homepage = "http://pivotallabs.com"
60
59
  s.rubyforge_project = "pivotalrb"
60
+ s.add_dependency('Selenium')
61
+ s.add_dependency('thin')
62
+ s.add_dependency('uuid')
61
63
  end
62
64
 
63
65
  Rake::GemPackageTask.new(spec) do |pkg|
data/bin/js_spec CHANGED
@@ -3,8 +3,4 @@
3
3
  dir = File.dirname(__FILE__)
4
4
  $LOAD_PATH.unshift("#{dir}/../lib")
5
5
  require "js_spec"
6
- require "net/http"
7
-
8
- response = Net::HTTP.start(JsSpec::Server::DEFAULT_HOST, JsSpec::Server::DEFAULT_PORT) do |http|
9
- http.post('/runners/firefox', {})
10
- end
6
+ exit JsSpec::Client.run_argv(ARGV)
data/bin/js_spec_server CHANGED
File without changes
@@ -1,20 +1,74 @@
1
- var Require = {
2
- require: function(path_from_javascripts) {
3
- if(!Require.required_paths[path_from_javascripts]) {
1
+ function Spec() {
2
+ }
3
+
4
+ Spec.register = function(spec_constructor) {
5
+ spec_constructor.describe = function(context, definition) {
6
+ var custom_before = definition['before each'];
7
+ if(custom_before) {
8
+ definition['before each'] = function() {
9
+ if(spec_constructor['before each']) spec_constructor['before each']();
10
+ custom_before();
11
+ }
12
+ } else {
13
+ definition['before each'] = function() {
14
+ if(spec_constructor['before each']) spec_constructor['before each']();
15
+ };
16
+ }
17
+
18
+ var custom_after = definition['after each'];
19
+ if(custom_after) {
20
+ definition['after each'] = function() {
21
+ custom_after();
22
+ if(spec_constructor['after each']) spec_constructor['after each']();
23
+ Spec.reset();
24
+ }
25
+ } else {
26
+ definition['after each'] = function() {
27
+ if(spec_constructor['after each']) spec_constructor['after each']();
28
+ Spec.reset();
29
+ }
30
+ }
31
+ new spec_constructor();
32
+ describe(spec_constructor.name.toString() + context.toString(), definition);
33
+ }
34
+ }
35
+
36
+ Spec.reset = function() {}
37
+
38
+ var Assets = {
39
+ require: function(path_from_javascripts, onload) {
40
+ if(!Assets.required_paths[path_from_javascripts]) {
4
41
  var full_path = path_from_javascripts + ".js";
5
- if (Require.use_cache_buster) {
6
- full_path += '?' + Require.cache_buster;
42
+ if (Assets.use_cache_buster) {
43
+ full_path += '?' + Assets.cache_buster;
7
44
  }
8
45
  document.write("<script src='" + full_path + "' type='text/javascript'></script>");
9
- Require.required_paths[path_from_javascripts] = true;
46
+ if(onload) {
47
+ var scripts = document.getElementsByTagName('script');
48
+ scripts[scripts.length-1].onload = onload;
49
+ }
50
+ Assets.required_paths[path_from_javascripts] = true;
51
+ }
52
+ },
53
+
54
+ stylesheet: function(path_from_stylesheets) {
55
+ if(!Assets.included_stylesheets[path_from_stylesheets]) {
56
+ var full_path = path_from_stylesheets + ".css";
57
+ if(Assets.use_cache_buster) {
58
+ full_path += '?' + Assets.cache_buster;
59
+ }
60
+ document.write("<link rel='stylesheet' type='text/css' href='" + full_path + "' />");
61
+ Assets.included_stylesheets[path_from_stylesheets] = true;
10
62
  }
11
63
  },
12
64
 
13
65
  required_paths: {},
14
- use_cache_buster: true, // TODO: NS/CTI - make this configurable from the UI.
66
+ included_stylesheets: {},
67
+ use_cache_buster: false, // TODO: NS/CTI - make this configurable from the UI.
15
68
  cache_buster: parseInt(new Date().getTime()/(1*1000))
16
69
  }
17
- var require = Require.require;
70
+ var require = Assets.require;
71
+ var stylesheet = Assets.stylesheet;
18
72
 
19
73
  var URL_REGEX = /^((\w+):\/\/)(([^:]+):?([^@]+)?@)?([^\/\?:]*):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(.+)?/;
20
74
  function parse_url(url) {
@@ -37,21 +91,16 @@ function parse_url(url) {
37
91
  JSSpec.Logger.prototype.onRunnerEndWithoutServerNotification = JSSpec.Logger.prototype.onRunnerEnd;
38
92
  JSSpec.Logger.prototype.onRunnerEndWithServerNotification = function() {
39
93
  this.onRunnerEndWithoutServerNotification();
40
- var data = {
41
- 'text': this.get_error_message_text()
42
- };
43
-
44
- current_location_params = parse_url(window.location.href);
45
- if(current_location_params.guid) {
46
- data.guid = current_location_params.guid;
47
- }
48
- jQuery.realAjax({
49
- type: 'POST',
50
- url: '/suites/1/finish',
51
- data: data
52
- });
94
+ var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
95
+ xml.open("POST", '/suites/1/finish', true);
96
+ xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
97
+ var body = [];
98
+ body.push(encodeURIComponent("guid") + "=" + encodeURIComponent( JSSpec.guid ));
99
+ body.push(encodeURIComponent("text") + "=" + encodeURIComponent( this.get_error_message_text() ));
100
+ xml.send(body.join("&"));
53
101
  }
54
102
  JSSpec.Logger.prototype.onRunnerEnd = JSSpec.Logger.prototype.onRunnerEndWithServerNotification;
103
+ JSSpec.guid = null;
55
104
 
56
105
  JSSpec.Logger.prototype.get_error_message_text = function() {
57
106
  var error_messages = [];
@@ -140,7 +189,3 @@ JSSpec.DSL.Subject.prototype.should_not_raise = function(expected) {
140
189
  throw JSSpec._assertionFailure;
141
190
  }
142
191
  }
143
-
144
-
145
-
146
-