Sha256: dda3a683f2f902cf1f88d8ae9c9d744303db3d2ce97d5e8c28351e3803f2c044

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

describe Skala::Transformation do
  describe ".require_directory" do
    it "requires all *.rb files in the given directory" do
      described_class.require_directory "#{File.dirname(__FILE__)}/../assets/transformation"
      expect(defined?(SomeClass)).to eq("constant")
    end
  end

  describe "#sequence" do
    let(:steps_array) do
      [ -> { } ]
    end

    let(:transformation) do
      steps = steps_array

      Class.new(described_class) do
        sequence steps
      end
    end

    it "is a wrapper for the steps setter" do
      expect(transformation.steps).to be(steps_array)
    end
  end

  describe "#abort!" do
    let(:transformation) do
      Class.new(described_class) do
        sequence [
          -> (transformation) do
            transformation.target = "first_steps_output"
            transformation.abort!
          end,
          -> (transformation) do
            transformation.target = "second_steps_output"
          end
        ]
      end.new
    end

    it "aborts the execution of the steps sequence" do
      expect(transformation.apply to: {}).to eq("first_steps_output") 
    end
  end

  describe "#apply" do
    let(:transformation) do
      step_class = Class.new(described_class::Step) do
        def call
          transformation.target = source.dup
        end
      end

      step_lambda = -> (transformation) do
        transformation.target.upcase!
      end

      Class.new(described_class) do
        sequence [
          step_class,
          step_lambda
        ]
      end.new
    end

    context "if no :source or :to option is given" do
      it "raises an error" do
        expect { transformation.apply }.to raise_error(ArgumentError)
      end
    end

    it "applies the transformation" do
      some_string = "foo"

      expect(transformation.apply(to: some_string)).to eq(some_string.upcase)
      expect(some_string).to eq("foo")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skala-0.2.0 spec/skala/transformation_spec.rb