Sha256: ab7ee74693e7c3de9f5c8a4cc73baa8c4435cb22511ddcf0486e8f4ef451c869

Contents?: true

Size: 1.4 KB

Versions: 11

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'

describe "#inspect" do
  class Inspector < Cistern::Model
    identity :id
    attribute :name
  end

  class Inspectors < Cistern::Collection

    model Inspector

    def all(options={})
      merge_attributes(options)
      self.load([{id: 1, name: "2"},{id: 3, name: "4"}])
    end
  end

  describe "Cistern::Model" do
    it "should use awesome_print" do
      Cistern.formatter = Cistern::Formatter::AwesomePrint

      Inspector.new(id: 1, name: "name").inspect.match /(?x-mi:\#<Inspector:0x[0-9a-f]+>\ {\n\ \ \ \ \ \ :id\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[1;34m1\x1B\[0m,\n\ \ \ \ :name\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[0;33m"name"\x1B\[0m\n})/
    end

    it "should use formatador" do
      Cistern.formatter = Cistern::Formatter::Formatador

      expect(Inspector.new(id: 1, name: "name").inspect).to eq(%q{  <Inspector
    id=1,
    name="name"
  >})
    end
  end

  describe "Cistern::Collection" do
    it "should use formatador" do
      Cistern.formatter = Cistern::Formatter::Formatador
      expect(Inspectors.new.all.inspect).to eq(%q{  <Inspectors
    [
      <Inspector
        id=1,
        name="2"
      >,
      <Inspector
        id=3,
        name="4"
      >
    ]
  >})
    end

    it "should use awesome_print" do
      Cistern.formatter = Cistern::Formatter::AwesomePrint
      expect(Inspectors.new.all.inspect).to match(/Inspectors\s+{.*}$/m) # close enough
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cistern-0.11.3 spec/formatter_spec.rb
cistern-0.11.2 spec/formatter_spec.rb
cistern-0.11.1 spec/formatter_spec.rb
cistern-0.11.0 spec/formatter_spec.rb
cistern-0.10.2 spec/formatter_spec.rb
cistern-0.9.2 spec/formatter_spec.rb
cistern-0.9.1 spec/formatter_spec.rb
cistern-0.9.0 spec/cistern_spec.rb
cistern-0.8.0 spec/cistern_spec.rb
cistern-0.7.1 spec/cistern_spec.rb
cistern-0.7.0 spec/cistern_spec.rb