rspec-interactive 0.9.2 → 0.9.5

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
  SHA256:
3
- metadata.gz: 17f3d7cb90e4271d19e1eb1a835a9c759084d12baf1f7404bedc521d8ff54047
4
- data.tar.gz: 98688109728bbaa18e0b64339987fc0d2320331095ad09f2761d2162254ad868
3
+ metadata.gz: bfaebc90c8fc0856566eb671fb122248778540ce78832af3a4c7b8cc3e8374a2
4
+ data.tar.gz: 476896ae26c3acf5fef26486ba7d3b5ee4caa2de220bb2c42b61f740989d6d92
5
5
  SHA512:
6
- metadata.gz: f0fbe89b3308f29db1302f28b265c0374a6b5c586b32b5c2bee2351d035faaf82c5f5d0362bb95158966d5ea9354de404dc126efd7b899d1bb9d2f8bee40edde
7
- data.tar.gz: a8bbeaf1ca9e8f51b975cde6bf51be7cc5c6a57b1266bc4ee527c1e1ffcf995b9ac8c78ac77fe1a8ca79b937c4c31d712c9d58119ca4283854da8a6c4f78ccc9
6
+ metadata.gz: 20746051789c2591c9e398e65e645b343c994b1cae438f5c509d107217298af9bbef9d0c12327f446ed47214a7800c3ed594acad929fc48873280f5aed380c36
7
+ data.tar.gz: e844ef291294500ca6702a876662f03f6c20ec261a4864eb43dacca7d8b17fd29b995ea567ccbb3c0d9170c204e24902679b0ca4e24aa4e3925c86026ba5eca3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-interactive (0.9.1)
4
+ rspec-interactive (0.9.4)
5
5
  listen
6
6
  pry
7
7
  rspec-core
@@ -5,8 +5,16 @@ module RSpec
5
5
  @client = client
6
6
  end
7
7
 
8
+ def print(str = "")
9
+ @client.print(str.to_s)
10
+ end
11
+
12
+ def write(str = "")
13
+ @client.print(str.to_s)
14
+ end
15
+
8
16
  def puts(str = "")
9
- @client.puts(str&.to_s || '')
17
+ @client.print(str.to_s + "\n")
10
18
  end
11
19
 
12
20
  def string
@@ -1,10 +1,18 @@
1
1
  module RSpec
2
2
  module Interactive
3
3
  class Stdio
4
- def self.capture(output)
4
+ def self.capture2(stdout:, stderr:)
5
+ old_stdout, old_stderr = $stdout, $stderr
6
+ $stdout, $stderr = stdout, stderr
7
+ yield
8
+ ensure
9
+ $stdout, $stderr = old_stdout, old_stderr
10
+ end
11
+
12
+ def self.capture(stdout:, stderr:)
5
13
  raise ArgumentError, 'missing block' unless block_given?
6
14
 
7
- stdout, stderr = STDOUT.dup, STDERR.dup
15
+ old_stdout, old_stderr = STDOUT.dup, STDERR.dup
8
16
 
9
17
  IO.pipe do |stdout_read, stdout_write|
10
18
  IO.pipe do |stderr_read, stderr_write|
@@ -14,23 +22,28 @@ module RSpec
14
22
  stdout_write.close
15
23
  stderr_write.close
16
24
 
17
- thread = Thread.new do
18
- until stdout_read.eof? && stderr_read.eof? do
19
- line = stdout_read.gets
20
- output.puts line if line
21
- line = stderr_read.gets
22
- output.puts if line
25
+ stdout_thread = Thread.new do
26
+ while line = stdout_read.gets do
27
+ stdout.print(line)
28
+ end
29
+ end
30
+
31
+ stderr_thread = Thread.new do
32
+ while line = stderr_read.gets do
33
+ stderr.print(line)
23
34
  end
24
35
  end
25
36
 
26
37
  begin
27
38
  yield
28
39
  ensure
29
- STDOUT.reopen stdout
30
- STDERR.reopen stderr
40
+ # TODO: should the threads be killed here?
41
+ STDOUT.reopen old_stdout
42
+ STDERR.reopen old_stderr
31
43
  end
32
44
 
