pinspec 0.1.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 +7 -0
- data/CHANGELOG.md +133 -0
- data/LICENSE.txt +21 -0
- data/README.md +183 -0
- data/exe/pinspec +8 -0
- data/lib/pinspec/analyzer/app_profile_reader.rb +348 -0
- data/lib/pinspec/analyzer/factory_registry.rb +288 -0
- data/lib/pinspec/analyzer/inflector.rb +85 -0
- data/lib/pinspec/analyzer/schema_reader.rb +444 -0
- data/lib/pinspec/analyzer/source.rb +56 -0
- data/lib/pinspec/analyzer/target_parser.rb +710 -0
- data/lib/pinspec/cli.rb +585 -0
- data/lib/pinspec/emit/namer.rb +103 -0
- data/lib/pinspec/emit/spec_writer.rb +504 -0
- data/lib/pinspec/emit/stability_filter.rb +183 -0
- data/lib/pinspec/errors.rb +85 -0
- data/lib/pinspec/inputs/boundary.rb +112 -0
- data/lib/pinspec/inputs/corpus.rb +148 -0
- data/lib/pinspec/inputs/hydrator.rb +197 -0
- data/lib/pinspec/inputs/redactor.rb +138 -0
- data/lib/pinspec/inputs/sample_runner.rb +98 -0
- data/lib/pinspec/inputs/sampler.rb +187 -0
- data/lib/pinspec/report/summary.rb +348 -0
- data/lib/pinspec/runner/capture.rb +127 -0
- data/lib/pinspec/runner/probe_generator.rb +662 -0
- data/lib/pinspec/runner/sandbox.rb +121 -0
- data/lib/pinspec/setup/context_builder.rb +471 -0
- data/lib/pinspec/setup/dependency_resolver.rb +236 -0
- data/lib/pinspec/tags.rb +103 -0
- data/lib/pinspec/types.rb +497 -0
- data/lib/pinspec/validate/mutation_adapter.rb +108 -0
- data/lib/pinspec/validate/pin_scorer.rb +164 -0
- data/lib/pinspec/verify/verifier.rb +149 -0
- data/lib/pinspec/version.rb +8 -0
- data/lib/pinspec.rb +17 -0
- data/templates/factory_build.rb +54 -0
- data/templates/serializer.rb +243 -0
- data/templates/spec_support.rb +83 -0
- metadata +134 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PinspecSupport
|
|
4
|
+
def pinspec_guard_env!(expected)
|
|
5
|
+
actual = ENV["TZ"].to_s
|
|
6
|
+
return if expected.to_s.empty?
|
|
7
|
+
return if actual == expected.to_s
|
|
8
|
+
|
|
9
|
+
raise <<~MESSAGE
|
|
10
|
+
pinspec: this pin was captured with TZ=#{expected}, but this process has
|
|
11
|
+
TZ=#{actual.empty? ? '(unset)' : actual}.
|
|
12
|
+
|
|
13
|
+
The target reads the process clock (see the warning in this spec's header),
|
|
14
|
+
so the pinned values are only valid under the capture's timezone. Re-run with
|
|
15
|
+
TZ=#{expected}, or re-capture under this one.
|
|
16
|
+
MESSAGE
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def pinspec_refs(records, result = nil)
|
|
20
|
+
refs = {}
|
|
21
|
+
|
|
22
|
+
records.each do |name, record|
|
|
23
|
+
next if record.nil?
|
|
24
|
+
|
|
25
|
+
refs["#{record.class.table_name}:#{record.id}"] = name.to_s
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if defined?(ActiveRecord::Base) && result.is_a?(ActiveRecord::Base) && !result.id.nil?
|
|
29
|
+
refs["#{result.class.table_name}:#{result.id}"] = "__returned__"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
refs
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def pinspec_jobs_from(refs_for, fk_map)
|
|
36
|
+
pinspec_clear_sinks
|
|
37
|
+
result = yield
|
|
38
|
+
refs = refs_for.call(result)
|
|
39
|
+
|
|
40
|
+
jobs = ActiveJob::Base.queue_adapter.enqueued_jobs.map do |job|
|
|
41
|
+
{
|
|
42
|
+
"job" => job[:job].to_s,
|
|
43
|
+
"queue" => job[:queue].to_s,
|
|
44
|
+
"args" => PinspecSerializer.normalize(job[:args], refs: refs, fk_map: fk_map)
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
[result, jobs]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def pinspec_deliveries
|
|
52
|
+
ActionMailer::Base.deliveries.map do |mail|
|
|
53
|
+
{ "to" => Array(mail.to).join(","), "subject" => mail.subject.to_s }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def pinspec_clear_sinks
|
|
58
|
+
if defined?(ActiveJob::Base) && ActiveJob::Base.queue_adapter.respond_to?(:enqueued_jobs)
|
|
59
|
+
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
|
|
60
|
+
ActiveJob::Base.queue_adapter.performed_jobs.clear
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
ActionMailer::Base.deliveries.clear if defined?(ActionMailer::Base)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
RSpec.configure do |config|
|
|
68
|
+
config.include PinspecSupport, pinspec: true
|
|
69
|
+
|
|
70
|
+
config.around(:each, pinspec: true) do |example|
|
|
71
|
+
previous = defined?(ActiveJob::Base) ? ActiveJob::Base.queue_adapter : nil
|
|
72
|
+
ActiveJob::Base.queue_adapter = :test if defined?(ActiveJob::Base)
|
|
73
|
+
|
|
74
|
+
if defined?(ActionMailer::Base)
|
|
75
|
+
ActionMailer::Base.delivery_method = :test
|
|
76
|
+
ActionMailer::Base.perform_deliveries = true
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
example.run
|
|
80
|
+
|
|
81
|
+
ActiveJob::Base.queue_adapter = previous if previous
|
|
82
|
+
end
|
|
83
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pinspec
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rehan Munir
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: prism
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.0'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '2'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '1.0'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '2'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: thor
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - "~>"
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '1.2'
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - "~>"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '1.2'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: zeitwerk
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - "~>"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '2.6'
|
|
53
|
+
type: :runtime
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - "~>"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '2.6'
|
|
60
|
+
description: |
|
|
61
|
+
Point pinspec at a Rails service object or model method and it works out how to
|
|
62
|
+
invoke it, executes it against your test database, and emits an idiomatic RSpec
|
|
63
|
+
file that freezes the current behavior - then verifies that file runs green in
|
|
64
|
+
your app's own test environment.
|
|
65
|
+
email:
|
|
66
|
+
- rehanir.munir@gmail.com
|
|
67
|
+
executables:
|
|
68
|
+
- pinspec
|
|
69
|
+
extensions: []
|
|
70
|
+
extra_rdoc_files: []
|
|
71
|
+
files:
|
|
72
|
+
- CHANGELOG.md
|
|
73
|
+
- LICENSE.txt
|
|
74
|
+
- README.md
|
|
75
|
+
- exe/pinspec
|
|
76
|
+
- lib/pinspec.rb
|
|
77
|
+
- lib/pinspec/analyzer/app_profile_reader.rb
|
|
78
|
+
- lib/pinspec/analyzer/factory_registry.rb
|
|
79
|
+
- lib/pinspec/analyzer/inflector.rb
|
|
80
|
+
- lib/pinspec/analyzer/schema_reader.rb
|
|
81
|
+
- lib/pinspec/analyzer/source.rb
|
|
82
|
+
- lib/pinspec/analyzer/target_parser.rb
|
|
83
|
+
- lib/pinspec/cli.rb
|
|
84
|
+
- lib/pinspec/emit/namer.rb
|
|
85
|
+
- lib/pinspec/emit/spec_writer.rb
|
|
86
|
+
- lib/pinspec/emit/stability_filter.rb
|
|
87
|
+
- lib/pinspec/errors.rb
|
|
88
|
+
- lib/pinspec/inputs/boundary.rb
|
|
89
|
+
- lib/pinspec/inputs/corpus.rb
|
|
90
|
+
- lib/pinspec/inputs/hydrator.rb
|
|
91
|
+
- lib/pinspec/inputs/redactor.rb
|
|
92
|
+
- lib/pinspec/inputs/sample_runner.rb
|
|
93
|
+
- lib/pinspec/inputs/sampler.rb
|
|
94
|
+
- lib/pinspec/report/summary.rb
|
|
95
|
+
- lib/pinspec/runner/capture.rb
|
|
96
|
+
- lib/pinspec/runner/probe_generator.rb
|
|
97
|
+
- lib/pinspec/runner/sandbox.rb
|
|
98
|
+
- lib/pinspec/setup/context_builder.rb
|
|
99
|
+
- lib/pinspec/setup/dependency_resolver.rb
|
|
100
|
+
- lib/pinspec/tags.rb
|
|
101
|
+
- lib/pinspec/types.rb
|
|
102
|
+
- lib/pinspec/validate/mutation_adapter.rb
|
|
103
|
+
- lib/pinspec/validate/pin_scorer.rb
|
|
104
|
+
- lib/pinspec/verify/verifier.rb
|
|
105
|
+
- lib/pinspec/version.rb
|
|
106
|
+
- templates/factory_build.rb
|
|
107
|
+
- templates/serializer.rb
|
|
108
|
+
- templates/spec_support.rb
|
|
109
|
+
homepage: https://github.com/rehanmunir/pinspec
|
|
110
|
+
licenses:
|
|
111
|
+
- MIT
|
|
112
|
+
metadata:
|
|
113
|
+
source_code_uri: https://github.com/rehanmunir/pinspec
|
|
114
|
+
changelog_uri: https://github.com/rehanmunir/pinspec/blob/main/CHANGELOG.md
|
|
115
|
+
bug_tracker_uri: https://github.com/rehanmunir/pinspec/issues
|
|
116
|
+
rubygems_mfa_required: 'true'
|
|
117
|
+
rdoc_options: []
|
|
118
|
+
require_paths:
|
|
119
|
+
- lib
|
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 3.2.0
|
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - ">="
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: '0'
|
|
130
|
+
requirements: []
|
|
131
|
+
rubygems_version: 3.6.9
|
|
132
|
+
specification_version: 4
|
|
133
|
+
summary: Characterization-test harness for legacy Rails codebases.
|
|
134
|
+
test_files: []
|