rspec_runner 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f53daae848dfe791940da70582763099d84fb014
4
- data.tar.gz: 1be24fbdc7fbb1f91aa125a62174beee0fd6a7a7
3
+ metadata.gz: 6537a01d0edf8244bee0f8e8c1561950e92260a2
4
+ data.tar.gz: a6b5dde3a76f11d61f30b2f593ff3a8dc9674e31
5
5
  SHA512:
6
- metadata.gz: b0106b07a621099d30ef228ed722fd7580a33931928d726c4efd4cf9837a8a50c3cd83aba37135ad716f916b74e117cfdf6ac3fa424286b76414b62d916135f8
7
- data.tar.gz: 82c077d5c2ea9641dcbf7ee32bba3d353bc9fa8da1f51fb40c26cd2a8e334251e366b9666eeb6f6ee09cb9c12553b29355b0cd4a8c938e30d5f38225c82a2b7e
6
+ metadata.gz: 8d260b1df5d8ffc2ff71d0df28a912ac37b532a220c15315cbbbbc6afa23aff2eb7776f4cc388f65b8e1bc23d8ffefea67353a4674d067f949f4213e2dbfdb5e
7
+ data.tar.gz: 6b4aee0adc08c8b15f80bfa52066be7c2dc73b29935e8c8cd8c57822eab882d9e15335754861fd48000e1bbce3cd32b8cd2955ffeb2d71c61cee0b751ba2cfcd
data/README.md CHANGED
@@ -37,6 +37,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
37
37
 
38
38
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec_runner. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
39
39
 
40
+ ## TODO
41
+
42
+ * Try to kill a process without `kill -9`
43
+ * Make it configurable
44
+ * Add tests!
45
+ * Speedup client
40
46
 
41
47
  ## License
42
48
 
data/bin/rspec_runner CHANGED
@@ -6,9 +6,6 @@ case cmd
6
6
  when 'monitor'.freeze
7
7
  require 'rspec_runner/monitor'
8
8
  RspecRunner::Monitor.run
9
- when 'start'.freeze
10
- require 'rspec_runner/server'
11
- RspecRunner::Server.run
12
9
  else
13
10
  require 'rspec_runner/client'
14
11
  RspecRunner::Client.execute(cmd)
@@ -6,12 +6,16 @@ module RspecRunner
6
6
  class << self
7
7
  def execute(*args)
8
8
  DRb.start_service
9
- runner = DRbObject.new_with_uri(RspecRunner.configuration.uri)
10
-
11
9
  try_count = 0
12
- print 'Running tests... '
13
- while try_count <= RspecRunner.configuration.client_timeout
10
+ print 'Connecting... '
11
+
12
+ while try_count < RspecRunner.configuration.client_timeout
14
13
  begin
14
+ uri = fetch_uri
15
+ raise DRb::DRbConnError unless uri
16
+
17
+ runner = DRbObject.new_with_uri(uri)
18
+ print 'running... '
15
19
  runner.execute(*args)
16
20
  puts 'done!'
17
21
  return true
@@ -23,6 +27,12 @@ module RspecRunner
23
27
 
24
28
  puts 'Server is down :('
25
29
  end
30
+
31
+ private
32
+
33
+ def fetch_uri
34
+ File.read(RspecRunner.configuration.uri_filepath) if File.exist?(RspecRunner.configuration.uri_filepath)
35
+ end
26
36
  end
27
37
  end
28
38
  end
@@ -1,10 +1,10 @@
1
1
  module RspecRunner
2
2
  class Configuration
3
- attr_accessor :uri, :client_timeout, :watch_directories, :watch_pattern, :ignore_pattern
3
+ attr_accessor :uri_filepath, :client_timeout, :watch_directories, :watch_pattern, :ignore_pattern
4
4
 
5
5
  def initialize
6
- @uri = 'druby://localhost:8787'.freeze
7
- @client_timeout = 10 # seconds
6
+ @uri_filepath = "#{Dir.pwd}/tmp/rspec_runner"
7
+ @client_timeout = 60 # seconds
8
8
  @watch_directories = ["#{Dir.pwd}"]
9
9
  @watch_pattern = /\.rb$/
10
10
  @ignore_pattern = /spec\/.+_spec\.rb$/
@@ -1,4 +1,5 @@
1
1
  require 'open3'
2
+ require 'rspec_runner/server'
2
3
  require 'rspec_runner/watcher'
3
4
 
4
5
  module RspecRunner
@@ -23,13 +24,15 @@ module RspecRunner
23
24
  private
24
25
 
25
26
  def start
26
- @pid = fork { exec(CMD) }
27
+ @pid = fork { RspecRunner::Server.run }
27
28
  Process.detach(@pid) # so if the child exits, it dies
28
29
  end
29
30
 
30
31
  def stop
31
32
  if @pid && @pid != 0
32
- send_signal('KILL') # TODO: try to kill without -9
33
+ # TODO: try to kill without -9
34
+ send_signal('KILL')
35
+ RspecRunner::Server.stop
33
36
  end
34
37
  end
35
38
 
@@ -1,3 +1,4 @@
1
+ require 'socket'
1
2
  require 'drb/drb'
2
3
  require 'rspec_runner/configuration'
3
4
 
@@ -11,9 +12,11 @@ module RspecRunner
11
12
  require 'rspec'
12
13
  require 'spec_helper.rb'
13
14
 
14
- DRb.start_service(RspecRunner.configuration.uri, self)
15
+ DRb.start_service(assign_uri, self)
15
16
  puts 'Server started!'
16
17
 
18
+ at_exit { stop }
19
+
17
20
  DRb.thread.join
18
21
  end
19
22
 
@@ -24,8 +27,25 @@ module RspecRunner
24
27
  reset_rspec!
25
28
  end
26
29
 
30
+ def stop
31
+ File.delete(RspecRunner.configuration.uri_filepath) if File.exist?(RspecRunner.configuration.uri_filepath)
32
+ end
33
+
27
34
  private
28
35
 
36
+ def assign_uri
37
+ socket = Socket.new(:INET, :STREAM, 0)
38
+ socket.bind(Addrinfo.tcp('127.0.0.1'.freeze, 0))
39
+ free_port = socket.local_address.ip_port
40
+ uri = "druby://localhost:#{free_port}"
41
+
42
+ dirname = File.dirname(RspecRunner.configuration.uri_filepath)
43
+ FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
44
+ File.write(RspecRunner.configuration.uri_filepath, uri)
45
+
46
+ uri
47
+ end
48
+
29
49
  def filepaths(path)
30
50
  multiple_files?(path) ? Dir.glob(path) : [path]
31
51
  end
@@ -1,3 +1,3 @@
1
1
  module RspecRunner
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - exAspArk