rspec-interactive 0.9.0 → 0.9.3

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: 987faf5573f9ae7554f4983ee350beaf7ad9ef832544cea3b6f92114cf554788
4
- data.tar.gz: 29e0c2b195497e1d2af2f7e8565ee64ae6039870f3bb685dc86e750c11342a71
3
+ metadata.gz: ca3d9ea9bc7a43930a9d3400a30b1c9d0bb06cc6691b70340966c8543b830646
4
+ data.tar.gz: 6f22c4c95eb720509cabb7cd3edd18277b1b68f96bdca32ab7f55ff6197c3e11
5
5
  SHA512:
6
- metadata.gz: 2f3e0573bd9280ca150292045134b5eea34243661733aa68dda3ca03c086fc0275ecfecd919aaf022e5aeb943ca4523170e39e6d47c60f8ef59fc5b925fc60b4
7
- data.tar.gz: 618437758587eb88be800508ef487960c1c760143e81594e89c3e80280a2eada7e3904e323c960b6dce2b40ec93eba6638e3dbda311d57144a95d6fef719a1d9
6
+ metadata.gz: f39caa7d3669358769a1aa5f8c901bfbfafbef2d9e5854e14a3331f87bfb5065cf42c3609dcb5d84940371811ae35b6168ed46effa99da032e9d4dae8e0a85d0
7
+ data.tar.gz: 426d3c1feaec48508dfc48712914c40e278641c669a789b9902fa8a307c3ac349ed4cb580b008be8527d664cde94865d5e33b127a21192bf872f91261f3a93bc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-interactive (0.8.1)
4
+ rspec-interactive (0.9.2)
5
5
  listen
6
6
  pry
7
7
  rspec-core
@@ -12,15 +12,15 @@ GEM
12
12
  specs:
13
13
  coderay (1.1.3)
14
14
  diff-lcs (1.4.4)
15
- ffi (1.15.3)
16
- listen (3.5.1)
15
+ ffi (1.15.5)
16
+ listen (3.7.1)
17
17
  rb-fsevent (~> 0.10, >= 0.10.3)
18
18
  rb-inotify (~> 0.9, >= 0.9.10)
19
19
  method_source (1.0.0)
20
20
  pry (0.14.1)
21
21
  coderay (~> 1.1)
22
22
  method_source (~> 1.0)
23
- rb-fsevent (0.11.0)
23
+ rb-fsevent (0.11.1)
24
24
  rb-inotify (0.10.1)
25
25
  ffi (~> 1.0)
26
26
  rspec (3.9.0)
@@ -4,20 +4,20 @@ require 'optparse'
4
4
  require 'rspec-interactive'
5
5
 
6
6
  @options = {
7
- server: false,
8
- port: RSpec::Interactive::DEFAULT_PORT
7
+ server: true,
8
+ server_port: RSpec::Interactive::DEFAULT_PORT
9
9
  }
10
10
 
11
11
  parser = OptionParser.new do |opts|
12
12
  opts.banner = "Starts an interactive RSpec shell.\n\n"\
13
- "Usage: bundle exec rspec-interactive [--config config-file] [--server [--port <port>]]"
13
+ "Usage: bundle exec rspec-interactive [--config config-file] [--no-server] [--port <port>]"
14
14
 
15
15
  opts.on("-c", "--config <config-file>", String, "Optional. Path to the RSpec Interactive config file.") do |config_file|
16
16
  @options[:config_file] = config_file
17
17
  end
18
18
 
19
- opts.on("-s", "--server", "Optional. Enable server used by IDEs.") do
20
- @options[:server] = true
19
+ opts.on("--no-server", "Optional. Disable server.") do
20
+ @options[:server] = false
21
21
  end
22
22
 
23
23
  opts.on("-p", "--port <port>", Integer, "Optional. Server port. Defaults to #{RSpec::Interactive::DEFAULT_PORT}.") do |port|
@@ -26,4 +26,4 @@ parser = OptionParser.new do |opts|
26
26
 
27
27
  end.parse!
28
28
 
