Class: RSpecRcv::Handler
- Inherits:
-
Object
- Object
- RSpecRcv::Handler
- Defined in:
- lib/rspec-rcv/handler.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(file_path, data, metadata: {}) ⇒ Handler
constructor
A new instance of Handler.
Constructor Details
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rspec-rcv/handler.rb', line 12 def call return :no_change if existing_data && existing_data["file"] == file_path && existing_data["data"] == data output = { recorded_at: Time.now, file: file_path, data: data } output = opts[:codec].export_with(output) + "\n" if existing_data existing_data_comparison = opts.fetch(:parse_existing).call(existing_data) eq = opts[:compare_with].call(existing_data_comparison, data, opts) if !eq && opts[:fail_on_changed_output] raise_error!(output, JsonCompare.get_diff(existing_data_comparison, data, opts.fetch(:ignore_keys, []))) end return :same if eq end FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w') do |file| file.write(output) end return :to_disk end |