From 89ba413a11eea251b263887a261efeec14226846 Mon Sep 17 00:00:00 2001 From: Kristina Spurgin Date: Mon, 12 Aug 2024 16:14:09 -0400 Subject: [PATCH] Switch to yardspec tests --- .../extend/transforms/append/nil_fields.rb | 30 +++------- .../transforms/append/to_field_value.rb | 45 +++++++------- spec/kiba/extend/transforms/append_spec.rb | 58 ------------------- 3 files changed, 28 insertions(+), 105 deletions(-) delete mode 100644 spec/kiba/extend/transforms/append_spec.rb diff --git a/lib/kiba/extend/transforms/append/nil_fields.rb b/lib/kiba/extend/transforms/append/nil_fields.rb index f246d7af6..0ed3dc04a 100644 --- a/lib/kiba/extend/transforms/append/nil_fields.rb +++ b/lib/kiba/extend/transforms/append/nil_fields.rb @@ -7,29 +7,15 @@ module Append # Adds the given field(s) to the row with nil value if they do not # already exist in row # - # # Examples + # @example + # # Used in pipeline as: + # # transform Append::NilFields, fields: %i[a b z] # - # Input table: - # - # ~~~ - # | z | - # |----| - # | zz | - # ~~~ - # - # Used in pipeline as: - # - # ~~~ - # transform Append::NilFields, fields: %i[a b c z] - # ~~~ - # - # Results in: - # - # ~~~ - # | z | a | b | c | - # |----+-----+-----+-----| - # | zz | nil | nil | nil | - # ~~~ + # xform = Append::NilFields.new(fields: %i[a b z]) + # input = [{z: "zz"}] + # result = input.map{ |row| xform.process(row) } + # expected = [{z: "zz", a: nil, b: nil}] + # expect(result).to eq(expected) class NilFields # @param fields [Array, Symbol] field name or list of field # names to add diff --git a/lib/kiba/extend/transforms/append/to_field_value.rb b/lib/kiba/extend/transforms/append/to_field_value.rb index 502bbbec7..2ede43cf5 100644 --- a/lib/kiba/extend/transforms/append/to_field_value.rb +++ b/lib/kiba/extend/transforms/append/to_field_value.rb @@ -4,33 +4,28 @@ module Kiba module Extend module Transforms module Append - # # Examples + # Adds the given value to the end of value of the given field. Does not + # affect nil/empty field values # - # Input table: + # @example Treated as single value (default) + # # Used in pipeline as: + # # transform Append::ToFieldValue, field: :name, value: " (name)" # - # ~~~ - # | name | - # |-------| - # | Weddy | - # | nil | - # | | - # ~~~ - # - # Used in pipeline as: - # - # ~~~ - # transform Append::ToFieldValue, field: :name, value: ' (name)' - # ~~~ - # - # Results in: - # - # ~~~ - # | name | - # |--------------| - # | Weddy (name) | - # | nil | - # | | - # ~~~ + # xform = Append::ToFieldValue.new(field: :name, value: " (name)") + # input = [ + # {name: "Weddy"}, + # {name: "Kernel|Zipper"}, + # {name: nil}, + # {name: ""} + # ] + # result = input.map{ |row| xform.process(row) } + # expected = [ + # {name: "Weddy (name)"}, + # {name: "Kernel|Zipper (name)"}, + # {name: nil}, + # {name: ""} + # ] + # expect(result).to eq(expected) class ToFieldValue # @param field [Symbol] name of field to append to # @param value [String] value to append to existing field values diff --git a/spec/kiba/extend/transforms/append_spec.rb b/spec/kiba/extend/transforms/append_spec.rb deleted file mode 100644 index ecbd5375d..000000000 --- a/spec/kiba/extend/transforms/append_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe Kiba::Extend::Transforms::Append do - let(:accumulator) { [] } - let(:test_job) do - Helpers::TestJob.new(input: input, accumulator: accumulator, - transforms: transforms) - end - let(:result) { test_job.accumulator } - - describe "NilFields" do - let(:input) { [{z: "zz"}] } - - let(:transforms) do - Kiba.job_segment do - transform Append::NilFields, fields: %i[a b c z] - end - end - - let(:expected) { [{z: "zz", a: nil, b: nil, c: nil}] } - - it "adds non-existing fields, populating with nil, "\ - "while leaving existing fields alone" do - expect(result).to eq(expected) - end - end - - describe "ToFieldValue" do - let(:input) do - [ - {name: "Weddy"}, - {name: nil}, - {name: ""} - ] - end - - let(:transforms) do - Kiba.job_segment do - transform Append::ToFieldValue, field: :name, value: " (name)" - end - end - - let(:expected) do - [ - {name: "Weddy (name)"}, - {name: nil}, - {name: ""} - ] - end - - it "prepends given value to existing field values, "\ - "leaving blank values alone" do - expect(result).to eq(expected) - end - end -end