Skip to content

Commit

Permalink
Merge pull request #896 from nanoc/view-inspect-methods
Browse files Browse the repository at this point in the history
Add #inspect method to views
  • Loading branch information
denisdefreyne committed Jul 3, 2016
2 parents d07e34d + 8506fdf commit 2331305
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/nanoc/base/views/item_rep_view.rb
Expand Up @@ -77,5 +77,9 @@ def raw_path(snapshot: :last)
def binary?
@item_rep.binary?
end

def inspect
"<#{self.class} item.identifier=#{item.identifier} name=#{name}>"
end
end
end
4 changes: 4 additions & 0 deletions lib/nanoc/base/views/mixins/document_view_mixin.rb
Expand Up @@ -76,5 +76,9 @@ def reference
def raw_content
unwrap.content.string
end

def inspect
"<#{self.class} identifier=#{unwrap.identifier}>"
end
end
end
4 changes: 4 additions & 0 deletions lib/nanoc/base/views/view.rb
Expand Up @@ -23,5 +23,9 @@ def unwrap
def frozen?
unwrap.frozen?
end

def inspect
"<#{self.class}>"
end
end
end
5 changes: 5 additions & 0 deletions spec/nanoc/base/views/config_view_spec.rb
Expand Up @@ -88,4 +88,9 @@
expect(res).to eql([[:amount, 9000], [:animal, 'donkey']])
end
end

describe '#inspect' do
subject { view.inspect }
it { is_expected.to eql('<Nanoc::ConfigView>') }
end
end
15 changes: 15 additions & 0 deletions spec/nanoc/base/views/item_collection_view_spec.rb
@@ -1,4 +1,19 @@
# FIXME: fix name
describe Nanoc::ItemCollectionWithRepsView do
let(:view_class) { Nanoc::ItemWithRepsView }
it_behaves_like 'an identifiable collection'

describe '#inspect' do
let(:wrapped) do
Nanoc::Int::IdentifiableCollection.new(config)
end

let(:view) { described_class.new(wrapped, view_context) }
let(:view_context) { double(:view_context) }
let(:config) { { string_pattern_type: 'glob' } }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::ItemCollectionWithRepsView>') }
end
end
6 changes: 6 additions & 0 deletions spec/nanoc/base/views/item_rep_collection_view_spec.rb
Expand Up @@ -129,4 +129,10 @@
end
end
end

describe '#inspect' do
subject { view.inspect }

it { is_expected.to eql('<Nanoc::ItemRepCollectionView>') }
end
end
10 changes: 10 additions & 0 deletions spec/nanoc/base/views/item_rep_view_spec.rb
Expand Up @@ -212,4 +212,14 @@
expect(subject._context).to equal(view_context)
end
end

describe '#inspect' do
let(:item_rep) { Nanoc::Int::ItemRep.new(item, :jacques) }
let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo/') }
let(:view) { described_class.new(item_rep, view_context) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::ItemRepView item.identifier=/foo/ name=jacques>') }
end
end
9 changes: 9 additions & 0 deletions spec/nanoc/base/views/item_view_spec.rb
Expand Up @@ -331,4 +331,13 @@
describe '#raw_filename' do
# TODO: implement
end

describe '#inspect' do
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf/') }
let(:view) { described_class.new(item, nil) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::ItemWithRepsView identifier=/asdf/>') }
end
end
14 changes: 14 additions & 0 deletions spec/nanoc/base/views/layout_collection_view_spec.rb
@@ -1,4 +1,18 @@
describe Nanoc::LayoutCollectionView do
let(:view_class) { Nanoc::LayoutView }
it_behaves_like 'an identifiable collection'

describe '#inspect' do
let(:wrapped) do
Nanoc::Int::IdentifiableCollection.new(config)
end

let(:view) { described_class.new(wrapped, view_context) }
let(:view_context) { double(:view_context) }
let(:config) { { string_pattern_type: 'glob' } }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::LayoutCollectionView>') }
end
end
9 changes: 9 additions & 0 deletions spec/nanoc/base/views/layout_view_spec.rb
Expand Up @@ -2,4 +2,13 @@
let(:entity_class) { Nanoc::Int::Layout }
let(:other_view_class) { Nanoc::ItemWithRepsView }
it_behaves_like 'a document view'

describe '#inspect' do
let(:item) { Nanoc::Int::Layout.new('content', {}, '/asdf/') }
let(:view) { described_class.new(item, nil) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::LayoutView identifier=/asdf/>') }
end
end
11 changes: 8 additions & 3 deletions spec/nanoc/base/views/mutable_config_view_spec.rb
@@ -1,11 +1,16 @@
describe Nanoc::MutableConfigView do
describe '#[]=' do
let(:config) { {} }
let(:view) { described_class.new(config, nil) }
let(:config) { {} }
let(:view) { described_class.new(config, nil) }

describe '#[]=' do
it 'sets attributes' do
view[:awesomeness] = 'rather high'
expect(config[:awesomeness]).to eq('rather high')
end
end

describe '#inspect' do
subject { view.inspect }
it { is_expected.to eql('<Nanoc::MutableConfigView>') }
end
end
14 changes: 14 additions & 0 deletions spec/nanoc/base/views/mutable_item_collection_view_spec.rb
Expand Up @@ -32,4 +32,18 @@
expect(ret).to equal(view)
end
end

describe '#inspect' do
let(:wrapped) do
Nanoc::Int::IdentifiableCollection.new(config)
end

let(:view) { described_class.new(wrapped, view_context) }
let(:view_context) { double(:view_context) }
let(:config) { { string_pattern_type: 'glob' } }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::MutableItemCollectionView>') }
end
end
9 changes: 9 additions & 0 deletions spec/nanoc/base/views/mutable_item_view_spec.rb
Expand Up @@ -10,4 +10,13 @@
expect(view).not_to respond_to(:path)
expect(view).not_to respond_to(:reps)
end

describe '#inspect' do
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf/') }
let(:view) { described_class.new(item, nil) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::MutableItemView identifier=/asdf/>') }
end
end
14 changes: 14 additions & 0 deletions spec/nanoc/base/views/mutable_layout_collection_view_spec.rb
Expand Up @@ -32,4 +32,18 @@
expect(ret).to equal(view)
end
end

describe '#inspect' do
let(:wrapped) do
Nanoc::Int::IdentifiableCollection.new(config)
end

let(:view) { described_class.new(wrapped, view_context) }
let(:view_context) { double(:view_context) }
let(:config) { { string_pattern_type: 'glob' } }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::MutableLayoutCollectionView>') }
end
end
9 changes: 9 additions & 0 deletions spec/nanoc/base/views/mutable_layout_view_spec.rb
@@ -1,4 +1,13 @@
describe Nanoc::MutableLayoutView do
let(:entity_class) { Nanoc::Int::Layout }
it_behaves_like 'a mutable document view'

describe '#inspect' do
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf/') }
let(:view) { described_class.new(item, nil) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::MutableLayoutView identifier=/asdf/>') }
end
end

0 comments on commit 2331305

Please sign in to comment.