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.0.17 spec/timber/contexts_spec.rb
timber-2.0.16 spec/timber/contexts_spec.rb
timber-2.0.15 spec/timber/contexts_spec.rb
timber-2.0.14 spec/timber/contexts_spec.rb
timber-2.0.12 spec/timber/contexts_spec.rb
timber-2.0.11 spec/timber/contexts_spec.rb
timber-2.0.10 spec/timber/contexts_spec.rb
timber-2.0.9 spec/timber/contexts_spec.rb
timber-2.0.8 spec/timber/contexts_spec.rb
timber-2.0.7 spec/timber/contexts_spec.rb
timber-2.0.6 spec/timber/contexts_spec.rb
timber-2.0.5 spec/timber/contexts_spec.rb
timber-2.0.4 spec/timber/contexts_spec.rb
timber-2.0.3 spec/timber/contexts_spec.rb
timber-2.0.2 spec/timber/contexts_spec.rb
timber-2.0.1 spec/timber/contexts_spec.rb
timber-2.0.0 spec/timber/contexts_spec.rb
timber-1.1.14 spec/timber/contexts_spec.rb
timber-1.1.13 spec/timber/contexts_spec.rb
timber-1.1.12 spec/timber/contexts_spec.rb