Sha256: 90e141fa5e3b491f8875e454ef4757939178920d74b0e1a48aa6c44fc9f375da

Contents?: true

Size: 1.75 KB

Versions: 12

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

class Inspector < Sample::Model
  identity :id
  attribute :name
end

class Anon < Sample::Model
  attribute :chan
end

class Inspectors < Sample::Collection
  model Inspector

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

describe Cistern::Formatter::Default do
  before { Cistern.formatter = described_class }

  it 'formats a model' do
    expect(
      Inspector.new(id: 1, name: 'name').inspect
    ).to match(
      /<Inspector:0x[a-z0-9]+> {:id=>1, :name=>\"name\"}/
    )

    Anon.inspect
  end

  it 'formats a collection' do
    expect(
      Inspectors.new.all.inspect
    ).to match(
      /<Inspectors:0x[a-z0-9]+> {} records/
    )
  end
end

describe Cistern::Formatter::AwesomePrint do
  before { Cistern.formatter = described_class }

  it 'formats a model' do
    expect(
      Inspector.new(id: 1, name: 'name').inspect
    ).to 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 'formats a collection' do
    expect(Inspectors.new.all.inspect).to match(/Inspectors\s+{.*}$/m) # close enough
  end
end

describe Cistern::Formatter::Formatador do
  before { Cistern.formatter = described_class }

  it 'formats a model' do
    Cistern.formatter = Cistern::Formatter::Formatador

    expect(Inspector.new(id: 1, name: 'name').inspect).to eq('  <Inspector
    id=1,
    name="name"
  >')
  end

  it 'formats a collection' do
    expect(Inspectors.new.all.inspect).to eq('  <Inspectors
    [
      <Inspector
        id=1,
        name="2"
      >,
      <Inspector
        id=3,
        name="4"
      >
    ]
  >')
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cistern-2.7.2 spec/formatter_spec.rb
cistern-2.7.1 spec/formatter_spec.rb
cistern-2.7.0 spec/formatter_spec.rb
cistern-2.6.0 spec/formatter_spec.rb
cistern-2.5.0 spec/formatter_spec.rb
cistern-2.4.1 spec/formatter_spec.rb
cistern-2.4.0 spec/formatter_spec.rb
cistern-2.3.0 spec/formatter_spec.rb
cistern-2.2.7 spec/formatter_spec.rb
cistern-2.2.6 spec/formatter_spec.rb
cistern-2.2.5 spec/formatter_spec.rb
cistern-2.2.4 spec/formatter_spec.rb