From 37ccbc2b6e250f2e4c1876d455be880295282336 Mon Sep 17 00:00:00 2001 From: st0012 Date: Sun, 28 Jun 2020 16:01:50 +0800 Subject: [PATCH] Add force_recording option for debugging When debugging tapping_device, it's easy to forget about the configs that have been set and get confused by the result. By using the `force_recording` option, it'll temporarily ignore all additional filters added by options or `.with` calls. --- lib/tapping_device.rb | 10 +++++++--- spec/shared_examples/optionable_examples.rb | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/tapping_device.rb b/lib/tapping_device.rb index b32a7e9..b9b2afc 100644 --- a/lib/tapping_device.rb +++ b/lib/tapping_device.rb @@ -96,13 +96,15 @@ def track(object) def build_minimum_trace_point(event_type:) TracePoint.new(*event_type) do |tp| next unless filter_condition_satisfied?(tp) - next if is_tapping_device_call?(tp) filepath, line_number = get_call_location(tp) payload = build_payload(tp: tp, filepath: filepath, line_number: line_number) - next if should_be_skipped_by_paths?(filepath) - next unless with_condition_satisfied?(payload) + unless @options[:force_recording] + next if is_tapping_device_call?(tp) + next if should_be_skipped_by_paths?(filepath) + next unless with_condition_satisfied?(payload) + end yield(payload) end @@ -204,6 +206,8 @@ def process_options(options) options[:event_type] ||= config[:event_type] options[:hijack_attr_methods] ||= config[:hijack_attr_methods] options[:track_as_records] ||= config[:track_as_records] + # for debugging the gem more easily + options[:force_recording] ||= false options[:descendants] ||= [] options[:root_device] ||= self diff --git a/spec/shared_examples/optionable_examples.rb b/spec/shared_examples/optionable_examples.rb index ab0b35c..7db7f9b 100644 --- a/spec/shared_examples/optionable_examples.rb +++ b/spec/shared_examples/optionable_examples.rb @@ -32,4 +32,13 @@ expect(count).to eq(1) end end + context "with options - force_recording: true" do + it "skips all other filtering options" do + device = send(subject, target, filter_by_paths: [/lib/], force_recording: true) + + trigger_action.call(target) + + expect(device.calls.count).to be >= 1 + end + end end