rspec-interactive 0.3.0 → 0.3.1

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: e3ff2b23a6cf52444bf173292d0e161006bbcf764f153f31ea9052d0f0c0f912
4
- data.tar.gz: ddb6567801ceb90ff76054d554d3d63ecc951a92584395d809f691c10520555f
3
+ metadata.gz: 44ae79866c1c58455a4c3002cd84f80b5a81ee65ff2256edee608179e8f0b4e1
4
+ data.tar.gz: 189c67764a53a77ce517fbfe23f33a4a17fd368ce369a7ceb9bf423ce2cca3b1
5
5
  SHA512:
6
- metadata.gz: 2aa35c7ed2108213d90e97d9b8d30208f28993ab2e8111127024dec1ddf7404226a00a5e7c2a99dd47a026efc18f043558e8db3d87373e3c486bf4de8fac32a8
7
- data.tar.gz: 35147d8a59a432d163dfd309db75c92100c781e5e1d6fa925df431ec70cc849b6886f1bd0cac9bb27e53ee9b6094b7332012520f69b29ed30e8178af5dbe6125
6
+ metadata.gz: 5e8c797fc2481ce1380d4f4056883b39479d6519be4f40af235979fd63dd23040eb7b62e1e80234156b805dead002837afb09ca4fb569f30c134cc97a6f5c6e3
7
+ data.tar.gz: a49843eff84cb74c5a3de6da1758de16a947b9ce16e741253354d69b4082c871184ce7e8dd346cb51576e2484e44ca3950d5079d581cc211915d3f600e7b01fd
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
1
  rspec-interactive-*.gem
2
2
  .rspec_interactive_history
3
3
  .rspec_interactive_config
4
- .rspec_interactive_results
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-interactive (0.2.0)
4
+ rspec-interactive (0.3.1)
5
5
  listen
6
6
  pry
7
7
  rspec-core
data/README.md CHANGED
@@ -35,7 +35,6 @@ Update `.gitignore`
35
35
 
36
36
  ```shell
37
37
  echo '.rspec_interactive_history' >> .gitignore
38
- echo '.rspec_interactive_results' >> .gitignore
39
38
  ```
40
39
 
41
40
  ## Usage
@@ -12,23 +12,24 @@ require 'rspec-interactive/rspec_command'
12
12
  module RSpec
13
13
  module Interactive
14
14
 
15
- HISTORY_FILE = '.rspec_interactive_history'.freeze
16
- CONFIG_FILE = '.rspec_interactive_config'.freeze
15
+ DEFAULT_HISTORY_FILE = '.rspec_interactive_history'.freeze
16
+ DEFAULT_CONFIG_FILE = '.rspec_interactive_config'.freeze
17
17
 
18
18
  class <<self
19
19
  attr_accessor :readline, :input_stream, :output_stream, :error_stream
20
- attr_accessor :config, :stty_save, :mutex, :config_cache, :runner, :results, :result, :updated_files
20
+ attr_accessor :config, :mutex, :config_cache, :runner, :results, :result, :updated_files
21
21
  end
22
22
 
23
- def self.start(args, input_stream: STDIN, output_stream: STDOUT, error_stream: STDERR)
23
+ def self.start(args, config_file: DEFAULT_CONFIG_FILE, history_file: DEFAULT_HISTORY_FILE, input_stream: STDIN, output_stream: STDOUT, error_stream: STDERR)
24
24
  if args.size > 1
25
25
  @error_stream.puts "expected 0 or 1 argument, got: #{args.join(', ')}"
26
- exit!(1)
26
+ return 1
27
27
  end
28
28
 
29
+ @config_file = config_file
30
+ @history_file = history_file
29
31
  @updated_files = []
30
32
  @results = []
31
- @config = get_config(args[0])
32
33
  @stty_save = %x`stty -g`.chomp
33
34
  @mutex = Mutex.new
34
35
  @output_stream = output_stream
@@ -36,6 +37,9 @@ module RSpec
36
37
  @error_stream = error_stream
37
38
  @config_cache = RSpec::Interactive::ConfigCache.new
38
39
 
40
+ @config = get_config(args[0])
41
+ return 1 unless @config
42
+
39
43
  load_rspec_config
