jasmine-phantom 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jasmine-phantom.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,39 @@
1
+ Jasmine Phantom
2
+ ===============
3
+
4
+ Jasmine Phantom provides a rake task that runs your jasmine specs via phanstomjs. It is adapted from the jasmine runner example that comes with
5
+ phantom js. It requires jasmine `>= 1.2.0rc2`, which is only currency available via github.
6
+
7
+ Installation
8
+ ------------
9
+
10
+ Add jasmine 1.2.0rc2 and jasmine-phantom to your gemfile:
11
+
12
+ gem 'jasmine', '1.2.0.rc2',
13
+ git: "git://github.com/pivotal/jasmine-gem.git",
14
+ branch: "953d17dff4b4adba79b2a808b55cf33f4ff93af7"
15
+
16
+ gem 'jasmine-phantom'
17
+
18
+
19
+ and run `bundle install`.
20
+
21
+ Then run `bundle exec rake jasmine` and check `http://localhost:8888/` to make sure you jasmine specs are passing.
22
+
23
+ Download and install the appropriate [PhantomJS](http://code.google.com/p/phantomjs/downloads/list) for your platform.
24
+ Make sure to add the directory with the `phantomjs` executable to your `PATH`.
25
+
26
+ Finally, run `bundle exec rake jasmine:phantom:ci` and you should see output similar to:
27
+
28
+ Waiting for jasmine server on 57832...
29
+ [2012-04-18 15:50:52] INFO WEBrick 1.3.1
30
+ [2012-04-18 15:50:52] INFO ruby 1.9.3 (2011-10-30) [x86_64-darwin10.8.0]
31
+ [2012-04-18 15:50:52] INFO WEBrick::HTTPServer#start: pid=11608 port=57832
32
+ Waiting for jasmine server on 57832...
33
+ jasmine server started.
34
+ phantomjs /some-path-to/jasmine-phantom/lib/jasmine-phantom/run-jasmine.js http://localhost:57832
35
+
36
+ 215 specs | 0 failing
37
+
38
+ That's it!
39
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jasmine-phantom/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jasmine-phantom"
7
+ s.version = Jasmine::Phantom::VERSION
8
+ s.authors = ["David Vollbracht"]
9
+ s.email = ["david@flipstone.com"]
10
+ s.homepage = "http://github.com/flipstone/jasmine-phantom"
11
+ s.summary = %q{Run you jasmine specs from the commant line using phantomjs}
12
+ s.description = %q{jasmine-phantom provides a rake task, jasmine:phantom:ci,
13
+ that runs your jasmine specs via the phantomjs browser just as if you had
14
+ run rake jasmine and run them manually via your browser.
15
+
16
+ You need to have phantomjs installed and in your PATH for the rake task to work}
17
+
18
+ s.rubyforge_project = "jasmine-phantom"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ # specify any dependencies here; for example:
26
+ # s.add_development_dependency "rspec"
27
+ s.add_runtime_dependency "rails", '>= 3.0'
28
+ s.add_runtime_dependency "jasmine", '>= 1.2.0rc2'
29
+ end
@@ -0,0 +1,8 @@
1
+ require "jasmine-phantom/version"
2
+
3
+ module Jasmine
4
+ module Phantom
5
+ end
6
+ end
7
+
8
+ require File.join('jasmine-phantom', 'railtie')
@@ -0,0 +1,9 @@
1
+ require 'rails/railtie'
2
+
3
+ module JasminePhantom
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load "jasmine-phantom/tasks.rake"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,121 @@
1
+ var system = require('system');
2
+
3
+ function waitFor(message, testFx, onReady, timeOutMillis) {
4
+ var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001; //< Default Max Timeout is 3s
5
+ var start = new Date().getTime();
6
+ var condition = false;
7
+ var interval = setInterval(function() {
8
+ if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
9
+ // If not time-out yet and condition not yet fulfilled
10
+ condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
11
+ } else {
12
+ if(!condition) {
13
+ // If condition still not fulfilled (timeout but condition is 'false')
14
+ console.log("'Timed out waiting for " + message);
15
+ phantom.exit(1);
16
+ } else {
17
+ // Condition fulfilled (timeout and/or condition is 'true')
18
+ typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
19
+ clearInterval(interval); //< Stop this interval
20
+ }
21
+ }
22
+ }, 100); //< repeat check every 100ms
23
+ };
24
+
25
+
26
+ if (system.args.length !== 2) {
27
+ console.log('Usage: run-jasmine.js URL');
28
+ phantom.exit();
29
+ }
30
+
31
+ var page = require('webpage').create();
32
+
33
+ // Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
34
+ page.onConsoleMessage = function(msg) {
35
+ console.log(msg);
36
+ };
37
+
38
+ page.open(system.args[1], function(status){
39
+ if (status !== "success") {
40
+ console.log("Unable to access network");
41
+ phantom.exit();
42
+ } else {
43
+ waitFor("Jasmine specs to report finished", function(){
44
+ return page.evaluate(function(){
45
+ return jsApiReporter.finished;
46
+ });
47
+ }, function(){
48
+ var summary = page.evaluate(function(){
49
+ console.log('');
50
+ var suites = jsApiReporter.suites();
51
+ var results = jsApiReporter.results();
52
+
53
+ for(var specId in results) {
54
+ var result = results[specId];
55
+ if (result.result != "passed") {
56
+
57
+ var name = findSpecName(specId, suites);
58
+
59
+ console.log(name);
60
+
61
+ for (var msgId in result.messages) {
62
+ console.log(' ' + result.messages[msgId]);
63
+ }
64
+
65
+ console.log('');
66
+ }
67
+ }
68
+
69
+ return summarizeResults(suites, results);
70
+
71
+ function findSpecName(specId, suites) {
72
+ for (var i in suites) {
73
+ if (suites[i].id == specId) {
74
+ return suites[i].name;
75
+ }
76
+
77
+ var name = findSpecName(specId, suites[i].children);
78
+
79
+ if (name) { return suites[i].name + ' ' + name };
80
+ }
81
+ }
82
+
83
+ function summarizeResults(suites, results) {
84
+ var total = { total: 0, passed: 0, failed: 0 }
85
+
86
+ for (var i in suites) {
87
+ var suite = suites[i];
88
+
89
+ if (suite.type == 'spec') {
90
+ total.total++;
91
+
92
+ if (results[suite.id].result == 'passed') {
93
+ total.passed++;
94
+ } else {
95
+ total.failed++;
96
+ }
97
+ }
98
+
99
+ var subTotal = summarizeResults(suite.children, results);
100
+ total.total += subTotal.total;
101
+ total.passed += subTotal.passed;
102
+ total.failed += subTotal.failed;
103
+ }
104
+
105
+ return total;
106
+ }
107
+
108
+ return passed;
109
+ });
110
+
111
+ console.log(summary.total + ' specs | ' + summary.failed + ' failing');
112
+
113
+ if (summary.passed == summary.total) {
114
+ phantom.exit();
115
+ } else {
116
+ phantom.exit(1);
117
+ }
118
+ });
119
+ }
120
+
121
+ });
@@ -0,0 +1,18 @@
1
+ namespace :jasmine do
2
+ namespace :phantom do
3
+ desc "Run jasmine specs using phantomjs and report the results"
4
+ task :ci => "jasmine:require" do
5
+ jasmine_config_overrides = File.join(Jasmine::Config.new.project_root, 'spec', 'javascripts' ,'support' ,'jasmine_config.rb')
6
+ require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
7
+
8
+ config = Jasmine::Config.new
9
+ config.start_jasmine_server
10
+
11
+ # omg config.jasmine_port finds a new unused port every time!
12
+ port = config.instance_variable_get :@jasmine_server_port
13
+
14
+ script = File.join File.dirname(__FILE__), 'run-jasmine.js'
15
+ sh "phantomjs #{script} http://localhost:#{port}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Jasmine
2
+ module Phantom
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jasmine-phantom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Vollbracht
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2153382420 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2153382420
25
+ - !ruby/object:Gem::Dependency
26
+ name: jasmine
27
+ requirement: &2153381920 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.0rc2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2153381920
36
+ description: ! "jasmine-phantom provides a rake task, jasmine:phantom:ci,\n that
37
+ runs your jasmine specs via the phantomjs browser just as if you had\n run
38
+ rake jasmine and run them manually via your browser.\n\n You
39
+ need to have phantomjs installed and in your PATH for the rake task to work"
40
+ email:
41
+ - david@flipstone.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - README.markdown
49
+ - Rakefile
50
+ - jasmine-phantom.gemspec
51
+ - lib/jasmine-phantom.rb
52
+ - lib/jasmine-phantom/railtie.rb
53
+ - lib/jasmine-phantom/run-jasmine.js
54
+ - lib/jasmine-phantom/tasks.rake
55
+ - lib/jasmine-phantom/version.rb
56
+ homepage: http://github.com/flipstone/jasmine-phantom
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: jasmine-phantom
76
+ rubygems_version: 1.8.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Run you jasmine specs from the commant line using phantomjs
80
+ test_files: []