rspec-interactive 0.9.8 → 0.9.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 895c315e10777f7d94c8efdf005129bb532463b31d764af1ddd079692b3e0e62
4
- data.tar.gz: 264d523cfc32ffab312ef3d9323611c05f00d851d755d5cf53735680eac0ce4a
3
+ metadata.gz: c87a284feb4bf76bac68cda8cbe5703a66f04a856c8e2aed9e27d30b89e2654e
4
+ data.tar.gz: 9336d2bff3ba1973921f8d7ba6a36d88bc11d4acd1c2b2ee86d7c47cb58d0356
5
5
  SHA512:
6
- metadata.gz: 47ca24fe9e49e7ea070c62b3786d72232cb52eabc2faac4777b913099c515a4cb9a0eaeb2515ab204637c344824461fcfdc6e3a460082ca1384bf57d2e04e773
7
- data.tar.gz: f7d35eb450b116bb275eac5eaf729d37af936464e18ce9015d3bea953b6204517212299c923eb9e114182b120df3ad3868112be716bd9bd20d6de2c2c8c6326d
6
+ metadata.gz: 36afe559f97bc7cdee9e6833655f23e6092004b800e53beed28099afb8db6ce5511bc8177c9cc648ffc0a558bd221ca2ff13c5ff44e76132c20af99b30281fda
7
+ data.tar.gz: '097084b7f1fec026f08433a8d12d56997b83a8deb8852026fc04dc1f3e7ec5410433e0758b374724cb2b5450f7b5be4e4db2d9953241a7bbd703f610f032e6ef'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-interactive (0.9.7)
4
+ rspec-interactive (0.9.8)
5
5
  listen
6
6
  pry
7
7
  rspec-core
@@ -18,6 +18,13 @@ module RSpec
18
18
  def print(str = "")
19
19
  @string += str.to_s
20
20
  end
21
+
22
+ def flush
23
+ end
24
+
25
+ def closed?
26
+ @client.closed?
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -0,0 +1,33 @@
1
+ module RSpec
2
+ module Interactive
3
+ class ThreadedOutput
4
+ attr_reader :string
5
+
6
+ def initialize(thread_map:, default:)
7
+ @thread_map = thread_map
8
+ @default = default
9
+ @string = ''
10
+ end
11
+
12
+ def write(name, str = "")
13
+ (@thread_map[Thread.current] || @default).write(name, str)
14
+ end
15
+
16
+ def puts(str = "")
17
+ (@thread_map[Thread.current] || @default).puts(str)
18
+ end
19
+
20
+ def print(str = "")
21
+ (@thread_map[Thread.current] || @default).puts(str)
22
+ end
23
+
24
+ def flush
25
+ (@thread_map[Thread.current] || @default).flush
26
+ end
27
+
28
+ def closed?
29
+ (@thread_map[Thread.current] || @default).closed?
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Interactive
5
- VERSION = "0.9.8"
5
+ VERSION = "0.9.9"
6
6
  end
7
7
  end
@@ -19,6 +19,7 @@ require 'rspec-interactive/rubo_cop_command'
19
19
  require 'rspec-interactive/runner'
20
20
  require 'rspec-interactive/stdio'
21
21
  require 'rspec-interactive/string_output'
22
+ require 'rspec-interactive/threaded_output'
22
23
 
23
24
  module RSpec
24
25
  module Interactive
@@ -47,7 +48,7 @@ module RSpec
47
48
  @updated_files = []
48
49
  @stty_save = %x`stty -g`.chomp
49
50
  @file_change_mutex = Mutex.new
50
- @command_mutex = Mutex.new
51
+ @rspec_mutex = Mutex.new
51
52
  @output_stream = output_stream
52
53
  @input_stream = input_stream
53
54
  @error_stream = error_stream
@@ -61,21 +62,38 @@ module RSpec
61
62
  configure_pry
62
63
 
63
64
  @startup_thread = Thread.start do
65
+ Thread.current.report_on_exception = false
64
66
  if server
65
67
  @server_thread = Thread.start do
66
68
  server = TCPServer.new port
67
69
 
68
- while client = server.accept
69
- request = client.gets
70
- args = Shellwords.split(request)
71
- rspec_for_server(client, args)
72
- client.close
70
+ while true
71
+ break unless client = server.accept
72
+ begin
73
+ request = client.gets
74
+ args = Shellwords.split(request)
75
+ rspec_for_server(client, args)
76
+ rescue StandardError => e
77
+ # It would be nice to log to the client here but it might be
78
+ # disconnected or disconnect before we successfully write. Any
79
+ # error here is unexpected so just log to the console.
80
+ @output_stream.puts
81
+ @output_stream.puts 'error handling client request'
82
+ log_exception(@output_stream, e)
83
+ ensure
84
+ client.close
85
+ end
73
86
  end
74
87
  end
75
88
  end
76
89
 
77
- @config_cache.record_configuration { @configuration.configure_rspec.call }
78
- start_file_watcher
90
+ @startup_output = StringOutput.new
91
+ output = ThreadedOutput.new(thread_map: { Thread.current => @startup_output }, default: @output_stream)
92
+
93
+ Stdio.capture(stdout: output, stderr: output) do
94
+ @config_cache.record_configuration { @configuration.configure_rspec.call }
95
+ start_file_watcher
96
+ end
79
97
  end
80
98
 
81
99
  Pry.start