40
44
  check_rails
41
45
  start_file_watcher
@@ -43,6 +47,7 @@ module RSpec
43
47
  configure_pry
44
48
 
45
49
  Pry.start
50
+ 0
46
51
  end
47
52
 
48
53
  def self.check_rails
@@ -74,15 +79,21 @@ module RSpec
74
79
  end
75
80
 
76
81
  def self.get_config(name = nil)
77
- unless File.exists? CONFIG_FILE
78
- @error_stream.puts "warning: #{CONFIG_FILE} not found, using default config"
82
+ unless @config_file && File.exists?(@config_file)
83
+ @error_stream.puts "warning: config file not found, using default config" if @config_file
79
84
  return {}
80
85
  end
81
86
 
82
- configs = JSON.parse(File.read(CONFIG_FILE))["configs"] || []
87
+ begin
88
+ configs = JSON.parse(File.read(@config_file))["configs"] || []
89
+ rescue JSON::ParserError => e
90
+ @error_stream.puts "failed to parse config file"
91
+ return nil
92
+ end
93
+
83
94
  if configs.empty?
84
- @error_stream.puts "no configs found in: #{CONFIG_FILE}"
85
- exit!(1)
95
+ @error_stream.puts "no configs found in config file"
96
+ return nil
86
97
  end
87
98
 
88
99
  # If a specific config was specified, use it.
@@ -90,7 +101,7 @@ module RSpec
90
101
  config = configs.find { |e| e["name"] == name }
91
102
  return config if config
92
103
  @error_stream.puts "invalid config: #{name}"
93
- exit!(1)
104
+ return nil
94
105
  end
95
106
 
96
107
  # If there is only one, use it.
@@ -151,7 +162,7 @@ module RSpec
151
162
  # Use custom completer to get file completion.
152
163
  Pry.config.completer = RSpec::Interactive::InputCompleter
153
164
 
154
- Pry.config.history_file = HISTORY_FILE
165
+ Pry.config.history_file = @history_file
155
166
  end
156
167
  end
157
168
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Interactive
5
- VERSION = "0.3.0"
5
+ VERSION = "0.3.1"
6
6
  end
7
7
  end
@@ -29,7 +29,10 @@ Test.test "debugged spec" do
29
29
  Finished in 0 seconds (files took 0 seconds to load)
30
30
  1 example, 0 failures
31
31
 
32
- => <RSpec::Interactive::Result @success=true, @group_results=[...]>
33
32
  [2] pry(main)> exit
34
33
  EOF
34
+
35
+ expect_history <<~EOF
36
+ rspec examples/debugged_spec.rb
37
+ EOF
35
38
  end
@@ -36,9 +36,6 @@ Test.test "failing spec" do
36
36
 
37
37
  rspec ./examples/failing_spec.rb:4 # example spec fails
38
38
 
39
- Rerun failures by executing the previous command with --only-failures or --next-failure.
40
-
41
- => <RSpec::Interactive::Result @success=false, @group_results=[...]>
42
39
  [2] pry(main)> exit
43
40
  EOF
44
41
  end
@@ -0,0 +1,26 @@
1
+ require_relative 'support/test_helper'
2
+
3
+ config = Tempfile.new('config')
4
+ config.write '{'
5
+ config.rewind
6
+
7
+ Test.test "invalid config", config_path: config.path do
8
+ await_termination
9
+ expect_error_output <<~EOF
10
+ failed to parse config file
11
+ EOF
12
+ expect_result 1
13
+ end
14
+ config.close
15
+
16
+ config = Tempfile.new('config')
17
+ config.write '{}'
18
+ config.rewind
19
+
20
+ Test.test "empty config", config_path: config.path do
21
+ await_termination
22
+ expect_error_output <<~EOF
23
+ no configs found in config file
24
+ EOF
25
+ expect_result 1
26
+ end
@@ -13,7 +13,6 @@ Test.test "passing spec" do
13
13
  Finished in 0 seconds (files took 0 seconds to load)
14
14
  2 examples, 0 failures
15
15
 
16
- => <RSpec::Interactive::Result @success=true, @group_results=[...]>
17
16
  [2] pry(main)> exit