29
- RSpec::Interactive.start(config_file: @options[:config_file], server: @options[:server], port: @options[:port])
29
+ RSpec::Interactive.start(config_file: @options[:config_file], server: @options[:server], port: @options[:server_port])
@@ -0,0 +1,7 @@
1
+ RSpec::Interactive.configure do |config|
2
+ config.watch_dirs += ['lib']
3
+
4
+ config.configure_rspec do
5
+ RSpec.configuration.formatter = :documentation
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module RSpec
2
+ module Interactive
3
+ class ClientOutput
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def print(str = "")
9
+ @client.print(str&.to_s || '')
10
+ end
11
+
12
+ def string
13
+ @output
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require 'pry'
2
+
3
+ class Pry
4
+ alias_method :old_eval, :eval
5
+
6
+ def eval(line, options = {})
7
+ RSpec::Interactive.eval do
8
+ old_eval(line, options)
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,15 @@
1
+ require 'rspec/core'
2
+
3
+ module RSpec
4
+ module Core
5
+ class Example
6
+ alias_method :old_run, :run
7
+
8
+ def run(example_group_instance, reporter)
9
+ execution_result.started_at = RSpec::Core::Time.now
10
+ old_run(example_group_instance, reporter)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,44 @@
1
+ module RSpec
2
+ module Interactive
3
+ class Stdio
4
+ def self.capture(output)
5
+ raise ArgumentError, 'missing block' unless block_given?
6
+
7
+ stdout, stderr = STDOUT.dup, STDERR.dup
8
+
9
+ IO.pipe do |stdout_read, stdout_write|
10
+ IO.pipe do |stderr_read, stderr_write|
11
+ STDOUT.reopen(stdout_write)
12
+ STDERR.reopen(stderr_write)
13
+
14
+ stdout_write.close
15
+ stderr_write.close
16
+
17
+ stdout_thread = Thread.new do
18
+ while line = stdout_read.gets do
19
+ output.print(line)
20
+ end
21
+ end
22
+
23
+ stderr_thread = Thread.new do
24
+ while line = stderr_read.gets do
25
+ output.print(line)
26
+ end
27
+ end
28
+
29
+ begin
30
+ yield
31
+ ensure
32
+ # TODO: should the threads be killed here?
33
+ STDOUT.reopen stdout
34
+ STDERR.reopen stderr
35
+ end
36
+
37
+ stdout_thread.join
38
+ stderr_thread.join
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Interactive
5
- VERSION = "0.9.0"
5
+ VERSION = "0.9.3"
6
6
  end
7
7
  end
@@ -7,13 +7,17 @@ require 'shellwords'
7
7
  require 'socket'
8
8
  require 'teamcity/spec/runner/formatter/teamcity/formatter'
9
9
 
10
+ require 'rspec-interactive/client_output'
10
11
  require 'rspec-interactive/config'
11
12
  require 'rspec-interactive/input_completer'
13
+ require 'rspec-interactive/pry'
12
14
  require 'rspec-interactive/refresh_command'
13
15
  require 'rspec-interactive/rspec_command'
14
16
  require 'rspec-interactive/rspec_config_cache'
17
+ require 'rspec-interactive/rspec_core_example'
15
18
  require 'rspec-interactive/rubo_cop_command'
16
19
  require 'rspec-interactive/runner'
20
+ require 'rspec-interactive/stdio'
17
21
 
18
22
  module RSpec
19
23
  module Interactive
@@ -42,7 +46,7 @@ module RSpec
42
46
  @updated_files = []
43
47
  @stty_save = %x`stty -g`.chomp
44
48
  @file_change_mutex = Mutex.new
45
- @rspec_mutex = Mutex.new
49
+ @command_mutex = Mutex.new
46
50
  @output_stream = output_stream
47
51
  @input_stream = input_stream
48
52
  @error_stream = error_stream
@@ -55,12 +59,19 @@ module RSpec
55
59
  trap_interrupt
56
60
  configure_pry
57
61
 
62
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
58
63
  @config_cache.record_configuration { @configuration.configure_rspec.call }
64
+ end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
65
+ if end_time - start_time > 5
66
+ @output_stream.puts "Configuring RSpec took #{(end_time - start_time).round} seconds."
67
+ end
68
+
59
69
  start_file_watcher
60
70
 
61
71
  if server
72
+ @output_stream.puts "Listening on port #{port}."
62
73
  server_thread = Thread.start do
63
- server = TCPServer.new 5678
74
+ server = TCPServer.new port
64
75
 
65
76
  while client = server.accept
66
77
  request = client.gets
@@ -161,58 +172,67 @@ module RSpec
161
172
  end
162
173
 
163
174
  def self.rspec(args)
