Skip to content

Commit

Permalink
move back to share_example usign describe block too
Browse files Browse the repository at this point in the history
require fixed_values for all specs with as_json example
  • Loading branch information
ConorSheehan1 committed Oct 4, 2018
1 parent 7624a04 commit e13d7a4
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 38 deletions.
7 changes: 5 additions & 2 deletions spec/support/shared_examples/json_format.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
shared_examples 'it has symmetric as_json and to_json methods' do
it 'should return a json representation of the object as a ruby hash' do
expect(subject.as_json).to eq JSON.parse(subject.to_json)
describe "#{described_class}.as_json" do
it 'should return a json representation of the object as a ruby hash' do
obj = described_class.new(fixed_values)
expect(obj.as_json).to eq JSON.parse(obj.to_json)
end
end
end
6 changes: 3 additions & 3 deletions spec/unit/iiif/presentation/annotation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
describe IIIF::Presentation::Annotation do

let(:fixed_values) { {} }

describe "#{described_class}.define_methods_for_abstract_resource_only_keys" do
it_behaves_like 'it has the appropriate methods for abstract_resource_only_keys'
end

describe "#{described_class}.as_json" do
it_behaves_like 'it has symmetric as_json and to_json methods'
end
it_behaves_like 'it has symmetric as_json and to_json methods'
end
9 changes: 1 addition & 8 deletions spec/unit/iiif/presentation/canvas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@
end
end

describe '#as_json' do
# must have @id, width, height etc to pass validation in to_ordered_hash
# could also use to_oredered_hash(force: true) to skip validation
subject do
IIIF::Presentation::Canvas.new(fixed_values)
end
it_behaves_like 'it has symmetric as_json and to_json methods'
end
it_behaves_like 'it has symmetric as_json and to_json methods'
end

4 changes: 1 addition & 3 deletions spec/unit/iiif/presentation/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
describe '#validate' do
end

describe '#as_json' do
it_behaves_like 'it has symmetric as_json and to_json methods'
end
it_behaves_like 'it has symmetric as_json and to_json methods'
end


10 changes: 1 addition & 9 deletions spec/unit/iiif/presentation/image_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@
"width" => 750,
}
end

# describe '#as_json' do
# # must have @id, width, height etc to pass validation in to_ordered_hash
# # could also use to_oredered_hash(force: true) to skip validation
# subject do
# IIIF::Presentation::Canvas.new(fixed_values)
# end
# it_behaves_like 'it has symmetric as_json and to_json methods'
# end

it_behaves_like 'it has symmetric as_json and to_json methods'
end
7 changes: 1 addition & 6 deletions spec/unit/iiif/presentation/layer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@
it_behaves_like 'it has the appropriate methods for any-type keys'
end

describe "#{described_class}.as_json" do
subject do
IIIF::Presentation::Layer.new(fixed_values)
end
it_behaves_like 'it has symmetric as_json and to_json methods'
end
it_behaves_like 'it has symmetric as_json and to_json methods'

end

7 changes: 4 additions & 3 deletions spec/unit/iiif/presentation/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def initialize(hsh={})

let(:fixed_values) do
{
'type' => 'a:SubClass',
'id' => 'http://example.com/prefix/manifest/123',
'context' => IIIF::Presentation::CONTEXT,
'@type' => 'a:SubClass',
'@id' => 'http://example.com/prefix/manifest/123',
'@context' => IIIF::Presentation::CONTEXT,
'label' => 'Book 1',
'description' => 'A longer description of this example book. It should give some real information.',
'thumbnail' => {
Expand Down Expand Up @@ -86,4 +86,5 @@ def initialize(hsh={})
it_behaves_like 'it has the appropriate methods for any-type keys'
end

it_behaves_like 'it has symmetric as_json and to_json methods'
end
1 change: 1 addition & 0 deletions spec/unit/iiif/presentation/range_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
describe '#validate' do
end

it_behaves_like 'it has symmetric as_json and to_json methods'
end


9 changes: 9 additions & 0 deletions spec/unit/iiif/presentation/resource_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
describe IIIF::Presentation::Resource do

let(:fixed_values) do
{
'@id' => 'http://www.example.org/iiif/book1/resource',
# '@type' => 'sc:Range',
'label' => 'Introduction'
}
end

describe "#{described_class}.define_methods_for_abstract_resource_only_keys" do
it_behaves_like 'it has the appropriate methods for abstract_resource_only_keys'
end
Expand All @@ -12,5 +20,6 @@
it_behaves_like 'it has the appropriate methods for string-only keys'
end

it_behaves_like 'it has symmetric as_json and to_json methods'
end

3 changes: 2 additions & 1 deletion spec/unit/iiif/presentation/sequence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def initialize(hsh={})
end
end


it_behaves_like 'it has symmetric as_json and to_json methods'

end

6 changes: 3 additions & 3 deletions spec/unit/iiif/service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe IIIF::Service do

let(:fixed_values) { {} }

describe 'self#get_descendant_class_by_jld_type' do
before do
Expand All @@ -25,8 +27,6 @@ def self.singleton_class?
end
end

describe '#as_json' do
it_behaves_like 'it has symmetric as_json and to_json methods'
end
it_behaves_like 'it has symmetric as_json and to_json methods'

end

0 comments on commit e13d7a4

Please sign in to comment.