Sha256: f4e7d66d419c2a697e8f1407c66c02fe7b1e7d3b7d1c8fecb99d938ada1d42b9

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require "spec_helper"

describe XRayMachine::Config do

  before { XRayMachine.instance_eval{ @options = nil } }

  describe ".config" do

    it "allows to config things" do
      XRayMachine.config do |config|
        config.thing = {title: "Thingy"}
      end

      expect(XRayMachine.options.instance_variable_get("@streams")).to eq({
        thing: {title: "Thingy", color: :red, show_in_summary: true}
      })
    end

    it "allows to override colors and the summary settings" do
      XRayMachine.config do |config|
        config.thing = {title: "Thingy", color: :yellow, show_in_summary: false}
      end

      expect(XRayMachine.options.instance_variable_get("@streams")).to eq({
        thing: {title: "Thingy", color: :yellow, show_in_summary: false}
      })
    end

  end

  describe ".for" do
    subject { XRayMachine::Config.for("some_thing").to_h }

    it "generates a new config if the settings are missing" do
      is_expected.to eq({title: "SomeThing", color: "\e[31m", show_in_summary: true})
    end

    it "uses the user settings when it configured" do
      XRayMachine.config { |c| c.some_thing = {title: "ST", color: :yellow} }

      is_expected.to eq({title: "ST", color: "\e[33m", show_in_summary: true})
    end

    it "returns the same object every time" do
      is_expected.to eq(XRayMachine::Config.for("some_thing").to_h)
    end

    it "picks different colors for different things" do
      colors = (1..3).to_a.map{|i| XRayMachine::Config.for("thing_#{i}").color }
      expect(colors).to eq ["\e[31m", "\e[32m", "\e[33m"]
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
x-ray-machine-1.0.0 spec/lib/x_ray_machine/config_spec.rb