33
- thread.join
45
+ stdout_thread.join
46
+ stderr_thread.join
34
47
  end
35
48
  end
36
49
  end
@@ -0,0 +1,23 @@
1
+ module RSpec
2
+ module Interactive
3
+ class StringOutput
4
+ attr_reader :string
5
+
6
+ def initialize
7
+ @string = ''
8
+ end
9
+
10
+ def write(name, str = "")
11
+ @string += str.to_s
12
+ end
13
+
14
+ def puts(str = "")
15
+ @string += str.to_s + "\n"
16
+ end
17
+
18
+ def print(str = "")
19
+ @string += str.to_s
20
+ end
21
+ end
22
+ end
23
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Interactive
5
- VERSION = "0.9.2"
5
+ VERSION = "0.9.5"
6
6
  end
7
7
  end
@@ -18,6 +18,7 @@ require 'rspec-interactive/rspec_core_example'
18
18
  require 'rspec-interactive/rubo_cop_command'
19
19
  require 'rspec-interactive/runner'
20
20
  require 'rspec-interactive/stdio'
21
+ require 'rspec-interactive/string_output'
21
22
 
22
23
  module RSpec
23
24
  module Interactive
@@ -56,34 +57,33 @@ module RSpec
56
57
  load config_file if config_file
57
58
 
58
59
  check_rails
60
+ trap_interrupt
59
61
  configure_pry
60
62
 
61
- start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
62
- @config_cache.record_configuration { @configuration.configure_rspec.call }
63
- end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
64
- if end_time - start_time > 5
65
- @output_stream.puts "Configuring RSpec took #{(end_time - start_time).round} seconds."
66
- end
67
-
68
- start_file_watcher
63
+ @startup_thread = Thread.start do
64
+ @startup_output = StringOutput.new
65
+ Stdio.capture2(stdout: @startup_output, stderr: @startup_output) do
66
+ @config_cache.record_configuration { @configuration.configure_rspec.call }
67
+ start_file_watcher
68
+ end
69
69
 
70
- if server
71
- @output_stream.puts "Listening on port #{port}."
72
- server_thread = Thread.start do
73
- server = TCPServer.new port
70
+ if server
71
+ @server_thread = Thread.start do
72
+ server = TCPServer.new port
74
73
 
75
- while client = server.accept
76
- request = client.gets
77
- args = Shellwords.split(request)
78
- rspec_for_server(client, args)
79
- client.close
74
+ while client = server.accept
75
+ request = client.gets
76
+ args = Shellwords.split(request)
77
+ rspec_for_server(client, args)
78
+ client.close
79
+ end
80
80
  end
81
81
  end
82
82
  end
83
83
 
84
84
  Pry.start
85
85
  @listener.stop if @listener
86
- server_thread.exit if server_thread
86
+ @server_thread.exit if @server_thread
87
87
  0
88
88
  end
89
89
 
@@ -95,11 +95,14 @@ module RSpec
95
95
  end
96
96
  end
97
97
 
98
- def self.configure_rspec(error_stream: @error_stream, output_stream: @output_stream)
99
- RSpec.configure do |config|
100
- config.error_stream = error_stream
101
- config.output_stream = output_stream
102
- config.start_time = RSpec::Core::Time.now
98
+ def self.trap_interrupt
99
+ trap('INT') do
100
+ if @runner
101
+ # We are on a different thread. There is a race here. Ignore nil.
102
+ @runner&.quit
103
+ else
104
+ raise Interrupt
105
+ end
103
106
  end
104
107
  end
105
108
 
@@ -116,6 +119,9 @@ module RSpec
116
119
  end
117
120
 
118
121
  def self.configure_pry
122
+ # Prevent Pry from trapping too. It will break ctrl-c handling.
123
+ Pry.config.should_trap_interrupts = false
124
+
119
125
  # Set up IO.
120
126
  Pry.config.input = Readline
121
127
  Pry.config.output = @output_stream
@@ -146,14 +152,24 @@ module RSpec
146
152
  end
147
153
 
148
154
  def self.parse_args(args)
