rspec-interactive 0.7.0 → 0.7.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
  SHA256:
3
- metadata.gz: e1f9390c00756ace39f74e3af9d78410cf2890000285035537c2ec6ce6b9e861
4
- data.tar.gz: 8d07aec8a3fb5bc78849dbf403a3d30aeb1fec9bdbb38cef2204672e84ba3e9d
3
+ metadata.gz: ad5fba3e662512b5cce97181a4495493a2a4c04a302e616a02a8b8ab71361cd8
4
+ data.tar.gz: 28d14de9e9e05607adc35f5a03823cb11f9f93f87252316e3c6ee16d2655d9ff
5
5
  SHA512:
6
- metadata.gz: 8f585f27c12cc58f2ccb1f8a9d1baf5c05139b58244cba1daf0228c7a9ff8bff71bc0ad79bc0d87ae27ac7580138cb3607ae51c84f3a11d2443fe03f8eaff183
7
- data.tar.gz: d8bd001d9bd1be1b3cfa21ec69bcd70b9cb55f3d684bcc336f71e458aa20483a30ced6977c40e4055e9871698246e6e494f805a3fd210a3ec0310dfe72ef25e4
6
+ metadata.gz: 00f3ddf1f4e82d8a2590bb6b899ddacd470a7473c1aa32038b82cadd0ac664be5b8b86d96b13160cd8182f18d9a25843b948d694fa98cf6363fc49632c05b9b2
7
+ data.tar.gz: 8368023eb258fcd9df41b7497ca16112733f7a9513dc7a0830967652d52c5faec4ad61d613c9b9d5141945a0312db6a53a7981564cc76532befe512d0e4a3dbf
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ruby '3.0.0'
4
+
3
5
  source "https://rubygems.org"
4
6
 
5
7
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-interactive (0.6.1)
4
+ rspec-interactive (0.7.0)
5
5
  listen
6
6
  pry
7
7
  rspec-core
@@ -36,5 +36,8 @@ DEPENDENCIES
36
36
  rspec-expectations
37
37
  rspec-interactive!
38
38
 
39
+ RUBY VERSION
40
+ ruby 3.0.0p0
41
+
39
42
  BUNDLED WITH
40
43
  2.2.17
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RSpec Interactive
2
2
 
3
- An Pry console capable of running specs.
3
+ A Pry console capable of running specs.
4
4
 
5
5
  ## Installation & Configuration
6
6
 
@@ -17,7 +17,7 @@ RSpec::Interactive.configure do |config|
17
17
  # Directories to watch for file changes. When a file changes, it will be reloaded like `load 'path/to/file'`.
18
18
  config.watch_dirs += ["app", "lib", "config"]
19
19
 
20
- # This block is invoked on startup. RSpec configuration must happen here so that it can be reloaded before each test run.
20
+ # This block is invoked on startup. RSpec configuration must happen here so that it can be cached and reloaded before each test run.
21
21
  config.configure_rspec do
22
22
  require './spec/spec_helper.rb'
23
23
  end
@@ -26,6 +26,13 @@ RSpec::Interactive.configure do |config|
26
26
  config.on_class_load do |clazz|
27
27
  clazz.clear_validators! if clazz < ApplicationRecord
28
28
  end
29
+
30
+ # Invoked before each invocation of RSpec. Can also be manually invoked by typing `refresh` in the console.
31
+ # Any modified/added files will be loaded via `load` before invoking.
32
+ config.refresh do
33
+ FactoryBot.reload
34
+ Rails.application.reloader.reload!
35
+ end
29
36
  end
30
37
  ```
31
38
 
@@ -35,6 +42,27 @@ Update `.gitignore`
35
42
  echo '.rspec_interactive_history' >> .gitignore
36
43
  ```
37
44
 
45
+ ### A Note About FactoryBot
46
+
47
+ It is not possible to reload a file containing FactoryBot factory definitions via `load` because FactoryBot does not allow factories to be redefined. Be carefule not to add any directories to `watch_dirs` which contain factory definitions. Instead, you should configure the location of your factories like the following in your `spec_helper.rb`:
48
+
49
+ ```ruby
50
+ FactoryBot.definition_file_paths = %w(spec/factories)
51
+ FactoryBot.find_definitions
52
+ ```
53
+
54
+ Then add the following to your RSpec Interactive config
55
+
56
+ ```ruby
57
+ RSpec::Interactive.configure do |config|
58
+ config.refresh do
59
+ FactoryBot.reload
60
+ end
61
+ end
62
+ ```
63
+
64
+ This will cause factories to be reloaded before each test run and also whenever the `refresh` command is invoked in the console.
65
+
38
66
  ## Usage
39
67
 
40
68
  Optionally, specify a config file with `--config <config-file>`. Optionally, specify arguments to an initial RSpec invocation with `--initial-rspec-args <initial-rspec-args>`.
@@ -80,7 +108,6 @@ Run multiple specs:
80
108
  ```shell
81
109
  [6] pry(main)> rspec examples/passing_spec.rb examples/failing_spec.rb
82
110
  ```
83
-
84
111
  Debug a spec (use `exit` to resume while debugging):
85
112
 
