derail_specs 0.3.0 → 0.6.0
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 +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +2 -2
- data/README.md +34 -1
- data/bin/setup +3 -0
- data/example/Gemfile.lock +1 -1
- data/example/tests.sh +5 -0
- data/lib/derail_specs/boot.rb +12 -3
- data/lib/derail_specs/factory_bot.rb +4 -0
- data/lib/derail_specs/factory_bot_stub.rb +8 -0
- data/lib/derail_specs/initializer_hooks.rb +40 -0
- data/lib/derail_specs/server/app.rb +8 -0
- data/lib/derail_specs/transaction.rb +4 -1
- data/lib/derail_specs/version.rb +1 -1
- data/lib/derail_specs.rb +7 -1
- data/lib/generators/templates/config/initializers/derail_specs.rb +3 -1
- 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: f41316c2b4b33b60d06fb9a0a0b8fc647f93455e3a1a8978fd16f27b7c118b37
|
4
|
+
data.tar.gz: 4c3d831d2f467eb42fac527d07ff5edcb943b8ed36fc358ff239d5045acd3f6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b92ec87ddeabfc801dfaae6dab6f064ddf9b98dd4677bcef61041da677534944fcefc038f676f7b2f99dfec8e5c62b29ada587bd5c9aba366cad89994dbb32d9
|
7
|
+
data.tar.gz: e304ee8306d696348c44427febd0090912942cc4c07fc5334e1cea6d5aaf5521b8f72db997aa55fb6cdfbb5c991e71a7eddec9bbe251dfbf2a52f12ad596b836
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.0] - 2021-09-23
|
4
|
+
|
5
|
+
- Add /factory-bot/create-list to map to FactoryBot.create_list
|
6
|
+
|
7
|
+
## [0.5.1] - 2021-09-23
|
8
|
+
|
9
|
+
- Fixed a bug with Ruby 2.6 and Rails >= 6 where #bind_call (Ruby 2.7) was used instead of #bind#call
|
10
|
+
|
11
|
+
## [0.5.0] - 2021-09-17
|
12
|
+
|
13
|
+
- Add before_server_start and before_server_stop initializer hooks
|
14
|
+
|
15
|
+
## [0.4.0] - 2021-09-16
|
16
|
+
|
17
|
+
- Add infinite server mode, which can be used by not setting a command in the config
|
3
18
|
|
4
19
|
## [0.3.0] - 2021-09-16
|
5
20
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
derail_specs (0.
|
4
|
+
derail_specs (0.6.0)
|
5
5
|
puma (>= 3.8.0)
|
6
6
|
railties (>= 5.2.0)
|
7
7
|
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
parallel (1.21.0)
|
50
50
|
parser (3.0.2.0)
|
51
51
|
ast (~> 2.4.1)
|
52
|
-
puma (5.
|
52
|
+
puma (5.5.0)
|
53
53
|
nio4r (~> 2.0)
|
54
54
|
racc (1.5.2)
|
55
55
|
rack (2.2.3)
|
data/README.md
CHANGED
@@ -32,12 +32,18 @@ to include your test command:
|
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
DerailSpecs.configure do |config|
|
35
|
-
config.command = './tests.sh' # <-- your test command here
|
35
|
+
config.command = './tests.sh' # <-- your test command here, or blank for infinite mode
|
36
36
|
config.host = '127.0.0.1'
|
37
37
|
config.port = 3001
|
38
38
|
end
|
39
39
|
```
|
40
40
|
|
41
|
+
Alternatively, if you don't set a `config.command`, the server will boot in
|
42
|
+
*infinite* mode and will not stop until receiving an INT signal (IE Ctrl+c).
|
43
|
+
This is good for when your test command isn't available in a rails context,
|
44
|
+
like when you are running rails in docker, but have a test application running
|
45
|
+
on the host machine.
|
46
|
+
|
41
47
|
## Usage
|
42
48
|
|
43
49
|
To run tests, run
|
@@ -86,6 +92,33 @@ curl -X POST \
|
|
86
92
|
127.0.0.1:3001/factory-bot/create
|
87
93
|
```
|
88
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
|
+
```ruby
|
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
|
+
|
89
122
|
## Development
|
90
123
|
|
91
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/bin/setup
CHANGED
data/example/Gemfile.lock
CHANGED
data/example/tests.sh
CHANGED
@@ -6,3 +6,8 @@ curl -X POST \
|
|
6
6
|
-d '["test", { "name": "Test Name from Curl", "created_at": "2011-11-11 11:11:11" }]' \
|
7
7
|
-H 'Content-Type: application/json' \
|
8
8
|
127.0.0.1:3001/factory-bot/create
|
9
|
+
|
10
|
+
curl -X POST \
|
11
|
+
-d '["test", 3, { "name": "Test Name from Curl", "created_at": "2011-11-11 11:11:11" }]' \
|
12
|
+
-H 'Content-Type: application/json' \
|
13
|
+
127.0.0.1:3001/factory-bot/create-list
|
data/lib/derail_specs/boot.rb
CHANGED
@@ -3,21 +3,30 @@ 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
|
-
|
12
|
-
|
13
|
-
|
12
|
+
if command.present?
|
13
|
+
puts "Run: #{command}"
|
14
|
+
system command
|
15
|
+
else
|
16
|
+
loop { sleep 60 }
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
private
|
17
21
|
|
22
|
+
def command
|
23
|
+
DerailSpecs.configuration.command
|
24
|
+
end
|
25
|
+
|
18
26
|
def set_exit_hooks!
|
19
27
|
at_exit do
|
20
28
|
Transaction.rollback
|
29
|
+
DerailSpecs.hooks.run(:before_server_stop)
|
21
30
|
end
|
22
31
|
Signal.trap("INT") do
|
23
32
|
puts "Exiting derail_specs…"
|
@@ -1,6 +1,14 @@
|
|
1
1
|
module DerailSpecs
|
2
2
|
class FactoryBot
|
3
3
|
def self.create(*_)
|
4
|
+
not_installed_message
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.create_list(*_)
|
8
|
+
not_installed_message
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.not_installed_message
|
4
12
|
puts "factory_bot_rails is not installed in group :test"
|
5
13
|
puts "Please add factory_bot_rails to your Gemfile to use this feature"
|
6
14
|
end
|
@@ -0,0 +1,40 @@
|
|
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
|
+
|
26
|
+
@hooks[name].each(&:call)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def register(name, blk)
|
32
|
+
@hooks[name] ||= []
|
33
|
+
@hooks[name] << blk
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
reset!
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -15,6 +15,14 @@ module DerailSpecs
|
|
15
15
|
[202, { "Content-Type" => "application/json" }, [object.to_json]]
|
16
16
|
}
|
17
17
|
end
|
18
|
+
map "/factory-bot/create-list" do
|
19
|
+
run lambda { |env|
|
20
|
+
body = Rack::Request.new(env).body.gets
|
21
|
+
object = FactoryBot.create_list(*JSON.parse(body))
|
22
|
+
|
23
|
+
[202, { "Content-Type" => "application/json" }, [object.to_json]]
|
24
|
+
}
|
25
|
+
end
|
18
26
|
map "/" do
|
19
27
|
run Rails.application
|
20
28
|
end
|
@@ -78,7 +78,10 @@ module DerailSpecs
|
|
78
78
|
@legacy_saved_pool_configs ||= Hash.new { |hash, key| hash[key] = {} }
|
79
79
|
@saved_pool_configs ||= Hash.new { |hash, key| hash[key] = {} }
|
80
80
|
|
81
|
-
ActiveRecord::TestFixtures
|
81
|
+
ActiveRecord::TestFixtures
|
82
|
+
.instance_method(:setup_shared_connection_pool)
|
83
|
+
.bind(self)
|
84
|
+
.call
|
82
85
|
end
|
83
86
|
end
|
84
87
|
end
|
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.6.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-23 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
|