Sha256: 96bb90b49d643bc9d2002c29a8f2fef8f4f10b76c3d93b23cf55bd5b51fe2a3c

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

describe Celsius::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 "#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

4 entries across 4 versions & 1 rubygems

Version Path
celsius-0.4.3 spec/celsius/transformation_spec.rb
celsius-0.4.2 spec/celsius/transformation_spec.rb
celsius-0.4.1 spec/celsius/transformation_spec.rb
celsius-0.4.0 spec/celsius/transformation_spec.rb