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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +27 -0
- data/example/Gemfile.lock +1 -1
- data/lib/derail_specs/boot.rb +2 -2
- data/lib/derail_specs/initializer_hooks.rb +42 -0
- data/lib/derail_specs/version.rb +1 -1
- data/lib/derail_specs.rb +7 -1
- data/lib/generators/templates/config/initializers/derail_specs.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90fd1d641de71a5a41d231af09190c33987e21efb49cd973fbef9671a9ef8cdb
|
4
|
+
data.tar.gz: 6eb5f40e29be236de49bf2625e54d04f33647f22c74862e6dd4fdf6ee891771a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba977461d31563b4d7dd4da9cf9217e4bba40b34f113170852f623d1a4a02e24963dbb64e6a9c18c7e0911824330ffe21636233446ce12c5f2efc03ce2258e0b
|
7
|
+
data.tar.gz: 969d0a9fa3c125ed4bcb707c3a5907616de8bd4567d081e0b8f23fc53056390fab0bc61418b72c0a27a5c7f88729573a1cbe52530169db20258c863e03161c7c
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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
data/lib/derail_specs/boot.rb
CHANGED
@@ -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
|
+
|
data/lib/derail_specs/version.rb
CHANGED
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(
|
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'
|
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
|
+
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-
|
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
|