spec/formatter_spec.rb in cistern-0.12.3 vs spec/formatter_spec.rb in cistern-1.0.0.pre

- old
+ new

@@ -1,77 +1,43 @@ require 'spec_helper' -class Inspector < Cistern::Model - identity :id - attribute :name -end - -class Anon < Cistern::Model - attribute :chan -end - -class Inspectors < Cistern::Collection - model Inspector - - def all(options={}) - merge_attributes(options) - self.load([{id: 1, name: "2"},{id: 3, name: "4"}]) +describe "#inspect" do + class Inspector < Sample::Model + identity :id + attribute :name end -end -describe Cistern::Formatter::Default do - before { Cistern.formatter = described_class } + class Inspectors < Sample::Collection + model Inspector - 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 + def all(options={}) + merge_attributes(options) + self.load([{id: 1, name: "2"},{id: 3, name: "4"}]) + end end - it "formats a collection" do - expect( - Inspectors.new.all.inspect - ).to match( - /<Inspectors:0x[a-z0-9]+> {} records/ - ) - end -end + describe "Cistern::Model" do + it "should use awesome_print" do + Cistern.formatter = Cistern::Formatter::AwesomePrint -describe Cistern::Formatter::AwesomePrint do - before { Cistern.formatter = described_class } + 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 "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 "should use formatador" do + Cistern.formatter = Cistern::Formatter::Formatador - 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(%q{ <Inspector + expect(Inspector.new(id: 1, name: "name").inspect).to eq(%q{ <Inspector id=1, name="name" >}) + end end - it "formats a collection" do - expect(Inspectors.new.all.inspect).to eq(%q{ <Inspectors + 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" >, @@ -79,7 +45,13 @@ 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