164
- @rspec_mutex.synchronize do
165
-
166
- @runner = RSpec::Interactive::Runner.new(parse_args(args))
175
+ @runner = RSpec::Interactive::Runner.new(parse_args(args))
167
176
 
168
- refresh
177
+ refresh
169
178
 
170
- # Stop saving history in case a new Pry session is started for debugging.
171
- Pry.config.history_save = false
179
+ # Stop saving history in case a new Pry session is started for debugging.
180
+ Pry.config.history_save = false
172
181
 
173
- # RSpec::Interactive-specific RSpec configuration
174
- configure_rspec
182
+ # RSpec::Interactive-specific RSpec configuration
183
+ configure_rspec
175
184
 
176
- # Run.
177
- exit_code = @runner.run
178
- @runner = nil
185
+ # Run.
186
+ exit_code = @runner.run
187
+ @runner = nil
179
188
 
180
- # Reenable history
181
- Pry.config.history_save = true
189
+ # Reenable history
190
+ Pry.config.history_save = true
182
191
 
183
- # Reset
184
- RSpec.clear_examples
185
- RSpec.reset
186
- @config_cache.replay_configuration
187
- ensure
188
- @runner = nil
189
- end
192
+ # Reset
193
+ RSpec.clear_examples
194
+ RSpec.reset
195
+ @config_cache.replay_configuration
196
+ ensure
197
+ @runner = nil
190
198
  end
191
199
 
192
200
  def self.rspec_for_server(client, args)
193
- @rspec_mutex.synchronize do
194
- # Set the client so that logs are written to the client rathe than STDOUT.
195
- Spec::Runner::Formatter::TeamcityFormatter.client = client
196
-
197
- @runner = RSpec::Interactive::Runner.new(parse_args(args))
198
-
199
- refresh
200
-
201
- # Stop saving history in case a new Pry session is started for debugging.
202
- Pry.config.history_save = false
203
-
204
- # RSpec::Interactive-specific RSpec configuration
205
- configure_rspec
206
- RSpec.configuration.formatter = Spec::Runner::Formatter::TeamcityFormatter
207
-
208
- # Run.
209
- exit_code = @runner.run
210
-
211
- # Reset
212
- Spec::Runner::Formatter::TeamcityFormatter.client = nil
213
- RSpec.clear_examples
214
- RSpec.reset
215
- @config_cache.replay_configuration
201
+ @command_mutex.synchronize do
202
+ # Prevent the debugger from being used. The server isn't interactive.
203
+ disable_pry = ENV['DISABLE_PRY']
204
+ ENV['DISABLE_PRY'] = 'true'
205
+
206
+ output = ClientOutput.new(client)
207
+ Stdio.capture(ClientOutput.new(client)) do
208
+ @runner = RSpec::Interactive::Runner.new(parse_args(args))
209
+
210
+ refresh
211
+
212
+ # RSpec::Interactive-specific RSpec configuration
213
+ configure_rspec
214
+
215
+ # RubyMine specifies --format. That causes a formatter to be added. It does not override
216
+ # the existing formatter (if one is set by default). Clear any formatters but resetting
217
+ # the loader.
218
+ RSpec.configuration.instance_variable_set(
219
+ :@formatter_loader,
220
+ RSpec::Core::Formatters::Loader.new(RSpec::Core::Reporter.new(RSpec.configuration)))
221
+
222
+ # Always use the teamcity formatter, even though RubyMine always specifies it.
223
+ # This make manual testing of rspec-interactive easier.
224
+ RSpec.configuration.formatter = Spec::Runner::Formatter::TeamcityFormatter
225
+
226
+ # Run.
227
+ exit_code = @runner.run
228
+
229
+ # Reset
230
+ RSpec.clear_examples
231
+ RSpec.reset
232
+ @config_cache.replay_configuration
233
+ end
234
+ ensure
235
+ ENV['DISABLE_PRY'] = disable_pry
216
236
  end
217
237
  end
218
238
 
@@ -224,5 +244,17 @@ module RSpec
224
244
  end
225
245
  end
226
246
 
247
+ def self.eval(&block)
248
+ if Thread.current.thread_variable_get('holding_lock')
249
+ yield
250
+ else
251
+ @command_mutex.synchronize do
252
+ Thread.current.thread_variable_set('holding_lock', true)
253
+ yield
254
+ ensure
255
+ Thread.current.thread_variable_set('holding_lock', false)
256
+ end
257
+ end
258
+ end
227
259
  end
228
260
  end
