spectator 1.3.0 → 1.3.1

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: cc53eefa112ce5dd549660142e9691fec2b7147e
4
- data.tar.gz: be808d5963f8a0878c6cd51b0f6ef8dc2e4a4578
3
+ metadata.gz: 8224d0dbd81297094686627e2c57a002ee6ebb10
4
+ data.tar.gz: d03578fac43dec450fca0c13e9710ffc2e04fde8
5
5
  SHA512:
6
- metadata.gz: b3e3a241bb6569789aac25566d109e99330a07bf82021809e8f592d3138afd31e57b2f69e71b097d8037cf3486a4162ea6cd6a227dd01781548af11dfa3e668b
7
- data.tar.gz: 80aff3fe557a50be933613d3977b8b7dc822d4933eb4adbe3eecf217aff9267e84c211fa0c7e5fad46f77c243a7a9719888eaa5d1418cc9c5592c875a9873b45
6
+ metadata.gz: ccc07eaab375e7ca4ed446a9780db3ab3b235d92ff220aa4f1ca9579199facdbd28e1bb074fe059412ae35240b4e7b8f1defd288ca32e0297ca4524762650b6a
7
+ data.tar.gz: db74db3619284f9641f06241d7cc12408ea793d1899a8ee471aa6142af89bae64e8cb5f612477c4ef18dc56175bb6374153f5f10060bc69aa267a523e1d1b09c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Spectator
2
2
 
