Skip to content

Commit

Permalink
Update to newest minitest version
Browse files Browse the repository at this point in the history
There were some changes to kwargs handling for mock objects, so those
tests were adjusted.
  • Loading branch information
gettalong committed Aug 1, 2022
1 parent 4f64c8e commit 893f0b5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions hexapdf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Gem::Specification.new do |s|
s.add_dependency('cmdparse', '~> 3.0', '>= 3.0.3')
s.add_dependency('geom2d', '~> 0.3')
s.add_development_dependency('kramdown', '~> 2.3')
s.add_development_dependency('minitest', '~> 5.16')
s.add_development_dependency('reline', '~> 0.1')
s.add_development_dependency('rubocop', '~> 1.0')
s.required_ruby_version = '>= 2.5'
Expand Down
2 changes: 1 addition & 1 deletion lib/hexapdf/type/trailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Trailer < Dictionary

# Returns the document's Catalog (see Type::Catalog), creating it if needed.
def catalog
self[:Root] ||= document.add({Type: :Catalog})
self[:Root] ||= document.add({Type: :Catalog}, type: :Catalog)
end

# Returns the document's information dictionary (see Type::Info), creating it if needed.
Expand Down
18 changes: 9 additions & 9 deletions test/hexapdf/test_dictionary_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
describe "convert" do
it "returns the converted object, using the first usable converter" do
doc = Minitest::Mock.new
doc.expect(:wrap, :data, [Hash, Hash])
doc.expect(:wrap, :data, [Hash], type: Integer)
@field.convert({}, doc)
doc.verify

Expand Down Expand Up @@ -67,20 +67,20 @@
end

it "allows conversion from a hash" do
@doc.expect(:wrap, :data, [Hash, Hash])
@doc.expect(:wrap, :data, [Hash], type: Class)
@field.convert({Test: :value}, @doc)
@doc.verify
end

it "allows conversion from a Dictionary" do
@doc.expect(:wrap, :data, [HexaPDF::Dictionary, Hash])
@doc.expect(:wrap, :data, [HexaPDF::Dictionary], type: Class)
@field.convert(HexaPDF::Dictionary.new({Test: :value}), @doc)
@doc.verify
end

it "allows conversion from an HexaPDF::Dictionary to a Stream if stream data is set" do
@field = self.class::Field.new(HexaPDF::Stream)
@doc.expect(:wrap, :data, [HexaPDF::Dictionary, Hash])
@doc.expect(:wrap, :data, [HexaPDF::Dictionary], type: Class)
data = HexaPDF::PDFData.new({}, 0, 0, "")
@field.convert(HexaPDF::Dictionary.new(data), @doc)
@doc.verify
Expand Down Expand Up @@ -108,7 +108,7 @@
end

it "allows conversion from an array" do
@doc.expect(:wrap, :data, [[1, 2], {type: HexaPDF::PDFArray}])
@doc.expect(:wrap, :data, [[1, 2]], type: HexaPDF::PDFArray)
@field.convert([1, 2], @doc)
@doc.verify
end
Expand Down Expand Up @@ -208,14 +208,14 @@ def config

it "allows conversion from a string" do
@doc = Minitest::Mock.new
@doc.expect(:wrap, :data, [{F: 'test'}, {type: HexaPDF::Type::FileSpecification}])
@doc.expect(:wrap, :data, [{F: 'test'}], type: HexaPDF::Type::FileSpecification)
@field.convert('test', @doc)
@doc.verify
end

it "allows conversion from a hash/dictionary" do
@doc = Minitest::Mock.new
@doc.expect(:wrap, :data, [{F: 'test'}, {type: HexaPDF::Type::FileSpecification}])
@doc.expect(:wrap, :data, [{F: 'test'}], type: HexaPDF::Type::FileSpecification)
@field.convert({F: 'test'}, @doc)
@doc.verify
end
Expand All @@ -232,15 +232,15 @@ def config

it "allows conversion to a Rectangle from an Array" do
doc = Minitest::Mock.new
doc.expect(:wrap, :data, [[0, 1, 2, 3], {type: HexaPDF::Rectangle}])
doc.expect(:wrap, :data, [[0, 1, 2, 3]], type: HexaPDF::Rectangle)
@field.convert([0, 1, 2, 3], doc)
doc.verify
end

it "allows conversion to a Rectangle from a HexaPDF::PDFArray" do
data = HexaPDF::PDFArray.new([0, 1, 2, 3])
doc = Minitest::Mock.new
doc.expect(:wrap, :data, [data, {type: HexaPDF::Rectangle}])
doc.expect(:wrap, :data, [data], type: HexaPDF::Rectangle)
@field.convert(data, doc)
doc.verify
end
Expand Down
6 changes: 3 additions & 3 deletions test/hexapdf/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@

it "defers to @revisions for iterating over all objects" do
revs = Minitest::Mock.new
revs.expect(:each_object, :retval, [{only_current: true, only_loaded: true}])
revs.expect(:each_object, :retval, only_current: true, only_loaded: true)
doc = HexaPDF::Document.new
doc.instance_variable_set(:@revisions, revs)
doc.each(only_current: true, only_loaded: true)
Expand Down Expand Up @@ -510,8 +510,8 @@

it "allows to conveniently sign a document" do
mock = Minitest::Mock.new
mock.expect(:handler, :handler, [{name: :handler, opt: :key}])
mock.expect(:add, :added, [:io, :handler, {signature: :sig, write_options: :write_options}])
mock.expect(:handler, :handler, name: :handler, opt: :key)
mock.expect(:add, :added, [:io, :handler], signature: :sig, write_options: :write_options)
@doc.instance_variable_set(:@signatures, mock)
result = @doc.sign(:io, handler: :handler, write_options: :write_options, signature: :sig, opt: :key)
assert_equal(:added, result)
Expand Down
6 changes: 3 additions & 3 deletions test/hexapdf/type/test_trailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def (@doc).wrap(obj, *)

it "returns the catalog object, creating it if needed" do
doc = Minitest::Mock.new
doc.expect(:add, :val, [{Type: :Catalog}])
doc.expect(:add, :val, [{Type: :Catalog}], type: :Catalog)
trailer = HexaPDF::Type::Trailer.new({}, document: doc)
assert_equal(:val, trailer.catalog)
doc.verify
Expand All @@ -34,7 +34,7 @@ def (@doc).wrap(obj, *)

it "returns the info object, creating it if needed" do
doc = Minitest::Mock.new
doc.expect(:add, :val, [{}, type: :XXInfo])
doc.expect(:add, :val, [{}], type: :XXInfo)
trailer = HexaPDF::Type::Trailer.new({}, document: doc)
assert_equal(:val, trailer.info)
doc.verify
Expand Down Expand Up @@ -89,7 +89,7 @@ def obj.encryption_key_valid?; true; end
it "corrects a missing Catalog entry" do
@obj.delete(:Root)
@obj.set_random_id
def (@doc).add(val) HexaPDF::Object.new(val, oid: 3) end
def (@doc).add(val, type:); type.to_s; HexaPDF::Object.new(val, oid: 3) end

message = ''
refute(@obj.validate(auto_correct: false) {|m, _| message = m })
Expand Down

0 comments on commit 893f0b5

Please sign in to comment.