@@ -4,14 +4,6 @@ module Spec
4
4
  module Runner
5
5
  module Formatter
6
6
  class TeamcityFormatter
7
- class << self
8
- attr_accessor :client
9
- end
10
-
11
- def log(msg)
12
- TeamcityFormatter.client.puts(msg)
13
- msg
14
- end
15
7
  end
16
8
  end
17
9
  end
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  end
24
24
  spec.bindir = 'bin'
25
25
  spec.executables << 'rspec-interactive'
26
- spec.executables << 'rspec-interactive-run'
27
26
  spec.require_paths = ["lib"]
28
27
 
29
28
  spec.add_dependency 'rspec-core'
data/runner/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ ruby '3.0.0'
4
+
5
+ source "https://rubygems.org"
@@ -0,0 +1,14 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+
5
+ PLATFORMS
6
+ x86_64-darwin-20
7
+
8
+ DEPENDENCIES
9
+
10
+ RUBY VERSION
11
+ ruby 3.0.0p0
12
+
13
+ BUNDLED WITH
14
+ 2.3.6
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
- require 'rspec-interactive'
5
4
  require 'shellwords'
6
5
  require 'socket'
7
6
 
8
7
  @options = {
9
8
  host: 'localhost',
10
- port: RSpec::Interactive::DEFAULT_PORT
9
+ port: 5678
11
10
  }
12
11
 
13
12
  parser = OptionParser.new do |opts|
@@ -18,15 +17,15 @@ parser = OptionParser.new do |opts|
18
17
  @options[:host] = host
19
18
  end
20
19
 
21
- opts.on("-p", "--port <port>", Integer, "Optional. Server port. Defaults to #{RSpec::Interactive::DEFAULT_PORT}.") do |port|
20
+ opts.on("-p", "--port <port>", Integer, "Optional. Server port. Defaults to 5678.") do |port|
22
21
  @options[:port] = port
23
22
  end
24
23
 
25
24
  end.parse
26
25
 
27
26
  server = TCPSocket.open(@options[:host], @options[:port])
28
- server.puts ARGV.map{|arg| Shellwords.escape arg}.join(' ')
27
+ server.puts ARGV.map{ |arg| Shellwords.escape arg }.join(' ')
29
28
  while response = server.gets do
30
- puts "response: #{response}"
29
+ puts response
31
30
  end
32
31
  server.close
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.0
4
+ version: 0.9.3
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-24 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
@@ -71,7 +71,6 @@ email:
71
71
  - nicholasdower@gmail.com
72
72
  executables:
73
73
  - rspec-interactive
74
- - rspec-interactive-run
75
74
  extensions: []
76
75
  extra_rdoc_files: []
77
76
  files:
@@ -83,25 +82,32 @@ files:
83
82
  - Rakefile
84
83
  - bin/console
85
84
  - bin/rspec-interactive
86
- - bin/rspec-interactive-run
87
85
  - bin/setup
88
86
  - bin/test
87
+ - examples/config.rb
89
88
  - examples/debugged_spec.rb
90
89
  - examples/failing_spec.rb
91
90
  - examples/other_passing_spec.rb
92
91
  - examples/passing_spec.rb
93
92
  - examples/spec_with_syntax_error.rb
94
93
  - lib/rspec-interactive.rb
94
+ - lib/rspec-interactive/client_output.rb
95
95
  - lib/rspec-interactive/config.rb
96
96
  - lib/rspec-interactive/input_completer.rb
97
+ - lib/rspec-interactive/pry.rb
97
98
  - lib/rspec-interactive/refresh_command.rb
98
99
  - lib/rspec-interactive/rspec_command.rb
99
100
  - lib/rspec-interactive/rspec_config_cache.rb
101
+ - lib/rspec-interactive/rspec_core_example.rb
100
102
  - lib/rspec-interactive/rubo_cop_command.rb
101
103
  - lib/rspec-interactive/runner.rb
104
+ - lib/rspec-interactive/stdio.rb
102
105
  - lib/rspec-interactive/version.rb
103
106
  - lib/teamcity/spec/runner/formatter/teamcity/formatter.rb
104
107
  - rspec-interactive.gemspec
108
+ - runner/Gemfile
109
+ - runner/Gemfile.lock
110
+ - runner/rspec-interactive-run
105
111
  - scripts/release.sh
106
112
  - scripts/run-with-local-dep.sh
107
113
  - tests/debugged_spec_test.rb