Sha256: ecbb7297eed06465a4d1f3d0ee75b44cbce3369e0d6180fe01ab7c4b28cd6b55

Contents?: true

Size: 1.58 KB

Versions: 72

Compression:

Stored size: 1.58 KB

Contents

require "spec_helper"

describe Timber::Contexts, :rails_23 => true do
  describe ".build" do
    it "should build a Timber::Context" do
      context = Timber::Contexts::Custom.new(
        type: :build,
        data: {version: "1.0.0"}
      )
      built_context = Timber::Contexts.build(context)
      expect(built_context).to eq(context)
    end

    it "should use #to_timber_context" do
      BuildContext = Struct.new(:version) do
        def to_timber_context
          Timber::Contexts::Custom.new(
            type: :build,
            data: respond_to?(:to_h) ? to_h : Timber::Util::Struct.to_hash(self)
          )
        end
      end
      built_context = Timber::Contexts.build(BuildContext.new("1.0.0"))
      expect(built_context).to be_kind_of(Timber::Contexts::Custom)
      expect(built_context.type).to eq(:build)
      Object.send(:remove_const, :BuildContext)
    end

    it "should accept a properly structured hash" do
      built_context = Timber::Contexts.build(build: {version: "1.0.0"})
      expect(built_context).to be_kind_of(Timber::Contexts::Custom)
      expect(built_context.type).to eq(:build)
    end

    it "should accept a struct" do
      BuildContext = Struct.new(:version) do
        def type; :build; end
      end
      built_context = Timber::Contexts.build(BuildContext.new("1.0.0"))
      expect(built_context).to be_kind_of(Timber::Contexts::Custom)
      expect(built_context.type).to eq(:build)
      Object.send(:remove_const, :BuildContext)
    end

    it "should return nil for unsupported" do
      expect(Timber::Contexts.build(1)).to be_nil
    end
  end
end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
timber-2.6.2 spec/timber/contexts_spec.rb
timber-2.6.1 spec/timber/contexts_spec.rb
timber-2.6.0 spec/timber/contexts_spec.rb
timber-2.6.0.pre.beta2 spec/timber/contexts_spec.rb
timber-2.6.0.pre.beta1 spec/timber/contexts_spec.rb
timber-2.5.1 spec/timber/contexts_spec.rb
timber-2.5.0 spec/timber/contexts_spec.rb
timber-2.4.0 spec/timber/contexts_spec.rb
timber-2.3.4 spec/timber/contexts_spec.rb
timber-2.3.3 spec/timber/contexts_spec.rb
timber-2.3.2 spec/timber/contexts_spec.rb
timber-2.3.1 spec/timber/contexts_spec.rb
timber-2.3.0 spec/timber/contexts_spec.rb
timber-2.2.3 spec/timber/contexts_spec.rb
timber-2.2.2 spec/timber/contexts_spec.rb
timber-2.2.1 spec/timber/contexts_spec.rb
timber-2.2.0 spec/timber/contexts_spec.rb
timber-2.1.10 spec/timber/contexts_spec.rb
timber-2.1.9 spec/timber/contexts_spec.rb
timber-2.1.8 spec/timber/contexts_spec.rb