Sha256: 21f6ff0a44542efc9f993deb0f06fa4072ce99de3c3aca60bdda8d2758c53aba

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe Parsable do

  let(:context) { Parsable::Context.new }

  before :each do
    context.system_store 'location', 'name', 'Here'
  end

  describe '.crunch' do
    it "outputs string with crunched values" do

      output = Parsable.crunch(\
        :string => %(my+{{location.name}}@email.com),
        :context => context
      )

      expect(output).to eql(%(my+Here@email.com))
    end

    context "nil string" do
      it "does nothing" do

        output = Parsable.crunch(\
          :string => nil,
          :context => context
        )

        expect(output).to eql("")
      end
    end

    context "no replacements" do
      it "returns the original" do
        string = %(my@email.com)
        output = Parsable.crunch(\
          :string => string,
          :context => context
        )

        expect(output).to eql(string)
      end
    end

    context "same replacement" do
      it "replaces both strings" do
        string = %(my{{location.name}}@email.com{{location.name}})
        output = Parsable.crunch(\
          :string => string,
          :context => context
        )

        expect(output).to eql(%(myHere@email.comHere))
      end
    end

    context "method not defined" do
      it "replaces with empty" do

        output = Parsable.crunch(\
          :string => %(my+{{location.not_name}}@email.com),
          :context => context
        )

        expect(output).to eql(%(my+@email.com))
      end
    end

    context "no context key" do
      it "replaces with empty" do

        output = Parsable.crunch(\
          :string => %(my+{{wrong_key.name}}@email.com),
          :context => context
        )

        expect(output).to eql(%(my+@email.com))
      end
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
parsable-0.2.5 spec/parsable_spec.rb
parsable-0.2.4 spec/parsable_spec.rb
parsable-0.2.3 spec/parsable_spec.rb
parsable-0.2.2 spec/parsable_spec.rb
parsable-0.2.1 spec/parsable_spec.rb
parsable-0.2.0 spec/parsable_spec.rb