18
17
  EOF
19
18
  end
@@ -156,38 +156,61 @@ end
156
156
 
157
157
  class Test
158
158
 
159
- def self.test(name, &block)
160
- Test.new.run(name, &block)
159
+ def self.test(name, config_path: nil, &block)
160
+ Test.new.run(name, config_path, &block)
161
161
  end
162
162
 
163
- def run(name, &block)
163
+ def run(name, config_path, &block)
164
+ puts "running: #{name}"
165
+
164
166
  @output_temp_file = Tempfile.new('output')
165
167
  @output_write = File.open(@output_temp_file.path, 'w')
166
168
 
169
+ @error_temp_file = Tempfile.new('error')
170
+ @error_write = File.open(@error_temp_file.path, 'w')
171
+
172
+ @history_temp_file = Tempfile.new('history')
173
+
167
174
  @interactive_thread = Thread.start do
168
- RSpec::Interactive.start(ARGV, input_stream: STDIN, output_stream: @output_write, error_stream: @output_write)
175
+ @result = RSpec::Interactive.start(
176
+ ARGV,
177
+ config_file: config_path,
178
+ history_file: @history_temp_file.path,
179
+ input_stream: STDIN,
180
+ output_stream: @output_write,
181
+ error_stream: @error_write)
169
182
  end
170
183
 
171
184
  begin
172
185
  instance_eval &block
173
186
  rescue Exception => e
174
187
  failed = true
175
- Ansi.puts :red, "failed: #{name}\n#{e.message}"
188
+ STDERR.puts e.message
189
+ e.backtrace[0..5].each { |line| STDERR.puts " #{line}" }
176
190
  end
177
191
 
178
192
  await_termination
179
193
 
180
194
  if Readline.error
181
195
  failed = true
182
- Ansi.puts :red, "failed: #{name}\n#{Readline.error}"
196
+ STDOUT.puts Readline.error
183
197
  end
184
198
 
185
- if !failed
199
+ if failed
200
+ Ansi.puts :red, "failed: #{name}"
201
+ else
186
202
  Ansi.puts :green, "passed: #{name}"
187
203
  end
204
+ puts
188
205
  ensure
189
206
  @output_write.close
190
207
  @output_temp_file.close
208
+
209
+ @error_write.close
210
+ @error_temp_file.close
211
+
212
+ @history_temp_file.close
213
+
191
214
  Readline.reset
192
215
  end
193
216
 
@@ -213,9 +236,35 @@ class Test
213
236
  File.read(@output_temp_file.path).gsub("\e[0G", "")
214
237
  end
215
238
 
239
+ def error_output
240
+ @error_write.flush
241
+ @error_temp_file.rewind
242
+ File.read(@error_temp_file.path)
243
+ end
244
+
245
+ def expect_history(expected)
246
+ @history_temp_file.rewind
247
+ history = File.read(@history_temp_file.path)
248
+ if expected != history
249
+ raise "unexpected history:\n expected: #{expected.inspect}\n actual: #{history.inspect}"
250
+ end
251
+ end
252
+
216
253
  def expect_output(expected)
217
254
  if expected != output
218
255
  raise "unexpected output:\n expected: #{expected.inspect}\n actual: #{output.inspect}"
219
256
  end
220
257
  end
258
+
259
+ def expect_error_output(expected)
260
+ if expected != error_output
261
+ raise "unexpected error output:\n expected: #{expected.inspect}\n actual: #{error_output.inspect}"
262
+ end
263
+ end
264
+
265
+ def expect_result(expected)
266
+ if expected != @result
267
+ raise "unexpected result:\n expected: #{expected.inspect}\n actual: #{@result.inspect}"
268
+ end
269
+ end
221
270
  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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Dower
@@ -82,6 +82,7 @@ files:
82
82
  - rspec-interactive.gemspec
83
83
  - tests/debugged_spec_test.rb
84
84
  - tests/failing_spec_test.rb
85
+ - tests/invalid_config_test.rb
85
86
  - tests/passing_spec_test.rb
86
87
  - tests/support/ansi.rb
87
88
  - tests/support/test_helper.rb