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.1.7 spec/timber/contexts_spec.rb
timber-2.1.6 spec/timber/contexts_spec.rb
timber-2.1.5 spec/timber/contexts_spec.rb
timber-2.1.4 spec/timber/contexts_spec.rb
timber-2.1.3 spec/timber/contexts_spec.rb
timber-2.1.2 spec/timber/contexts_spec.rb
timber-2.1.1 spec/timber/contexts_spec.rb
timber-2.1.0 spec/timber/contexts_spec.rb
timber-2.1.0.rc6 spec/timber/contexts_spec.rb
timber-2.1.0.rc5 spec/timber/contexts_spec.rb
timber-2.1.0.rc4 spec/timber/contexts_spec.rb
timber-2.1.0.rc3 spec/timber/contexts_spec.rb
timber-2.1.0.rc2 spec/timber/contexts_spec.rb
timber-2.1.0.rc1 spec/timber/contexts_spec.rb
timber-2.0.24 spec/timber/contexts_spec.rb
timber-2.0.23 spec/timber/contexts_spec.rb
timber-2.0.22 spec/timber/contexts_spec.rb
timber-2.0.21 spec/timber/contexts_spec.rb
timber-2.0.20 spec/timber/contexts_spec.rb
timber-2.0.19 spec/timber/contexts_spec.rb