@@ -139,17 +157,17 @@ module RSpec
139
157
  Pry.config.history_file = @history_file
140
158
  end
141
159
 
142
- def self.refresh
160
+ def self.refresh(output: @output_stream)
143
161
  @file_change_mutex.synchronize do
144
162
  @updated_files.uniq.each do |filename|
145
- @output_stream.puts "changed: #{filename}"
163
+ output.puts "changed: #{filename}"
146
164
  trace = TracePoint.new(:class) do |tp|
147
165
  @configuration.on_class_load.call(tp.self)
148
166
  end
149
167
  trace.enable
150
168
  load filename
151
169
  trace.disable
152
- @output_stream.puts
170
+ output.puts
153
171
  end
154
172
  @updated_files.clear
155
173
  end
@@ -178,7 +196,7 @@ module RSpec
178
196
  end
179
197
 
180
198
  def self.rspec(args)
181
- @command_mutex.synchronize do
199
+ @rspec_mutex.synchronize do
182
200
  begin
183
201
  @runner = RSpec::Interactive::Runner.new(parse_args(args))
184
202
 
@@ -211,25 +229,22 @@ module RSpec
211
229
  end
212
230
 
213
231
  def self.rspec_for_server(client, args)
214
- @command_mutex.synchronize do
232
+ @rspec_mutex.synchronize do
215
233
  disable_pry = ENV['DISABLE_PRY']
216
234
  output = ClientOutput.new(client)
217
235
 
218
236
  ENV['TEAMCITY_RAKE_RUNNER_DEBUG_OUTPUT_CAPTURER_ENABLED'] = 'false'
219
237
  Rake::TeamCity::RunnerCommon.class_variable_set(:@@original_stdout, output)
220
238
 
221
- Stdio.capture(
222
- stdout: output,
223
- stderr: output) do
224
-
225
- await_startup(output: output)
239
+ return unless await_startup(output: output)
226
240
 
241
+ Stdio.capture(stdout: output, stderr: output) do
227
242
  # Prevent the debugger from being used. The server isn't interactive.
228
243
  ENV['DISABLE_PRY'] = 'true'
229
244
 
230
- @runner = RSpec::Interactive::Runner.new(parse_args(args))
245
+ runner = RSpec::Interactive::Runner.new(parse_args(args))
231
246
 
232
- refresh
247
+ refresh(output: output)
233
248
 
234
249
  # RSpec::Interactive-specific RSpec configuration
235
250
  RSpec.configure do |config|
@@ -250,18 +265,17 @@ module RSpec
250
265
  RSpec.configuration.formatter = Spec::Runner::Formatter::TeamcityFormatter
251
266
 
252
267
  # Run.
253
- @runner.run
254
- rescue Errno::EPIPE => e
268
+ runner.run
269
+ rescue Errno::EPIPE, IOError
255
270
  # Don't care.
256
271
  ensure
257
272
  ENV['DISABLE_PRY'] = disable_pry
258
- @runner = nil
273
+ runner = nil
259
274
 
260
275
  # Reset
261
276
  RSpec.clear_examples
262
277
  RSpec.reset
263
278
 
264
- await_startup(output: output)
265
279
  @config_cache.replay_configuration
266
280
  end
267
281
  end
@@ -279,24 +293,46 @@ module RSpec
279
293
  return yield if line.nil? # EOF
280
294
  return yield if line.empty? # blank line
281
295
 
282
- begin
283
- await_startup
284
- rescue Interrupt
296
+ if await_startup
297
+ yield
298
+ else
285
299
  @output_stream.puts
286
- return true
300
+ true
287
301
  end
288
-
289
- yield
290
302
  end
291
303
 
292
304
  def self.await_startup(output: @output_stream)
293
- if @startup_thread
294
- if @startup_thread.alive?
295
- output.puts 'waiting for configure_rspec...'
296
- end
305
+ return true unless @startup_thread
306
+
307
+ if @startup_thread.alive?
308
+ output.puts 'waiting for configure_rspec...'
309
+ end
310
+
311
+ begin
297
312
  @startup_thread.join
298
313
  @startup_thread = nil
314
+ print_startup_output(output: output)
315
+ true
316
+ rescue Interrupt
317
+ false
318
+ rescue StandardError => e
319
+ print_startup_output(output: output)
320
+ output.puts 'configure_rspec failed'
321
+ log_exception(output, e)
322
+ false
299
323
  end
300
324
  end
325
+
326
+ def self.log_exception(output, e)
327
+ output.puts "#{e.backtrace[0]}: #{e.message} (#{e.class})"
328
+ e.backtrace[1..-1].each { |b| output.puts "\t#{b}" }
329
+ end
330
+
331
+ def self.print_startup_output(output: @output_stream)
332
+ return if @startup_output.nil? || @startup_output.string.empty?
333
+
334
+ output.puts(@startup_output.string)
335
+ @startup_output = nil
336
+ end
301
337
  end
302
338
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-interactive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Dower
@@ -103,6 +103,7 @@ files:
103
103
  - lib/rspec-interactive/runner.rb
104
104
  - lib/rspec-interactive/stdio.rb
105
105
  - lib/rspec-interactive/string_output.rb
106
+ - lib/rspec-interactive/threaded_output.rb
106
107
  - lib/rspec-interactive/version.rb
107
108
  - lib/teamcity/spec/runner/formatter/teamcity/formatter.rb
108
109
  - rspec-interactive.gemspec