rspec-sprint 0.3.0 → 0.4.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/lib/rspec_sprint/cli.rb +21 -0
- data/lib/rspec_sprint/diagnosis.rb +10 -4
- data/lib/rspec_sprint/doctor.rb +3 -2
- data/lib/rspec_sprint/snapshot_store.rb +24 -0
- data/lib/rspec_sprint/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fff025e27cecb118a9aca49be7611c62cf40da2dddd17d827320883c6e232acd
|
|
4
|
+
data.tar.gz: 99e64c381ca443afea9d34bb909b9fddc9d857aadb32beec52d677040885f553
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c73e4b56bc7e6a57ad70c8fec7719ed24502ffc121b99fee8d8058c13996296f68d69cf218c1d75e1da4b0078a251dda9e61769aad86354eef14fb6d8c8e0246
|
|
7
|
+
data.tar.gz: 7d44089f6ec20e24796892c8f395b4be545ee1ce87d4b327555b3620548afad35bb5a047a8ceec07ac391887b8ed8758d2f5b4ae1b4940389bd23590d03cb9f1
|
data/lib/rspec_sprint/cli.rb
CHANGED
|
@@ -31,6 +31,27 @@ module RspecSprint
|
|
|
31
31
|
compare_last: options[:compare_last])
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
desc "compare [-- RSPEC_ARGS]", "Run your suite and save results for long-term tracking"
|
|
35
|
+
long_desc <<~DESC
|
|
36
|
+
Runs your RSpec suite once and (with --save-baseline) saves the result as a
|
|
37
|
+
named baseline in .rspec-sprint/baseline.json for long-term comparison.
|
|
38
|
+
|
|
39
|
+
Unlike the rolling snapshots used by `doctor --compare-last`, the baseline
|
|
40
|
+
is a permanent reference point that is never auto-pruned.
|
|
41
|
+
|
|
42
|
+
bundle exec rspec-sprint compare --save-baseline
|
|
43
|
+
bundle exec rspec-sprint compare --save-baseline -- spec/models
|
|
44
|
+
DESC
|
|
45
|
+
option :save_baseline, type: :boolean, default: false,
|
|
46
|
+
desc: "Save results as .rspec-sprint/baseline.json"
|
|
47
|
+
option :no_snapshot, type: :boolean, default: false,
|
|
48
|
+
desc: "Skip saving a rolling snapshot to .rspec-sprint/"
|
|
49
|
+
def compare(*rspec_args)
|
|
50
|
+
result = Collector.new(rspec_args: rspec_args).run
|
|
51
|
+
puts Doctor.diagnose(result, no_snapshot: options[:no_snapshot],
|
|
52
|
+
save_baseline: options[:save_baseline])
|
|
53
|
+
end
|
|
54
|
+
|
|
34
55
|
default_command :doctor
|
|
35
56
|
end
|
|
36
57
|
end
|
|
@@ -13,17 +13,23 @@ module RspecSprint
|
|
|
13
13
|
module Diagnosis
|
|
14
14
|
module_function
|
|
15
15
|
|
|
16
|
-
def from_files(rspec_json:, factory_prof_json: nil, save_snapshot: false, compare_last: false)
|
|
16
|
+
def from_files(rspec_json:, factory_prof_json: nil, save_snapshot: false, compare_last: false, save_baseline: false)
|
|
17
17
|
# Load previous BEFORE saving so "last" refers to the prior run, not this one.
|
|
18
18
|
previous = compare_last ? SnapshotStore.load_last : nil
|
|
19
19
|
|
|
20
20
|
snapshot = Normalizer.new(rspec_json: rspec_json, factory_prof_json: factory_prof_json).call
|
|
21
21
|
SnapshotStore.save(snapshot) if save_snapshot
|
|
22
|
+
SnapshotStore.save_baseline(snapshot) if save_baseline
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
sections = [Formatter.format(Ranker.call(snapshot))]
|
|
25
|
+
sections << Comparator.format_delta(previous, snapshot) if compare_last
|
|
26
|
+
sections << baseline_saved_msg if save_baseline
|
|
27
|
+
sections.join("\n\n")
|
|
28
|
+
end
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
def baseline_saved_msg
|
|
31
|
+
"ベースライン保存済み: #{SnapshotStore::BASELINE_PATH}\n" \
|
|
32
|
+
"(Baseline saved — run `rspec-sprint compare` to compare future runs)"
|
|
27
33
|
end
|
|
28
34
|
end
|
|
29
35
|
end
|
data/lib/rspec_sprint/doctor.rb
CHANGED
|
@@ -11,7 +11,7 @@ module RspecSprint
|
|
|
11
11
|
module Doctor
|
|
12
12
|
module_function
|
|
13
13
|
|
|
14
|
-
def diagnose(result, no_snapshot: false, compare_last: false)
|
|
14
|
+
def diagnose(result, no_snapshot: false, compare_last: false, save_baseline: false)
|
|
15
15
|
return diagnosis_impossible(result) unless result.rspec_json?
|
|
16
16
|
|
|
17
17
|
sections = []
|
|
@@ -21,7 +21,8 @@ module RspecSprint
|
|
|
21
21
|
rspec_json: result.rspec_json_path,
|
|
22
22
|
factory_prof_json: result.factory_prof? ? result.factory_prof_path : nil,
|
|
23
23
|
save_snapshot: !no_snapshot,
|
|
24
|
-
compare_last: compare_last
|
|
24
|
+
compare_last: compare_last,
|
|
25
|
+
save_baseline: save_baseline
|
|
25
26
|
)
|
|
26
27
|
sections.join("\n\n")
|
|
27
28
|
end
|
|
@@ -10,6 +10,7 @@ module RspecSprint
|
|
|
10
10
|
# Failure-safe: disk errors warn and skip; doctor never crashes because of us.
|
|
11
11
|
class SnapshotStore
|
|
12
12
|
DEFAULT_DIR = ".rspec-sprint/snapshots"
|
|
13
|
+
BASELINE_PATH = ".rspec-sprint/baseline.json"
|
|
13
14
|
MAX_SNAPSHOTS = 3
|
|
14
15
|
|
|
15
16
|
def self.save(snapshot, dir: DEFAULT_DIR)
|
|
@@ -20,6 +21,14 @@ module RspecSprint
|
|
|
20
21
|
new(dir: dir).load_last
|
|
21
22
|
end
|
|
22
23
|
|
|
24
|
+
def self.save_baseline(snapshot, path: BASELINE_PATH)
|
|
25
|
+
new.save_baseline(snapshot, path: path)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.load_baseline(path: BASELINE_PATH)
|
|
29
|
+
new.load_baseline(path: path)
|
|
30
|
+
end
|
|
31
|
+
|
|
23
32
|
def initialize(dir: DEFAULT_DIR)
|
|
24
33
|
@dir = dir
|
|
25
34
|
end
|
|
@@ -47,6 +56,21 @@ module RspecSprint
|
|
|
47
56
|
nil
|
|
48
57
|
end
|
|
49
58
|
|
|
59
|
+
# Saves snapshot as the named baseline (single file, never pruned).
|
|
60
|
+
def save_baseline(snapshot, path: BASELINE_PATH)
|
|
61
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
62
|
+
File.write(path, serialize(snapshot))
|
|
63
|
+
rescue Errno::EACCES, Errno::ENOSPC => e
|
|
64
|
+
warn "rspec-sprint: baseline not saved (#{e.class.name.split("::").last}: #{e.message})"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Returns the saved baseline as a symbol-keyed Hash, or nil if none.
|
|
68
|
+
def load_baseline(path: BASELINE_PATH)
|
|
69
|
+
JSON.parse(File.read(path), symbolize_names: true)
|
|
70
|
+
rescue JSON::ParserError, Errno::ENOENT
|
|
71
|
+
nil
|
|
72
|
+
end
|
|
73
|
+
|
|
50
74
|
private
|
|
51
75
|
|
|
52
76
|
def serialize(snapshot)
|
data/lib/rspec_sprint/version.rb
CHANGED