spring-commands-opal-rspec 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ff49f01bbfaa75a64c6116f20bc20bb585f2e09
4
+ data.tar.gz: 7e20d83d4ea56c3c4179311b34592f3f5d6bcf1b
5
+ SHA512:
6
+ metadata.gz: 1e21e6ee26b7225eb525eeb6d2284874a807de58940868f4eb9095ed875ec02ca79eb6c6bfcbb63fb2848827e0bb858ed5565e246ec5902bf4bfb38df43ddccc
7
+ data.tar.gz: ad4ef9640b7a73c67a7ad2f1f27b764e5b9d0601ff3cf7f70f829caf4b7804857fd308f3f4c3656e5cbe7f2579b8bfa8d753e5b974219cfa4077dd46c5d55309
@@ -0,0 +1,40 @@
1
+ require 'spring/application'
2
+
3
+ # Out of the box, there is no way to send any state back from a command to the application class
4
+ # We spin up another server process that needs to be terminated when the app process terminates
5
+ module Spring
6
+ class Application
7
+ def setup(command_wrapper)
8
+ setup = if command_wrapper.command.is_a?(Spring::Commands::OpalRSpec)
9
+ pid = command_wrapper.command.setup
10
+ @opal_rspec_pid ||= pid
11
+ else
12
+ command_wrapper.setup
13
+ end
14
+ if setup
15
+ watcher.add loaded_application_features # loaded features may have changed
16
+ end
17
+ end
18
+
19
+ alias_method :stock_terminate, :terminate
20
+
21
+ def kill_opal_process
22
+ if @opal_rspec_pid
23
+ log "terminating opal-rspec PID #{@opal_rspec_pid}"
24
+ Process.kill 'TERM', @opal_rspec_pid
25
+ end
26
+ end
27
+
28
+ def terminate
29
+ kill_opal_process
30
+ stock_terminate
31
+ end
32
+
33
+ alias_method :stock_exit, :exit
34
+
35
+ def exit
36
+ kill_opal_process
37
+ stock_exit
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ require 'spring/commands/opal_rspec'
2
+ require 'rack'
3
+ require 'webrick'
4
+ require File.expand_path('config/environment', ENV['RAILS_ROOT'])
5
+
6
+ pattern = ENV['PATTERN'] || (::Rails.application.config.opal.spec_location+'/**/*_spec{,.js}.{rb,opal}')
7
+ sprockets_env = Opal::RSpec::SprocketsEnvironment.new(spec_pattern = pattern)
8
+ app = Opal::Server.new(sprockets: sprockets_env) { |s|
9
+ s.main = 'opal/rspec/sprockets_runner'
10
+ s.debug = false
11
+
12
+ ::Rails.application.assets.paths.each { |p| s.append_path p }
13
+ }
14
+ sprockets_env.add_spec_paths_to_sprockets
15
+ app_name = ::Spring::Env.new.app_name
16
+
17
+ Spring::ProcessTitleUpdater.run { |distance|
18
+ "spring app | #{app_name} | started #{distance} ago | opal-rspec mode"
19
+ }
20
+
21
+ Rack::Server.start(
22
+ :app => app,
23
+ :Port => Spring::Commands::OpalRSpec::PORT,
24
+ :AccessLog => [],
25
+ :Logger => WEBrick::Log.new("/dev/null"),
26
+ )
@@ -0,0 +1,89 @@
1
+ require 'spring/commands'
2
+ require 'opal/rspec/rake_task'
3
+ require 'spring/application_opal'
4
+
5
+ module Spring
6
+ module Commands
7
+ class OpalRSpec
8
+ def env(*)
9
+ 'test'
10
+ end
11
+
12
+ def setup
13
+ unless server_running?
14
+ start_server
15
+ end
16
+ end
17
+
18
+ def call
19
+ wait_for_server
20
+ launch_phantom
21
+ end
22
+
23
+ PORT = 9999
24
+ URL = "http://localhost:#{PORT}/"
25
+
26
+ def launch_phantom(timeout_value=nil)
27
+ rspec_path = Gem.loaded_specs['opal-rspec'].full_gem_path
28
+ runner_path = File.join(rspec_path, 'vendor/spec_runner.js')
29
+
30
+ if `phantomjs -v`.strip.to_i >= 2
31
+ warn <<-WARN.gsub(/^ /, '')
32
+ Only PhantomJS v1 is currently supported,
33
+ if you're using homebrew on OSX you can switch version with:
34
+
35
+ brew switch phantomjs 1.9.8
36
+
37
+ WARN
38
+ exit 1
39
+ end
40
+ command_line = %Q{phantomjs #{runner_path} "#{URL}"#{timeout_value ? " #{timeout_value}" : ''}}
41
+ puts "Running #{command_line}"
42
+ system command_line
43
+ success = $?.success?
44
+ exit 1 unless success
45
+ end
46
+
47
+ def start_server
48
+ Process.spawn({
49
+ 'RAILS_ROOT' => ::Rails.root.to_s
50
+ },
51
+ 'ruby',
52
+ '-I',
53
+ File.expand_path('../..', __FILE__),
54
+ '-e',
55
+ 'require "spring/commands/opal_rack_boot"')
56
+ end
57
+
58
+ def server_running?
59
+ uri = URI(URL)
60
+ begin
61
+ socket = TCPSocket.new uri.hostname, uri.port
62
+ socket.close
63
+ true
64
+ rescue Errno::ECONNREFUSED
65
+ false
66
+ end
67
+ end
68
+
69
+ def wait_for_server
70
+ # avoid retryable dependency
71
+ tries = 0
72
+ up = false
73
+ max_tries = 50
74
+ while tries < max_tries && !up
75
+ tries += 1
76
+ sleep 0.1
77
+ up = server_running?
78
+ end
79
+ raise "Tried #{max_tries} times to contact Rack server and not up!" unless up
80
+ end
81
+
82
+ def description
83
+ 'Execute opal::rspec tests'
84
+ end
85
+ end
86
+
87
+ Spring.register_command 'opal-rspec', OpalRSpec.new
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ module Spring
2
+ module Commands
3
+ class OpalRSpec
4
+ VERSION = '1.0.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ if defined?(Spring.register_command)
2
+ require 'spring/commands/opal_rspec'
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spring-commands-opal-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brady Wied
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opal-rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0.beta3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0.beta3
27
+ - !ruby/object:Gem::Dependency
28
+ name: opal-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: spring
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Allows the opal-rspec Rake task to run faster by keeping the PhantomJS
84
+ process running in the background
85
+ email: brady@bswtechconsulting.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/spring-commands-opal-rspec.rb
91
+ - lib/spring/application_opal.rb
92
+ - lib/spring/commands/opal_rack_boot.rb
93
+ - lib/spring/commands/opal_rspec.rb
94
+ - lib/spring/commands/version.rb
95
+ homepage: https://github.com/wied03/spring-commands-orspec
96
+ licenses: []
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Adds spring support to opal-rspec
118
+ test_files: []