derail_specs 0.4.0 → 0.6.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 +4 -4
- data/CHANGELOG.md +17 -1
- data/README.md +29 -2
- data/bin/test +11 -0
- data/example/Gemfile.lock +1 -1
- data/example/tests.sh +5 -0
- data/lib/derail_specs/boot.rb +3 -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 +4 -3
- data/Gemfile.lock +0 -122
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8b54899a77d83026a909627639d48c24d9174e4069bd1a4e242666265c9a8c2
|
4
|
+
data.tar.gz: 42cde73f7dc9e73dd79f6b2138bf137a308170e1f891a4f1e6dbc1d4e1b20383
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 015e4dcb1c5fdf6c46ef12f4a2351054b59b427bcb065163667e89003a834c86c71e2bc13af12c9b3aab105c4f3e028d13c8e80579c45523b08d6121a722d308
|
7
|
+
data.tar.gz: aec06f8aed5fdc6606c28d63b9b3729b42011b165ebda41c27a953a756723f18252553e8e9442c40e1fc4aca18bde22ef5d087a9ec5e9032faf0c3ff8dd5a6c0
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,26 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.1] - 2021-09-27
|
4
|
+
|
5
|
+
- Change exit status of `rails derail_specs:run` to match config.command exit status when command is provided
|
6
|
+
- Fix template initializer Rails.env.test? typo (jasonfb, #4)
|
7
|
+
|
8
|
+
## [0.6.0] - 2021-09-23
|
9
|
+
|
10
|
+
- Add /factory-bot/create-list to map to FactoryBot.create_list
|
11
|
+
|
12
|
+
## [0.5.1] - 2021-09-23
|
13
|
+
|
14
|
+
- Fixed a bug with Ruby 2.6 and Rails >= 6 where #bind_call (Ruby 2.7) was used instead of #bind#call
|
15
|
+
|
16
|
+
## [0.5.0] - 2021-09-17
|
17
|
+
|
18
|
+
- Add before_server_start and before_server_stop initializer hooks
|
3
19
|
|
4
20
|
## [0.4.0] - 2021-09-16
|
5
21
|
|
6
22
|
- Add infinite server mode, which can be used by not setting a command in the config
|
7
|
-
|
23
|
+
|
8
24
|
## [0.3.0] - 2021-09-16
|
9
25
|
|
10
26
|
- Add `/factory-bot/create` route to map to FactoryBot.create
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ 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
|
@@ -92,9 +92,36 @@ 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
|
+
```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
|
+
|
95
122
|
## Development
|
96
123
|
|
97
|
-
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.
|
124
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the rspec tests and `bin/test` to run all tests, including sample rails app tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
98
125
|
|
99
126
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
100
127
|
|
data/bin/test
ADDED
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,16 +3,15 @@ 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
|
-
system
|
14
|
+
exit system(command)
|
16
15
|
else
|
17
16
|
loop { sleep 60 }
|
18
17
|
end
|
@@ -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…"
|
@@ -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.1
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puma
|
@@ -52,12 +52,12 @@ files:
|
|
52
52
|
- CHANGELOG.md
|
53
53
|
- CODE_OF_CONDUCT.md
|
54
54
|
- Gemfile
|
55
|
-
- Gemfile.lock
|
56
55
|
- LICENSE.txt
|
57
56
|
- README.md
|
58
57
|
- Rakefile
|
59
58
|
- bin/console
|
60
59
|
- bin/setup
|
60
|
+
- bin/test
|
61
61
|
- derail_specs.gemspec
|
62
62
|
- example/.gitignore
|
63
63
|
- example/.ruby-version
|
@@ -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
|
data/Gemfile.lock
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
derail_specs (0.4.0)
|
5
|
-
puma (>= 3.8.0)
|
6
|
-
railties (>= 5.2.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
actionpack (6.1.4.1)
|
12
|
-
actionview (= 6.1.4.1)
|
13
|
-
activesupport (= 6.1.4.1)
|
14
|
-
rack (~> 2.0, >= 2.0.9)
|
15
|
-
rack-test (>= 0.6.3)
|
16
|
-
rails-dom-testing (~> 2.0)
|
17
|
-
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
-
actionview (6.1.4.1)
|
19
|
-
activesupport (= 6.1.4.1)
|
20
|
-
builder (~> 3.1)
|
21
|
-
erubi (~> 1.4)
|
22
|
-
rails-dom-testing (~> 2.0)
|
23
|
-
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
-
activesupport (6.1.4.1)
|
25
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
|
-
i18n (>= 1.6, < 2)
|
27
|
-
minitest (>= 5.1)
|
28
|
-
tzinfo (~> 2.0)
|
29
|
-
zeitwerk (~> 2.3)
|
30
|
-
ast (2.4.2)
|
31
|
-
builder (3.2.4)
|
32
|
-
concurrent-ruby (1.1.9)
|
33
|
-
crass (1.0.6)
|
34
|
-
diff-lcs (1.4.4)
|
35
|
-
erubi (1.10.0)
|
36
|
-
generator_spec (0.9.4)
|
37
|
-
activesupport (>= 3.0.0)
|
38
|
-
railties (>= 3.0.0)
|
39
|
-
i18n (1.8.10)
|
40
|
-
concurrent-ruby (~> 1.0)
|
41
|
-
loofah (2.12.0)
|
42
|
-
crass (~> 1.0.2)
|
43
|
-
nokogiri (>= 1.5.9)
|
44
|
-
method_source (1.0.0)
|
45
|
-
minitest (5.14.4)
|
46
|
-
nio4r (2.5.8)
|
47
|
-
nokogiri (1.12.4-x86_64-linux)
|
48
|
-
racc (~> 1.4)
|
49
|
-
parallel (1.21.0)
|
50
|
-
parser (3.0.2.0)
|
51
|
-
ast (~> 2.4.1)
|
52
|
-
puma (5.4.0)
|
53
|
-
nio4r (~> 2.0)
|
54
|
-
racc (1.5.2)
|
55
|
-
rack (2.2.3)
|
56
|
-
rack-test (1.1.0)
|
57
|
-
rack (>= 1.0, < 3)
|
58
|
-
rails-dom-testing (2.0.3)
|
59
|
-
activesupport (>= 4.2.0)
|
60
|
-
nokogiri (>= 1.6)
|
61
|
-
rails-html-sanitizer (1.4.2)
|
62
|
-
loofah (~> 2.3)
|
63
|
-
railties (6.1.4.1)
|
64
|
-
actionpack (= 6.1.4.1)
|
65
|
-
activesupport (= 6.1.4.1)
|
66
|
-
method_source
|
67
|
-
rake (>= 0.13)
|
68
|
-
thor (~> 1.0)
|
69
|
-
rainbow (3.0.0)
|
70
|
-
rake (13.0.6)
|
71
|
-
regexp_parser (2.1.1)
|
72
|
-
rexml (3.2.5)
|
73
|
-
rspec (3.10.0)
|
74
|
-
rspec-core (~> 3.10.0)
|
75
|
-
rspec-expectations (~> 3.10.0)
|
76
|
-
rspec-mocks (~> 3.10.0)
|
77
|
-
rspec-core (3.10.1)
|
78
|
-
rspec-support (~> 3.10.0)
|
79
|
-
rspec-expectations (3.10.1)
|
80
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
81
|
-
rspec-support (~> 3.10.0)
|
82
|
-
rspec-mocks (3.10.2)
|
83
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
84
|
-
rspec-support (~> 3.10.0)
|
85
|
-
rspec-support (3.10.2)
|
86
|
-
rubocop (1.21.0)
|
87
|
-
parallel (~> 1.10)
|
88
|
-
parser (>= 3.0.0.0)
|
89
|
-
rainbow (>= 2.2.2, < 4.0)
|
90
|
-
regexp_parser (>= 1.8, < 3.0)
|
91
|
-
rexml
|
92
|
-
rubocop-ast (>= 1.9.1, < 2.0)
|
93
|
-
ruby-progressbar (~> 1.7)
|
94
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
95
|
-
rubocop-ast (1.11.0)
|
96
|
-
parser (>= 3.0.1.1)
|
97
|
-
rubocop-rake (0.6.0)
|
98
|
-
rubocop (~> 1.0)
|
99
|
-
rubocop-rspec (2.4.0)
|
100
|
-
rubocop (~> 1.0)
|
101
|
-
rubocop-ast (>= 1.1.0)
|
102
|
-
ruby-progressbar (1.11.0)
|
103
|
-
thor (1.1.0)
|
104
|
-
tzinfo (2.0.4)
|
105
|
-
concurrent-ruby (~> 1.0)
|
106
|
-
unicode-display_width (2.0.0)
|
107
|
-
zeitwerk (2.4.2)
|
108
|
-
|
109
|
-
PLATFORMS
|
110
|
-
x86_64-linux
|
111
|
-
|
112
|
-
DEPENDENCIES
|
113
|
-
derail_specs!
|
114
|
-
generator_spec
|
115
|
-
rake (~> 13.0)
|
116
|
-
rspec (~> 3.0)
|
117
|
-
rubocop (~> 1.7)
|
118
|
-
rubocop-rake
|
119
|
-
rubocop-rspec
|
120
|
-
|
121
|
-
BUNDLED WITH
|
122
|
-
2.2.27
|