3
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/elia/spectator)
3
+ [![Code Climate](http://img.shields.io/codeclimate/github/kabisaict/flow.svg)](https://codeclimate.com/github/elia/spectator)
4
4
 
5
5
  _Test driven development red-green cycle for simple people!_
6
6
 
data/lib/spectator.rb CHANGED
@@ -54,41 +54,44 @@ module Spectator
54
54
  path_watcher.on_change { ui << :run_specs }
55
55
  path_watcher.watch_paths!
56
56
 
57
- ui.on(:run_specs) do
58
- next unless ui.can_run_specs?
59
- ui.status = :running_specs
60
- files = path_watcher.pop_files
61
- specs = specs_matcher.specs_for(files)
62
- if specs.any?
63
- result = ui.run spec_runner.command(specs)
64
- success_notifier.notify(result)
65
- end
66
- ui.wait_for_changes
67
- end
68
-
69
- ui.on(:interrupt) do
70
- puts ' (Interrupted with CTRL+C)'.red
71
- p [ui.status, ui.interrupted_status]
72
- case ui.interrupted_status
73
- when :wait_for_input then ui.exit
74
- when :running_specs then ui.wait_for_changes
75
- when :exiting then Kernel.abort
76
- else Thread.new { ui.ask_what_to_do }
77
- end
78
- end
57
+ ui.on(:run_all) { run_all_handler }
58
+ ui.on(:run_specs) { run_specs_handler }
59
+ ui.on(:interrupt) { interrupt_handler }
79
60
 
80
61
  trap('INT') { ui.interrupt! }
62
+ ui.start
63
+ end
81
64
 
82
- ui.on(:run_all) do
83
- next unless ui.can_run_specs?
65
+ def run_all_handler
66
+ return unless ui.can_run_specs?
84
67
 
85
- ui.status = :running_specs
86
- result = ui.run(spec_runner.command)
68
+ ui.status = :running_specs
69
+ result = ui.run(spec_runner.command)
70
+ success_notifier.notify(result)
71
+ ui.status = nil if ui.status == :running_specs
72
+ end
73
+
74
+ def run_specs_handler
75
+ return unless ui.can_run_specs?
76
+ ui.status = :running_specs
77
+ files = path_watcher.pop_files
78
+ specs = specs_matcher.specs_for(files)
79
+ if specs.any?
80
+ result = ui.run spec_runner.command(specs)
87
81
  success_notifier.notify(result)
88
- ui.status = nil if ui.status == :running_specs
89
82
  end
83
+ ui.wait_for_changes
84
+ end
90
85
 
91
- ui.start
86
+ def interrupt_handler
87
+ puts ' (Interrupted with CTRL+C)'.red
88
+ p [ui.status, ui.interrupted_status]
89
+ case ui.interrupted_status
90
+ when :wait_for_input then ui.exit
91
+ when :running_specs then ui.wait_for_changes
92
+ when :exiting then Kernel.abort
93
+ else Thread.new { ui.ask_what_to_do }
94
+ end
92
95
  end
93
96
  end
94
97
 
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'notify'
2
3
 
3
4
  module Spectator
data/lib/spectator/ui.rb CHANGED
@@ -6,7 +6,6 @@ module Spectator
6
6
  class UI
7
7
  def initialize(config)
8
8
  @mutex = Mutex.new
9
- @status_mutex = Mutex.new
10
9
  @status = nil
11
10
  @status_callbacks = {}
12
11
  @callbacks = {}
@@ -19,30 +18,14 @@ module Spectator
19
18
  end
20
19
 
21
20
  def start
22
- queue = @queue
23
- mutex = @mutex
24
-
25
- thread = Thread.new do
26
- loop do
27
- wait_for_changes
28
- event = queue.pop
29
- p [:queue, event]
30
- mutex.synchronize { @callbacks[event].call }
31
- end
32
- end
21
+ wait_for_changes
22
+ thread = Thread.new { event_loop }
33
23
  p thread
34
24
  Thread.pass
35
25
  sleep
36
26
  end
37
27
 
38
- attr_reader :status
39
-
40
- def status= status
41
- @status_mutex.synchronize do
42
- @status = status
43
- (@status_callbacks[status] || noop).call
44
- end
45
- end
28
+ attr_accessor :status
46
29
 
47
30
  def noop
48
31
  @noop ||= lambda {}
@@ -55,10 +38,6 @@ module Spectator
55
38
 
56
39
  attr_accessor :interrupted_status
57
40
 
58
- def on_status status, &block
59
- @status_callbacks[status] = block
60
- end
61
-
62
41
  def on event, &block
63
42
  @callbacks[event] = block
64
43
  end
@@ -98,11 +77,6 @@ module Spectator
98
77
  super
99
78
  end
100
79
 
101
- def terminal_columns
102
- cols = `stty -a 2>&1`.scan(/ (\d+) columns/).flatten.first
103
- $?.success? ? cols.to_i : 80
104
- end
105
-
106
80
  def run cmd
107
81
  $running = true
108
82
  start = Time.now
@@ -118,5 +92,22 @@ module Spectator
118
92
  p [:can_run_specs?, status]
119
93
  status == :waiting_for_changes
120
94
  end
95
+
96
+
97
+ private
98
+
99
+ def terminal_columns
100
+ cols = `tput cols 2> /dev/tty`.strip.to_i
101
+ ($?.success? && cols.nonzero?) ? cols : 80
102
+ end
103
+
104
+ def event_loop
105
+ loop do
106
+ event = @queue.pop
107
+ p [:queue, event]
108
+ @mutex.synchronize { @callbacks[event].call }
109
+ end
110
+ end
111
+
121
112
  end
122
113
  end
@@ -1,3 +1,3 @@
1
1
  module Spectator
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
@@ -1,13 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'spectator'
3
3
 
4
- $spectator_debug = true
5
-
6
- describe Spectator do
7
- it 'does something' do
8
- #nope
9
- end
10
- end
4
+ # $spectator_debug = true
11
5
 
12
6
  describe Spectator::SpecRunner do
13
7
  let(:config) { Spectator.config }
@@ -18,5 +12,4 @@ describe Spectator::SpecRunner do
18
12
  expect(runner.default_files).to eq(['spec'])
19
13
  end
20
14
  end
21
-
22
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-30 00:00:00.000000000 Z
12
+ date: 2014-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: listen