Class: RspecSprint::Fixers::LetItBe::Verifier
- Inherits:
-
Object
- Object
- RspecSprint::Fixers::LetItBe::Verifier
- Defined in:
- lib/rspec_sprint/fixers/let_it_be/verifier.rb
Overview
runner: call(path) -> Boolean, duration: Float git_clean: call(path) -> Boolean(省略時は git status –porcelain を実行)
Instance Method Summary collapse
-
#initialize(runner:, dir: ".", git_clean: nil) ⇒ Verifier
constructor
A new instance of Verifier.
- #verify_file(path, candidates) ⇒ Object
Constructor Details
#initialize(runner:, dir: ".", git_clean: nil) ⇒ Verifier
Returns a new instance of Verifier.
25 26 27 28 29 |
# File 'lib/rspec_sprint/fixers/let_it_be/verifier.rb', line 25 def initialize(runner:, dir: ".", git_clean: nil) @runner = runner @dir = dir @git_clean_fn = git_clean end |
Instance Method Details
#verify_file(path, candidates) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rspec_sprint/fixers/let_it_be/verifier.rb', line 31 def verify_file(path, candidates) unless file_clean?(path) return FileResult.new(file: path, applied: [], reverted: [], skipped: candidates, baseline_s: nil, after_s: nil, status: :skipped_dirty) end source_backup = File.read(path) b1 = @runner.call(path) b2 = @runner.call(path) unless b1[:green] && b2[:green] return FileResult.new(file: path, applied: [], reverted: [], skipped: candidates, baseline_s: nil, after_s: nil, status: :skipped_unstable) end baseline_s = (b1[:duration] + b2[:duration]) / 2.0 rewritten = Rewriter.rewrite(source_backup, candidates) File.write(path, rewritten) r1 = @runner.call(path) r2 = @runner.call(path) if r1[:green] && r2[:green] after_s = (r1[:duration] + r2[:duration]) / 2.0 if improvement_sufficient?(baseline_s, after_s) return FileResult.new(file: path, applied: candidates, reverted: [], skipped: [], baseline_s: baseline_s, after_s: after_s, status: :accepted) else File.write(path, source_backup) return FileResult.new(file: path, applied: [], reverted: candidates, skipped: [], baseline_s: baseline_s, after_s: after_s, status: :reverted_slow) end else File.write(path, source_backup) bisect(path, candidates, source_backup, baseline_s) end end |