phantom_jasmine 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format Fuubar
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
data/Gemfile CHANGED
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in phantom_jasmine.gemspec
4
4
  gemspec
5
5
 
6
- gem 'jasmine', git: 'git://github.com/pivotal/jasmine-gem.git', ref: '479dccb62f9e6ffc7600b65d24df77ac1bdde403'
6
+ gem 'jasmine', :git => 'git://github.com/pivotal/jasmine-gem.git', :ref => '479dccb62f9e6ffc7600b65d24df77ac1bdde403'
7
7
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new 'spec'
5
+
6
+ task :default => :spec
@@ -1,6 +1,7 @@
1
1
  require 'facter'
2
+ require 'jasmine'
2
3
  require 'tempfile'
3
- require 'phantomjs-mac' if RUBY_PLATFORM.downcase.include?('darwin')
4
+ require 'phantomjs.rb'
4
5
 
5
6
  class Jasmine::Runners::Phantom
6
7
  attr_accessor :suites
@@ -9,6 +10,7 @@ class Jasmine::Runners::Phantom
9
10
  @port = port
10
11
  @results_processor = results_processor
11
12
  @result_batch_size = result_batch_size
13
+ @phantom = Phantomjs.send(:get_executable)
12
14
  end
13
15
 
14
16
  def run
@@ -20,7 +22,7 @@ class Jasmine::Runners::Phantom
20
22
 
21
23
  def load_suite_info
22
24
  tmpfile = Tempfile.new('count')
23
- pid = Process.spawn "#{Phantomjs.executable_path} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_count.js')}' #{@port}", :out => tmpfile.path
25
+ pid = Process.spawn "#{@phantom} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_count.js')}' #{@port}", :out => tmpfile.path
24
26
  Process.wait pid
25
27
  json = JSON.parse(tmpfile.read, :max_nesting => 100).tap { tmpfile.close }
26
28
  @suites = json['suites']
@@ -30,7 +32,7 @@ class Jasmine::Runners::Phantom
30
32
  def run_suites(suites)
31
33
  tmpfile = Tempfile.new('run')
32
34
  commands = suites.map do |suite|
33
- "#{Phantomjs.executable_path} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_run.js')}' #{@port} '#{suite['description']}'"
35
+ "#{@phantom} '#{File.join(File.dirname(__FILE__), 'phantom_jasmine_run.js')}' #{@port} '#{suite['description']}'"
34
36
  end.join(';echo ,;')
35
37
 
36
38
  pid = Process.spawn "echo [;#{commands};echo ]", :out => tmpfile.path
@@ -39,7 +41,6 @@ class Jasmine::Runners::Phantom
39
41
 
40
42
  def results_hash
41
43
  spec_results = {}
42
-
43
44
  @top_level_suites.group_by { |suite| suite['id'] % processor_count }.map { |(k, suites)| run_suites(suites) }.each do |pid, tmpfile|
44
45
  Process.wait pid
45
46
 
@@ -57,7 +58,7 @@ class Jasmine::Runners::Phantom
57
58
 
58
59
  def processor_count
59
60
  @processor_count ||= begin
60
- ENV['JASMINE_PARALLEL_COUNT'] || [Facter.sp_number_processors.to_i, 4].min
61
+ ENV['JASMINE_PARALLEL_COUNT'] || Facter.processorcount
61
62
  end.to_i
62
63
  end
63
64
  end
@@ -1,14 +1,12 @@
1
1
  (function() {
2
- var port = phantom.args[0];
3
- var filter = phantom.args[1];
2
+ var port = phantom.args[0], filter = phantom.args[1];
4
3
 
5
4
  if (!parseInt(port, 10) || phantom.args.length > 2) {
6
5
  console.log('Usage: run-jasmine.js PORT [spec_name_filter]');
7
6
  phantom.exit(1);
8
7
  }
9
8
 
10
- var page = require('webpage').create();
11
- var fs = require('fs');
9
+ var page = require('webpage').create(), fs = require('fs');
12
10
 
13
11
  var url = 'http://localhost:' + port;
14
12
  if (filter) {
@@ -21,16 +19,18 @@
21
19
  phantom.exit(1);
22
20
  } else {
23
21
  var json = page.evaluate(function() {
24
- var jasmineEnv = {
22
+ var topLevelSuites = [], suites = jasmine.getEnv().currentRunner().topLevelSuites();
23
+ for (var i = 0; i < suites.length; i++) {
24
+ var suite = suites[i];
25
+ topLevelSuites.push({
26
+ id: suite.id,
27
+ description: suite.description
28
+ });
29
+ }
30
+ return JSON.stringify({
25
31
  suites: jsApiReporter.suites(),
26
- top_level_suites: jasmine.getEnv().currentRunner().topLevelSuites().map(function(suite) {
27
- return {
28
- id: suite.id,
29
- description: suite.description
30
- };
31
- })
32
- };
33
- return JSON.stringify(jasmineEnv);
32
+ top_level_suites: topLevelSuites
33
+ });
34
34
  });
35
35
  fs.write('/dev/stdout', json, 'w');
36
36
  phantom.exit(0);
@@ -72,9 +72,10 @@
72
72
  });
73
73
  }, function() {
74
74
  var json = page.evaluate(function() {
75
- var specIds = _(jasmine.getEnv().currentRunner().specs()).map(function(spec) {
76
- return spec.id;
77
- });
75
+ var specIds = [], specs = jasmine.getEnv().currentRunner().specs();
76
+ for (var i = 0; i < specs.length; i++) {
77
+ specIds.push(specs[i].id);
78
+ }
78
79
  return JSON.stringify(jsApiReporter.resultsForSpecs(specIds));
79
80
  });
80
81
  fs.write('/dev/stdout', json, 'w');
@@ -21,7 +21,7 @@ server = Jasmine::Server.new(port, Jasmine::Application.app(config))
21
21
  t = Thread.new do
22
22
  begin
23
23
  server.start
24
- rescue ChildProcess::TimeoutError
24
+ rescue
25
25
  end
26
26
  # # ignore bad exits
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module PhantomJasmine
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,9 +1,13 @@
1
1
  require 'phantom_jasmine/version'
2
+ require 'jasmine/runners/phantom'
2
3
 
3
4
  module PhantomJasmine
4
- class Railtie < ::Rails::Railtie
5
- rake_tasks do
6
- load 'tasks/phantom_jasmine.rake'
5
+ begin
6
+ class Railtie < ::Rails::Railtie
7
+ rake_tasks do
8
+ load 'tasks/phantom_jasmine.rake'
9
+ end
7
10
  end
11
+ rescue LoadError, NameError
8
12
  end
9
13
  end
@@ -17,9 +17,18 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.extensions = ['ext/mkrf_conf.rb']
21
-
22
20
  gem.add_dependency %q{jasmine}, '>= 1.2'
23
21
  gem.add_dependency %q{facter}, '>= 1.6.17'
24
- gem.add_dependency %q{phantomjs-mac}, '>= 0.0.3'
22
+ gem.add_dependency %q{phantomjs.rb}, '>= 0.0.5'
23
+
24
+ gem.add_development_dependency %q{json}
25
+ gem.add_development_dependency %q{rspec}, '>= 2.13.0'
26
+ gem.add_development_dependency %q{fuubar}
27
+ gem.add_development_dependency %q{rake}
28
+
29
+ if RUBY_PLATFORM =~ /linux/
30
+ gem.add_runtime_dependency 'phantomjs-linux'
31
+ elsif RUBY_PLATFORM =~ /darwin/
32
+ gem.add_runtime_dependency 'phantomjs-mac'
33
+ end
25
34
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine::Runners::Phantom do
4
+ let!(:port) { 8888 }
5
+ let!(:results_processor) do
6
+ mock('results_processor').tap do |processor|
7
+ processor.stub :process
8
+ end
9
+ end
10
+ let!(:result_batch_size) { Object.new }
11
+
12
+ subject do
13
+ Jasmine::Runners::Phantom.new port, results_processor, result_batch_size
14
+ end
15
+
16
+ describe '#run' do
17
+ let(:messages) { {'messages' => [{'passed' => true, 'type' => 'expect', 'message' => 'Passed.', 'trace' => {}}]} }
18
+ let(:describe1) do
19
+ {'id' => 1, 'description' => 'foo'}
20
+ end
21
+
22
+ let(:describe2) do
23
+ {'id' => 2, 'description' => 'bar'}
24
+ end
25
+
26
+ let(:json) do
27
+ {
28
+ 'top_level_suites' => [describe1],
29
+ 'suites' => [describe1, describe2]
30
+ }
31
+ end
32
+
33
+ let(:tempfile) do
34
+ mock('tempfile').tap do |f|
35
+ f.should_receive(:read).and_return(describe1)
36
+ f.should_receive(:close)
37
+ end
38
+ end
39
+
40
+ before do
41
+ Process.should_receive :spawn
42
+ Process.should_receive :wait
43
+ end
44
+
45
+ describe '#load_suite_info' do
46
+ before do
47
+ JSON.should_receive(:parse).and_return json
48
+ subject.should_receive(:results_hash).and_return {}
49
+ subject.run
50
+ end
51
+ its(:suites) do
52
+ should == [describe1, describe2]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'phantom_jasmine'
4
+
5
+ ENV["RAILS_ENV"] ||= 'test'
6
+
7
+ RSpec.configure do |config|
8
+
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phantom_jasmine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-25 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jasmine
@@ -43,6 +43,86 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 1.6.17
46
+ - !ruby/object:Gem::Dependency
47
+ name: phantomjs.rb
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.5
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.5
62
+ - !ruby/object:Gem::Dependency
63
+ name: json
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.13.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.13.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: fuubar
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rake
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
46
126
  - !ruby/object:Gem::Dependency
47
127
  name: phantomjs-mac
48
128
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +130,7 @@ dependencies:
50
130
  requirements:
51
131
  - - ! '>='
52
132
  - !ruby/object:Gem::Version
53
- version: 0.0.3
133
+ version: '0'
54
134
  type: :runtime
55
135
  prerelease: false
56
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,23 +138,23 @@ dependencies:
58
138
  requirements:
59
139
  - - ! '>='
60
140
  - !ruby/object:Gem::Version
61
- version: 0.0.3
141
+ version: '0'
62
142
  description: Adds a new rake task jasmine:phantom that runs specs in parallel using
63
143
  phantoms js.
64
144
  email:
65
145
  - ryan.dy@gmail.com
66
146
  executables: []
67
- extensions:
68
- - ext/mkrf_conf.rb
147
+ extensions: []
69
148
  extra_rdoc_files: []
70
149
  files:
71
150
  - .gitignore
151
+ - .rspec
72
152
  - .rvmrc
153
+ - .travis.yml
73
154
  - Gemfile
74
155
  - LICENSE.txt
75
156
  - README.md
76
157
  - Rakefile
77
- - ext/mkrf_conf.rb
78
158
  - lib/jasmine/runners/phantom.rb
79
159
  - lib/jasmine/runners/phantom_jasmine_count.js
80
160
  - lib/jasmine/runners/phantom_jasmine_run.js
@@ -83,6 +163,8 @@ files:
83
163
  - lib/phantom_jasmine/version.rb
84
164
  - lib/tasks/phantom_jasmine.rake
85
165
  - phantom_jasmine.gemspec
166
+ - spec/lib/runners/phantom_spec.rb
167
+ - spec/spec_helper.rb
86
168
  homepage: https://github.com/rdy/phantom_jasmine
87
169
  licenses: []
88
170
  post_install_message:
@@ -95,16 +177,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
177
  - - ! '>='
96
178
  - !ruby/object:Gem::Version
97
179
  version: '0'
180
+ segments:
181
+ - 0
182
+ hash: 87089693277479132
98
183
  required_rubygems_version: !ruby/object:Gem::Requirement
99
184
  none: false
100
185
  requirements:
101
186
  - - ! '>='
102
187
  - !ruby/object:Gem::Version
103
188
  version: '0'
189
+ segments:
190
+ - 0
191
+ hash: 87089693277479132
104
192
  requirements: []
105
193
  rubyforge_project:
106
- rubygems_version: 1.8.21
194
+ rubygems_version: 1.8.24
107
195
  signing_key:
108
196
  specification_version: 3
109
197
  summary: an extension for running jasmine with phantom js in parallel
110
- test_files: []
198
+ test_files:
199
+ - spec/lib/runners/phantom_spec.rb
200
+ - spec/spec_helper.rb
data/ext/mkrf_conf.rb DELETED
@@ -1,22 +0,0 @@
1
- require 'rubygems'
2
- require 'rubygems/command.rb'
3
- require 'rubygems/dependency_installer.rb'
4
-
5
- begin
6
- Gem::Command.build_args = ARGV
7
- rescue NoMethodError
8
- end
9
- inst = Gem::DependencyInstaller.new
10
- begin
11
- if RUBY_PLATFORM.downcase.include? 'darwin'
12
- inst.install 'phantomjs-mac', '>= 0.0.3'
13
- end
14
- rescue
15
- #Exit with a non-zero value to let rubygems know something went wrong
16
- exit(1)
17
- end
18
-
19
- # create dummy rakefile to indicate success
20
- f = File.open(File.join(File.dirname(__FILE__), 'Rakefile'), 'w')
21
- f.write("task :default\n")
22
- f.close