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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 806c50acbafad7460f0a755f0bf56d6f38c7c28c9fad2726810d45bcd19c23fc
4
- data.tar.gz: 9958794c6f2f4d456246feeb2acae5576dc12a0565f697e0791e246b1fdfe83d
3
+ metadata.gz: fff025e27cecb118a9aca49be7611c62cf40da2dddd17d827320883c6e232acd
4
+ data.tar.gz: 99e64c381ca443afea9d34bb909b9fddc9d857aadb32beec52d677040885f553
5
5
  SHA512:
6
- metadata.gz: 458773150de314011f601648d4d50b48bdce862e6381ea21d19393ded0b9a3ac23a3691d1333cfc670f7ae00016091d61b5013032a9ab56f3290e57fe0810e1e
7
- data.tar.gz: 9969a1b44ed4a96cfc81262cabb41a6a86256007086211d0eb78b52263d572f929b0a7b8ff8c42764b33d56020492d22fffe766582a14f4720c491d6234175a3
6
+ metadata.gz: c73e4b56bc7e6a57ad70c8fec7719ed24502ffc121b99fee8d8058c13996296f68d69cf218c1d75e1da4b0078a251dda9e61769aad86354eef14fb6d8c8e0246
7
+ data.tar.gz: 7d44089f6ec20e24796892c8f395b4be545ee1ce87d4b327555b3620548afad35bb5a047a8ceec07ac391887b8ed8758d2f5b4ae1b4940389bd23590d03cb9f1
@@ -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
- report = Formatter.format(Ranker.call(snapshot))
24
- return report unless compare_last
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
- [report, Comparator.format_delta(previous, snapshot)].join("\n\n")
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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RspecSprint
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-sprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasu551