Module: Differ
- Defined in:
- lib/rspec/flaky/differ.rb
Constant Summary collapse
- EXPECTED_CONTENT =
%w(failed.json passed.json)
Class Method Summary collapse
- .contains_passed_and_failed_jsons?(tables_dir) ⇒ Boolean
- .create_summary_folder ⇒ Object
- .get_diffs(tables_dir) ⇒ Object
- .get_result ⇒ Object
- .read_jsons(pathes) ⇒ Object
Class Method Details
.contains_passed_and_failed_jsons?(tables_dir) ⇒ Boolean
54 55 56 57 |
# File 'lib/rspec/flaky/differ.rb', line 54 def contains_passed_and_failed_jsons? tables_dir actual_content = tables_dir.children.map(&:basename).map(&:to_s) EXPECTED_CONTENT & actual_content == EXPECTED_CONTENT end |
.create_summary_folder ⇒ Object
27 28 29 |
# File 'lib/rspec/flaky/differ.rb', line 27 def create_summary_folder FileUtils.mkdir_p(Pathes.summary_path) end |
.get_diffs(tables_dir) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rspec/flaky/differ.rb', line 31 def get_diffs tables_dir return 'no_content' unless contains_passed_and_failed_jsons? tables_dir result = [] jsons = tables_dir.children.select { |child| EXPECTED_CONTENT.include? child.basename.to_s } jsons = read_jsons(jsons) return 'empty_table' if jsons.values.all? &:empty? jsons.values.map(&:length).max.times do |idx| passed_record = jsons["passed"].try(:[], idx) || {} failed_record = jsons["failed"].try(:[], idx) || {} result << Hashdiff.diff(passed_record, failed_record) end result end |
.get_result ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rspec/flaky/differ.rb', line 9 def get_result create_summary_folder @diffs = [] Pathes.summary_path.children.each do |example_dir| next unless example_dir.directory? next unless example_dir.basename.to_s.start_with?(".:") example_dir.children.select do |tables_dir| next unless tables_dir.directory? @diffs << { location: Pathes.relative_path(example_dir), table: tables_dir.basename.to_s, result: get_diffs(tables_dir) } end end Drawer.draw @diffs end |