derail_specs 0.4.0 → 0.5.0

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: 1ca53c48f235d3cd9caf87c214bf4683b60cdf8e6211e3c65fa62a9dcdf5e45f
4
- data.tar.gz: 00ced973776c36fb38a419603ca5c00971f5f61f883e92b8a4e20add8c1b0d72
3
+ metadata.gz: 90fd1d641de71a5a41d231af09190c33987e21efb49cd973fbef9671a9ef8cdb
4
+ data.tar.gz: 6eb5f40e29be236de49bf2625e54d04f33647f22c74862e6dd4fdf6ee891771a
5
5
  SHA512:
6
- metadata.gz: 87242fbd1dab956f9eb10d7aed765d5d9f406a04fbb4008790d0623b833de7f59a8a3973659fd411ca3fa98cc38c09f12ea686413af5c70ce890c20ee596cedd
7
- data.tar.gz: c116887a284320c09f4e01503f1e48d171ee35aac750eeb33b03711719cf5a6d0ca50ec6650bda40541f1f6428c9709a9fd46835ea276731e26b5845bad614f2
6
+ metadata.gz: ba977461d31563b4d7dd4da9cf9217e4bba40b34f113170852f623d1a4a02e24963dbb64e6a9c18c7e0911824330ffe21636233446ce12c5f2efc03ce2258e0b
7
+ data.tar.gz: 969d0a9fa3c125ed4bcb707c3a5907616de8bd4567d081e0b8f23fc53056390fab0bc61418b72c0a27a5c7f88729573a1cbe52530169db20258c863e03161c7c
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
3
 
4
+ ## [0.5.0] - 2021-09-17
5
+
6
+ - Add before_server_start and before_server_stop initializer hooks
7
+
4
8
  ## [0.4.0] - 2021-09-16
5
9
 
6
10
  - Add infinite server mode, which can be used by not setting a command in the config
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- derail_specs (0.4.0)
4
+ derail_specs (0.5.0)
5
5
  puma (>= 3.8.0)
6
6
  railties (>= 5.2.0)
7
7
 
data/README.md CHANGED
@@ -92,6 +92,33 @@ curl -X POST \
92
92
  127.0.0.1:3001/factory-bot/create
93
93
  ```
94
94
 
95
+ ### Initializer Hooks
96
+
97
+ By default, DerailSpecs doesn't run any fixtures. You can configure global fixture
98
+ loading with initializer hooks in `config/initializers/derail_specs.rb`:
99
+
100
+ ```
101
+ return unless Rails.env.test?
102
+
103
+ DerailSpecs.hooks.before_server_start do
104
+ # Add our fixtures before the resettable transaction is started
105
+ fixtures_dir = Rails.root.join("spec/fixtures")
106
+ fixture_files = Dir.glob(fixtures_dir.join("**/*.yml")).map do |f|
107
+ f[(fixtures_dir.to_s.size + 1)..-5]
108
+ end
109
+
110
+ @fixtures = ActiveRecord::FixtureSet.create_fixtures(
111
+ fixtures_dir,
112
+ fixture_files,
113
+ )
114
+ end
115
+
116
+ DerailSpecs.hooks.before_server_stop do
117
+ @fixtures.map(&:model_class).each(&:delete_all)
118
+ end
119
+ ```
120
+
121
+
95
122
  ## Development
96
123
 
97
124
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/example/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- derail_specs (0.4.0)
4
+ derail_specs (0.5.0)
5
5
  puma (>= 3.8.0)
6
6
  railties (>= 5.2.0)
7
7
 
@@ -3,13 +3,12 @@ require_relative 'server'
3
3
  module DerailSpecs
4
4
  class Boot
5
5
  def run
6
+ DerailSpecs.hooks.run(:before_server_start)
6
7
  Transaction.begin
7
8
  set_exit_hooks!
8
9
 
9
10
  Server.new.tap(&:boot)
10
11
 
11
- puts "Starting Tests…"
12
-
13
12
  if command.present?
14
13
  puts "Run: #{command}"
15
14
  system command
@@ -27,6 +26,7 @@ module DerailSpecs
27
26
  def set_exit_hooks!
28
27
  at_exit do
29
28
  Transaction.rollback
29
+ DerailSpecs.hooks.run(:before_server_stop)
30
30
  end
31
31
  Signal.trap("INT") do
32
32
  puts "Exiting derail_specs…"
@@ -0,0 +1,42 @@
1
+ module DerailSpecs
2
+ def self.hooks
3
+ InitializerHooks.instance
4
+ end
5
+
6
+ class InitializerHooks
7
+ def self.instance
8
+ @instance ||= new
9
+ end
10
+
11
+ def before_server_start(&blk)
12
+ register(:before_server_start, blk)
13
+ end
14
+
15
+ def before_server_stop(&blk)
16
+ register(:before_server_stop, blk)
17
+ end
18
+
19
+ def reset!
20
+ @hooks = {}
21
+ end
22
+
23
+ def run(name)
24
+ return unless @hooks[name]
25
+ @hooks[name].each do |blk|
26
+ blk.call
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def register(name, blk)
33
+ @hooks[name] ||= []
34
+ @hooks[name] << blk
35
+ end
36
+
37
+ def initialize
38
+ reset!
39
+ end
40
+ end
41
+ end
42
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DerailSpecs
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/derail_specs.rb CHANGED
@@ -7,7 +7,12 @@ module DerailSpecs
7
7
 
8
8
  def self.configuration
9
9
  @configuration ||= Struct
10
- .new(:command, :host, :port, keyword_init: true)
10
+ .new(
11
+ :command,
12
+ :host,
13
+ :port,
14
+ keyword_init: true,
15
+ )
11
16
  .new(
12
17
  host: '127.0.0.1',
13
18
  port: 3001,
@@ -23,3 +28,4 @@ require 'derail_specs/boot'
23
28
  require 'derail_specs/transaction'
24
29
  require 'derail_specs/railtie'
25
30
  require 'derail_specs/factory_bot'
31
+ require 'derail_specs/initializer_hooks'
@@ -1,3 +1,5 @@
1
+ return unless Rails.test.env?
2
+
1
3
  DerailSpecs.configure do |config|
2
4
  config.command = './tests.sh'
3
5
  config.host = '127.0.0.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: derail_specs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Piechowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-16 00:00:00.000000000 Z
11
+ date: 2021-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -110,6 +110,7 @@ files:
110
110
  - lib/derail_specs/boot.rb
111
111
  - lib/derail_specs/factory_bot.rb
112
112
  - lib/derail_specs/factory_bot_stub.rb
113
+ - lib/derail_specs/initializer_hooks.rb
113
114
  - lib/derail_specs/railtie.rb
114
115
  - lib/derail_specs/server.rb
115
116
  - lib/derail_specs/server/app.rb