149
- args.flat_map do |arg|
150
- if arg.match(/[\*\?\[]/)
151
- glob = Dir.glob(arg)
152
- glob.empty? ? [arg] : glob
155
+ i = 0
156
+ parsed_args = []
157
+ until i == args.length
158
+ case args[i]
159
+ when /[\*\?\[]/
160
+ glob = Dir.glob(args[i])
161
+ parsed_args.concat(glob.empty? ? args[i] : glob)
162
+ when '--pattern'
163
+ # RubyMine passes --pattern when running all specs in a dir.
164
+ # We don't want to expand this since it is used as a glob by RSpec.
165
+ parsed_args.concat(args[i..(i + 1)])
166
+ i += 1
153
167
  else
154
- [arg]
168
+ parsed_args << args[i]
155
169
  end
170
+ i += 1
156
171
  end
172
+ parsed_args
157
173
  end
158
174
 
159
175
  def self.rspec(args)
@@ -165,7 +181,11 @@ module RSpec
165
181
  Pry.config.history_save = false
166
182
 
167
183
  # RSpec::Interactive-specific RSpec configuration
168
- configure_rspec
184
+ RSpec.configure do |config|
185
+ config.error_stream = @error_stream
186
+ config.output_stream = @output_stream
187
+ config.start_time = RSpec::Core::Time.now
188
+ end
169
189
 
170
190
  # Run.
171
191
  exit_code = @runner.run
@@ -178,9 +198,6 @@ module RSpec
178
198
  RSpec.clear_examples
179
199
  RSpec.reset
180
200
  @config_cache.replay_configuration
181
- rescue Interrupt => e
182
- @runner&.quit
183
- raise e
184
201
  ensure
185
202
  @runner = nil
186
203
  end
@@ -192,13 +209,17 @@ module RSpec
192
209
  ENV['DISABLE_PRY'] = 'true'
193
210
 
194
211
  output = ClientOutput.new(client)
195
- Stdio.capture(ClientOutput.new(client)) do
212
+ Stdio.capture(stdout: output, stderr: output) do
196
213
  @runner = RSpec::Interactive::Runner.new(parse_args(args))
197
214
 
198
215
  refresh
199
216
 
200
217
  # RSpec::Interactive-specific RSpec configuration
201
- configure_rspec
218
+ RSpec.configure do |config|
219
+ config.error_stream = @error_stream
220
+ config.output_stream = @output_stream
221
+ config.start_time = RSpec::Core::Time.now
222
+ end
202
223
 
203
224
  # RubyMine specifies --format. That causes a formatter to be added. It does not override
204
225
  # the existing formatter (if one is set by default). Clear any formatters but resetting
@@ -238,6 +259,17 @@ module RSpec
238
259
  else
239
260
  @command_mutex.synchronize do
240
261
  Thread.current.thread_variable_set('holding_lock', true)
262
+ if @startup_thread
263
+ if @startup_thread.alive?
264
+ @output_stream.puts 'waiting for configure_rspec...'
265
+ end
266
+ @startup_thread.join
267
+ @startup_thread = nil
268
+ unless @startup_output.string.empty?
269
+ @output_stream.puts(@startup_output.string)
270
+ end
271
+ @startup_output = nil
272
+ end
241
273
  yield
242
274
  ensure
243
275
  Thread.current.thread_variable_set('holding_lock', false)
data/runner/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # RSpec Interactive Runner
2
+
3
+ Use this directory as the working directory in RubyMine run configurations.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-interactive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Dower
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-25 00:00:00.000000000 Z
11
+ date: 2022-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
@@ -102,11 +102,13 @@ files:
102
102
  - lib/rspec-interactive/rubo_cop_command.rb
103
103
  - lib/rspec-interactive/runner.rb
104
104
  - lib/rspec-interactive/stdio.rb
105
+ - lib/rspec-interactive/string_output.rb
105
106
  - lib/rspec-interactive/version.rb
106
107
  - lib/teamcity/spec/runner/formatter/teamcity/formatter.rb
107
108
  - rspec-interactive.gemspec
108
109
  - runner/Gemfile
109
110
  - runner/Gemfile.lock
111
+ - runner/README.md
110
112
  - runner/rspec-interactive-run
111
113
  - scripts/release.sh
112
114
  - scripts/run-with-local-dep.sh