js_spec 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/CHANGES +6 -0
 - data/README +23 -1
 - data/Rakefile +5 -3
 - data/bin/js_spec +1 -5
 - data/bin/js_spec_server +0 -0
 - data/core/JSSpecExtensions.js +70 -25
 - data/core/jquery.js +2992 -0
 - data/init.rb +0 -0
 - data/lib/js_spec/client.rb +50 -0
 - data/lib/js_spec/rack/response.rb +5 -0
 - data/lib/js_spec/rails_server.rb +3 -3
 - data/lib/js_spec/resources/dir.rb +43 -43
 - data/lib/js_spec/resources/file.rb +16 -16
 - data/lib/js_spec/resources/runners/firefox1_runner.rb +8 -0
 - data/lib/js_spec/resources/runners/firefox_runner.rb +49 -72
 - data/lib/js_spec/resources/runners.rb +6 -7
 - data/lib/js_spec/resources/spec_dir_runner.rb +7 -7
 - data/lib/js_spec/resources/spec_file_runner.rb +7 -7
 - data/lib/js_spec/resources/spec_runner.rb +16 -11
 - data/lib/js_spec/resources/suite.rb +14 -14
 - data/lib/js_spec/resources/suite_finish.rb +12 -12
 - data/lib/js_spec/server.rb +29 -17
 - data/lib/js_spec/thin/backends/js_spec_server.rb +9 -0
 - data/lib/js_spec/thin/js_spec_connection.rb +43 -0
 - data/lib/js_spec.rb +14 -2
 - data/spec/integration/integration_spec.rb +14 -0
 - data/spec/integration/integration_spec_helper.rb +52 -0
 - data/spec/integration_suite.rb +10 -0
 - data/spec/spec_suite.rb +1 -0
 - data/spec/unit/js_spec/client_spec.rb +137 -0
 - data/spec/unit/{rails_server_spec.rb → js_spec/rails_server_spec.rb} +8 -7
 - data/spec/unit/{resources → js_spec/resources}/dir_spec.rb +1 -1
 - data/spec/unit/{resources → js_spec/resources}/file_spec.rb +9 -6
 - data/spec/unit/js_spec/resources/runner_spec.rb +24 -0
 - data/spec/unit/js_spec/resources/runners/firefox_runner_spec.rb +152 -0
 - data/spec/unit/js_spec/resources/spec_dir_runner_spec.rb +48 -0
 - data/spec/unit/{resources → js_spec/resources}/spec_file_runner_spec.rb +1 -1
 - data/spec/unit/{resources → js_spec/resources}/suite_finish_spec.rb +5 -5
 - data/spec/unit/{resources → js_spec/resources}/suite_spec.rb +1 -1
 - data/spec/unit/{resources → js_spec/resources}/web_root_spec.rb +1 -1
 - data/spec/unit/{server_spec.rb → js_spec/server_spec.rb} +29 -92
 - data/spec/unit/rack/response_spec.rb +30 -0
 - data/spec/unit/thin/js_spec_connection_spec.rb +50 -0
 - data/spec/unit/unit_spec_helper.rb +40 -5
 - metadata +107 -60
 - data/spec/unit/resources/runner_spec.rb +0 -24
 - data/spec/unit/resources/runners/firefox_runner_spec.rb +0 -87
 - data/spec/unit/resources/spec_dir_runner_spec.rb +0 -43
 
    
        data/CHANGES
    CHANGED
    
    
    
        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 
     | 
    
         
            -
             
     | 
| 
      
 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. 
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       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
         
     | 
    
        data/core/JSSpecExtensions.js
    CHANGED
    
    | 
         @@ -1,20 +1,74 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 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 ( 
     | 
| 
       6 
     | 
    
         
            -
                    full_path += '?' +  
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
      
 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 
     | 
    
         
            -
               
     | 
| 
      
 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 =  
     | 
| 
      
 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  
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
               
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
               
     | 
| 
       45 
     | 
    
         
            -
               
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     |