Sha256: 9e87b9bc1987fcaa6b25b8a55361d9523d0a4ef533971d5dcfed0b2ad8b9df3a

Contents?: true

Size: 1.61 KB

Versions: 6

Compression:

Stored size: 1.61 KB

Contents

# (c) 2017 Ribose Inc.
#

# No point in using ApplicationRecord here.

require "spec_helper"

RSpec.describe AttrMasker::Maskers::Replacing do
  subject { described_class.new **options }

  let(:address) { "1 Pedder Street, Hong Kong" }

  shared_examples "AttrMasker::Maskers::Replacing examples" do
    example { expect(subject.(value: address)).to eq(expected_masked_address) }
    example { expect(subject.(value: Math::PI)).to eq(Math::PI) }
    example { expect(subject.(value: nil)).to eq(nil) }
  end

  context "with default options" do
    let(:options) { {} }
    let(:expected_masked_address) { "**************************" }
    include_examples "AttrMasker::Maskers::Replacing examples"
  end

  context "with alphanum_only option set to true" do
    let(:options) { { alphanum_only: true } }
    let(:expected_masked_address) { "* ****** ******, **** ****" }
    include_examples "AttrMasker::Maskers::Replacing examples"
  end

  context "with a custom replacement string" do
    let(:options) { { replacement: "X" } }
    let(:expected_masked_address) { "XXXXXXXXXXXXXXXXXXXXXXXXXX" }
    include_examples "AttrMasker::Maskers::Replacing examples"
  end

  context "with an empty replacement string" do
    let(:options) { { replacement: "" } }
    let(:expected_masked_address) { "" }
    include_examples "AttrMasker::Maskers::Replacing examples"
  end

  context "with alphanum_only and replacement options combined" do
    let(:options) { { alphanum_only: true, replacement: "X" } }
    let(:expected_masked_address) { "X XXXXXX XXXXXX, XXXX XXXX" }
    include_examples "AttrMasker::Maskers::Replacing examples"
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
attr_masker-0.3.1 spec/unit/maskers/replacing_spec.rb
attr_masker-0.3.0 spec/unit/maskers/replacing_spec.rb
attr_masker-0.2.1 spec/unit/maskers/replacing_spec.rb
attr_masker-0.2.0 spec/unit/maskers/replacing_spec.rb
attr_masker-0.1.1 spec/unit/maskers/replacing_spec.rb
attr_masker-0.1.0 spec/maskers/replacing_spec.rb