derail_specs 0.2.0 → 0.5.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 +7 -2
- data/.rubocop_todo.yml +4 -20
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +1 -1
- data/README.md +56 -0
- data/bin/setup +3 -0
- data/example/Gemfile +1 -0
- data/example/Gemfile.lock +7 -1
- data/example/app/models/test.rb +2 -0
- data/example/db/migrate/20210916070010_create_tests.rb +9 -0
- data/example/db/schema.rb +21 -0
- data/example/factories.rb +5 -0
- data/example/tests.sh +5 -1
- data/lib/derail_specs/boot.rb +12 -3
- data/lib/derail_specs/factory_bot.rb +14 -0
- data/lib/derail_specs/factory_bot_stub.rb +8 -0
- data/lib/derail_specs/initializer_hooks.rb +42 -0
- data/lib/derail_specs/server/app.rb +8 -0
- data/lib/derail_specs/transaction.rb +1 -1
- data/lib/derail_specs/version.rb +1 -1
- data/lib/derail_specs.rb +8 -1
- data/lib/generators/templates/config/initializers/derail_specs.rb +2 -0
- data/lib/tasks/derail_specs.rake +1 -0
- metadata +9 -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/.rubocop.yml
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
|
+
AllCops:
|
4
|
+
NewCops: enable
|
5
|
+
Exclude:
|
6
|
+
- 'example/db/schema.rb'
|
7
|
+
- 'example/bin/*'
|
8
|
+
- 'vendor/**/*'
|
9
|
+
|
3
10
|
Style/StringLiterals:
|
4
11
|
Enabled: false
|
5
12
|
|
6
|
-
AllCops:
|
7
|
-
NewCops: enable
|
8
13
|
|
9
14
|
Style/Documentation:
|
10
15
|
Enabled: false
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2021-09-
|
3
|
+
# on 2021-09-16 08:00:52 UTC using RuboCop version 1.21.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -18,30 +18,14 @@ Gemspec/RequiredRubyVersion:
|
|
18
18
|
Metrics/AbcSize:
|
19
19
|
Max: 34
|
20
20
|
|
21
|
-
# Offense count:
|
22
|
-
# Configuration parameters: IgnoredMethods.
|
23
|
-
Metrics/CyclomaticComplexity:
|
24
|
-
Max: 9
|
25
|
-
|
26
|
-
# Offense count: 6
|
21
|
+
# Offense count: 4
|
27
22
|
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
28
23
|
Metrics/MethodLength:
|
29
24
|
Max: 20
|
30
25
|
|
31
|
-
# Offense count:
|
32
|
-
# Configuration parameters: IgnoredMethods.
|
33
|
-
Metrics/PerceivedComplexity:
|
34
|
-
Max: 9
|
35
|
-
|
36
|
-
# Offense count: 1
|
37
|
-
# Cop supports --auto-correct.
|
38
|
-
Style/IfUnlessModifier:
|
39
|
-
Exclude:
|
40
|
-
- 'example/bin/bundle'
|
41
|
-
|
42
|
-
# Offense count: 4
|
26
|
+
# Offense count: 3
|
43
27
|
# Cop supports --auto-correct.
|
44
28
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
45
29
|
# URISchemes: http, https
|
46
30
|
Layout/LineLength:
|
47
|
-
Max:
|
31
|
+
Max: 127
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
|
4
|
+
## [0.5.0] - 2021-09-17
|
5
|
+
|
6
|
+
- Add before_server_start and before_server_stop initializer hooks
|
7
|
+
|
8
|
+
## [0.4.0] - 2021-09-16
|
9
|
+
|
10
|
+
- Add infinite server mode, which can be used by not setting a command in the config
|
11
|
+
-
|
12
|
+
## [0.3.0] - 2021-09-16
|
13
|
+
|
14
|
+
- Add `/factory-bot/create` route to map to FactoryBot.create
|
15
|
+
- Run `rake derail_specs:run` in Rails test environment
|
16
|
+
|
17
|
+
## [0.2.1] - 2021-09-15
|
18
|
+
|
19
|
+
- Fix Rails 5.2 missing method `ActiveRecord::TestFixtures.setup_shared_connection_pool`
|
20
|
+
|
3
21
|
## [0.2.0] - 2021-09-15
|
4
22
|
|
5
23
|
- Initial release
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -38,6 +38,12 @@ DerailSpecs.configure do |config|
|
|
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
|
@@ -63,6 +69,56 @@ beforeEach(async () => {
|
|
63
69
|
});
|
64
70
|
```
|
65
71
|
|
72
|
+
### FactoryBot.create
|
73
|
+
|
74
|
+
Post with a JSON array to `/factory-bot/create` with the following structure:
|
75
|
+
|
76
|
+
```JSON
|
77
|
+
["test", { "name": "Test Name", "created_at": "2011-11-11 11:11:11" }]
|
78
|
+
````
|
79
|
+
|
80
|
+
which will run:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
FactoryBot.create(:test, name: "Test Name", created_at: "2011-11-11 11:11:11")
|
84
|
+
```
|
85
|
+
|
86
|
+
Example curl:
|
87
|
+
|
88
|
+
```bash
|
89
|
+
curl -X POST \
|
90
|
+
-d '["test", { "name": "Test Name from Curl", "created_at": "2011-11-11 11:11:11" }]' \
|
91
|
+
-H 'Content-Type: application/json' \
|
92
|
+
127.0.0.1:3001/factory-bot/create
|
93
|
+
```
|
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
|
+
|
66
122
|
## Development
|
67
123
|
|
68
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
CHANGED
data/example/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
derail_specs (0.
|
4
|
+
derail_specs (0.5.0)
|
5
5
|
puma (>= 3.8.0)
|
6
6
|
railties (>= 5.2.0)
|
7
7
|
|
@@ -72,6 +72,11 @@ GEM
|
|
72
72
|
concurrent-ruby (1.1.9)
|
73
73
|
crass (1.0.6)
|
74
74
|
erubi (1.10.0)
|
75
|
+
factory_bot (6.2.0)
|
76
|
+
activesupport (>= 5.0.0)
|
77
|
+
factory_bot_rails (6.2.0)
|
78
|
+
factory_bot (~> 6.2.0)
|
79
|
+
railties (>= 5.0.0)
|
75
80
|
globalid (0.5.2)
|
76
81
|
activesupport (>= 5.0)
|
77
82
|
i18n (1.8.10)
|
@@ -147,6 +152,7 @@ PLATFORMS
|
|
147
152
|
|
148
153
|
DEPENDENCIES
|
149
154
|
derail_specs!
|
155
|
+
factory_bot_rails
|
150
156
|
pry-rails
|
151
157
|
puma (~> 5.0)
|
152
158
|
rails (~> 6.1.4, >= 6.1.4.1)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 2021_09_16_070010) do
|
14
|
+
|
15
|
+
create_table "tests", force: :cascade do |t|
|
16
|
+
t.string "name"
|
17
|
+
t.datetime "created_at", precision: 6, null: false
|
18
|
+
t.datetime "updated_at", precision: 6, null: false
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/example/tests.sh
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
-
curl 127.0.0.1:3001
|
3
|
+
curl -s 127.0.0.1:3001 > /dev/null
|
4
4
|
curl 127.0.0.1:3001/reset-transaction
|
5
|
+
curl -X POST \
|
6
|
+
-d '["test", { "name": "Test Name from Curl", "created_at": "2011-11-11 11:11:11" }]' \
|
7
|
+
-H 'Content-Type: application/json' \
|
8
|
+
127.0.0.1:3001/factory-bot/create
|
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…"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
gem 'factory_bot_rails'
|
3
|
+
require 'factory_bot_rails'
|
4
|
+
|
5
|
+
module DerailSpecs
|
6
|
+
class FactoryBot
|
7
|
+
def self.create(factory, options = nil)
|
8
|
+
::FactoryBot.create(factory, options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
rescue Gem::LoadError
|
13
|
+
require_relative 'factory_bot_stub'
|
14
|
+
end
|
@@ -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
|
+
|
@@ -7,6 +7,14 @@ module DerailSpecs
|
|
7
7
|
[202, { "Content-Type" => "text/plain" }, ["Accepted"]]
|
8
8
|
}
|
9
9
|
end
|
10
|
+
map "/factory-bot/create" do
|
11
|
+
run lambda { |env|
|
12
|
+
body = Rack::Request.new(env).body.gets
|
13
|
+
object = FactoryBot.create(*JSON.parse(body))
|
14
|
+
|
15
|
+
[202, { "Content-Type" => "application/json" }, [object.to_json]]
|
16
|
+
}
|
17
|
+
end
|
10
18
|
map "/" do
|
11
19
|
run Rails.application
|
12
20
|
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,
|
@@ -22,3 +27,5 @@ end
|
|
22
27
|
require 'derail_specs/boot'
|
23
28
|
require 'derail_specs/transaction'
|
24
29
|
require 'derail_specs/railtie'
|
30
|
+
require 'derail_specs/factory_bot'
|
31
|
+
require 'derail_specs/initializer_hooks'
|
data/lib/tasks/derail_specs.rake
CHANGED
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
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- example/Rakefile
|
68
68
|
- example/app/controllers/application_controller.rb
|
69
69
|
- example/app/models/application_record.rb
|
70
|
+
- example/app/models/test.rb
|
70
71
|
- example/app/views/layouts/application.html.erb
|
71
72
|
- example/bin/bundle
|
72
73
|
- example/bin/rails
|
@@ -94,6 +95,9 @@ files:
|
|
94
95
|
- example/config/locales/en.yml
|
95
96
|
- example/config/puma.rb
|
96
97
|
- example/config/routes.rb
|
98
|
+
- example/db/migrate/20210916070010_create_tests.rb
|
99
|
+
- example/db/schema.rb
|
100
|
+
- example/factories.rb
|
97
101
|
- example/public/404.html
|
98
102
|
- example/public/422.html
|
99
103
|
- example/public/500.html
|
@@ -104,6 +108,9 @@ files:
|
|
104
108
|
- example/tests.sh
|
105
109
|
- lib/derail_specs.rb
|
106
110
|
- lib/derail_specs/boot.rb
|
111
|
+
- lib/derail_specs/factory_bot.rb
|
112
|
+
- lib/derail_specs/factory_bot_stub.rb
|
113
|
+
- lib/derail_specs/initializer_hooks.rb
|
107
114
|
- lib/derail_specs/railtie.rb
|
108
115
|
- lib/derail_specs/server.rb
|
109
116
|
- lib/derail_specs/server/app.rb
|