86
113
  ```shell
@@ -9,6 +9,7 @@ require 'rspec-interactive/runner'
9
9
  require 'rspec-interactive/config'
10
10
  require 'rspec-interactive/rspec_config_cache'
11
11
  require 'rspec-interactive/input_completer'
12
+ require 'rspec-interactive/refresh_command'
12
13
  require 'rspec-interactive/rspec_command'
13
14
 
14
15
  module RSpec
@@ -38,12 +39,12 @@ module RSpec
38
39
  load config_file if config_file
39
40
 
40
41
  check_rails
41
- start_file_watcher
42
42
  trap_interrupt
43
43
  configure_pry
44
44
 
45
45
  @init_thread = Thread.start {
46
46
  @config_cache.record_configuration { @configuration.configure_rspec.call }
47
+ start_file_watcher
47
48
  }
48
49
 
49
50
  if initial_rspec_args
@@ -88,7 +89,7 @@ module RSpec
88
89
  return if @configuration.watch_dirs.empty?
89
90
 
90
91
  # Only polling seems to work in Docker.
91
- @listener = Listen.to(*@configuration.watch_dirs, only: /\.rb$/, force_polling: true) do |modified, added, removed|
92
+ @listener = Listen.to(*@configuration.watch_dirs, only: /\.rb$/, force_polling: true) do |modified, added|
92
93
  @mutex.synchronize do
93
94
  @updated_files.concat(added + modified)
94
95
  end
@@ -112,24 +113,10 @@ module RSpec
112
113
  Pry.config.history_file = @history_file
113
114
  end
114
115
 
115
- def self.rspec(args)
116
- if @init_thread&.alive?
117
- @init_thread.join
118
- @init_thread = nil
119
- end
120
-
121
- parsed_args = args.flat_map do |arg|
122
- if arg.match(/[\*\?\[]/)
123
- glob = Dir.glob(arg)
124
- glob.empty? ? [arg] : glob
125
- else
126
- [arg]
127
- end
128
- end
129
-
116
+ def self.refresh
130
117
  @mutex.synchronize do
131
118
  @updated_files.uniq.each do |filename|
132
- @output_stream.puts "modified: #{filename}"
119
+ @output_stream.puts "changed: #{filename}"
133
120
  trace = TracePoint.new(:class) do |tp|
134
121
  @configuration.on_class_load.call(tp.self)
135
122
  end
@@ -140,9 +127,30 @@ module RSpec
140
127
  end
141
128
  @updated_files.clear
142
129
  end
130
+ @configuration.refresh.call
131
+ end
132
+
133
+ def self.rspec(args)
134
+ parsed_args = args.flat_map do |arg|
135
+ if arg.match(/[\*\?\[]/)
136
+ glob = Dir.glob(arg)
137
+ glob.empty? ? [arg] : glob
138
+ else
139
+ [arg]
140
+ end
141
+ end
143
142
 
143
+ # Initialize the runner before waiting for the init thread so that the interrupt
144
+ # handler will cancel the RSpec invocation rather than kill the app.
144
145
  @runner = RSpec::Interactive::Runner.new(parsed_args)
145
146
 
147
+ if @init_thread&.alive?
148
+ @init_thread.join
149
+ @init_thread = nil
150
+ end
151
+
152
+ refresh
153
+
146
154
  # Stop saving history in case a new Pry session is started for debugging.
147
155
  Pry.config.history_save = false
148
156
 
@@ -1,12 +1,13 @@
1
1
  module RSpec
2
2
  module Interactive
3
3
  class Configuration
4
- attr_accessor :watch_dirs, :configure_rspec, :on_class_load
4
+ attr_accessor :watch_dirs, :configure_rspec, :on_class_load, :refresh
5
5
 
6
6
  def initialize
7
7
  @watch_dirs = []
8
8
  @configure_rspec = proc {}
9
9
  @on_class_load = proc {}
10
+ @refresh = proc {}
10
11
  end
11
12
 
12
13
  def configure_rspec(&block)
@@ -18,6 +19,11 @@ module RSpec
18
19
  return @on_class_load unless block
19
20
  @on_class_load = block
20
21
  end
22
+
23
+ def refresh(&block)
24
+ return @refresh unless block
25
+ @refresh = block
26
+ end
21
27
  end
22
28
  end
23
29
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec::Interactive
4
+ class RefreshCommand < Pry::ClassCommand
5
+ match 'refresh'
6
+ description "Load any files in watched directories which have changed since the last refresh or rspec invocation."
7
+
8
+ banner <<-BANNER
9
+ Usage: refresh
10
+ BANNER
11
+
12
+ command_options(
13
+ :keep_retval => false
14
+ )
15
+
16
+ def process
17
+ RSpec::Interactive.refresh
18
+ end
19
+
20
+ Pry::Commands.add_command(::RSpec::Interactive::RefreshCommand)
21
+ end
22
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Interactive
5
- VERSION = "0.7.0"
5
+ VERSION = "0.7.1"
6
6
  end
7
7
  end
data/scripts/release.sh CHANGED
@@ -23,3 +23,4 @@ gem build
23
23
  gem push rspec-interactive-$NEW_VERSION.gem
24
24
  bundle install
25
25
  git commit -a -m "v$NEW_VERSION Release"
26
+ open "https://github.com/nicholasdower/rspec-interactive/releases/new?title=v$NEW_VERSION%20Release&tag=v$NEW_VERSION&target=$(git rev-parse HEAD)"
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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Dower
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-23 00:00:00.000000000 Z
11
+ date: 2021-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
@@ -78,6 +78,7 @@ files:
78
78
  - lib/rspec-interactive.rb
79
79
  - lib/rspec-interactive/config.rb
80
80
  - lib/rspec-interactive/input_completer.rb
81
+ - lib/rspec-interactive/refresh_command.rb
81
82
  - lib/rspec-interactive/rspec_command.rb
82
83
  - lib/rspec-interactive/rspec_config_cache.rb
83
84
  - lib/rspec-interactive/runner.rb