From e02b64856a8f28bf87e121e9b1b9ece094f827c4 Mon Sep 17 00:00:00 2001 From: Zsolt Kozaroczy Date: Fri, 19 Sep 2025 19:45:36 +0200 Subject: [PATCH] Fix deprecation warnings for Minitest 6 --- test/hash_test.rb | 12 ++--- test/json_test.rb | 6 ++- test/parser_test.rb | 4 +- test/string_test.rb | 16 +++---- test/xml_test.rb | 110 ++++++++++++++++++++++++-------------------- 5 files changed, 80 insertions(+), 68 deletions(-) diff --git a/test/hash_test.rb b/test/hash_test.rb index da38a31..4ef4836 100644 --- a/test/hash_test.rb +++ b/test/hash_test.rb @@ -7,9 +7,9 @@ it "turn the hash into xml attributes" do attrs = Crack::Util.to_xml_attributes(@hash) - attrs.must_match /one="ONE"/m - attrs.must_match /two="TWO"/m - attrs.must_match /three="it "should" work"/m + expect(attrs).must_match(/one="ONE"/m) + expect(attrs).must_match(/two="TWO"/m) + expect(attrs).must_match(/three="it "should" work"/m) end it "preserve _ in hash keys" do @@ -19,8 +19,8 @@ :merb => "uses extlib" }) - attrs.must_match /some_long_attribute="with short value"/ - attrs.must_match /merb="uses extlib"/ - attrs.must_match /crash="burn"/ + expect(attrs).must_match(/some_long_attribute="with short value"/) + expect(attrs).must_match(/merb="uses extlib"/) + expect(attrs).must_match(/crash="burn"/) end end diff --git a/test/json_test.rb b/test/json_test.rb index 74db077..641b3f7 100644 --- a/test/json_test.rb +++ b/test/json_test.rb @@ -47,7 +47,11 @@ TESTS.each do |json, expected| it "decode json (#{json})" do - Crack::JSON.parse(json).must_equal expected + if expected.nil? + assert_nil(Crack::JSON.parse(json)) + else + expect(Crack::JSON.parse(json)).must_equal expected + end end end diff --git a/test/parser_test.rb b/test/parser_test.rb index 51336f7..8b4cb84 100644 --- a/test/parser_test.rb +++ b/test/parser_test.rb @@ -2,7 +2,7 @@ describe Crack::XML do it "default to REXMLParser" do - Crack::XML.parser.must_equal Crack::REXMLParser + expect(Crack::XML.parser).must_equal Crack::REXMLParser end describe "with a custom Parser" do @@ -17,7 +17,7 @@ def self.parse(xml) end it "use the custom Parser" do - Crack::XML.parse("").must_equal "" + expect(Crack::XML.parse("")).must_equal "" end after do diff --git a/test/string_test.rb b/test/string_test.rb index c73f172..b945b04 100644 --- a/test/string_test.rb +++ b/test/string_test.rb @@ -3,29 +3,29 @@ describe Crack::Util do describe "snake_case" do it "lowercases one word CamelCase" do - Crack::Util.snake_case("Merb").must_equal "merb" + expect(Crack::Util.snake_case("Merb")).must_equal "merb" end it "makes one underscore snake_case two word CamelCase" do - Crack::Util.snake_case("MerbCore").must_equal "merb_core" + expect(Crack::Util.snake_case("MerbCore")).must_equal "merb_core" end it "handles CamelCase with more than 2 words" do - Crack::Util.snake_case("SoYouWantContributeToMerbCore").must_equal "so_you_want_contribute_to_merb_core" + expect(Crack::Util.snake_case("SoYouWantContributeToMerbCore")).must_equal "so_you_want_contribute_to_merb_core" end it "handles CamelCase with more than 2 capital letter in a row" do - Crack::Util.snake_case("CNN").must_equal "cnn" - Crack::Util.snake_case("CNNNews").must_equal "cnn_news" - Crack::Util.snake_case("HeadlineCNNNews").must_equal "headline_cnn_news" + expect(Crack::Util.snake_case("CNN")).must_equal "cnn" + expect(Crack::Util.snake_case("CNNNews")).must_equal "cnn_news" + expect(Crack::Util.snake_case("HeadlineCNNNews")).must_equal "headline_cnn_news" end it "does NOT change one word lowercase" do - Crack::Util.snake_case("merb").must_equal "merb" + expect(Crack::Util.snake_case("merb")).must_equal "merb" end it "leaves snake_case as is" do - Crack::Util.snake_case("merb_core").must_equal "merb_core" + expect(Crack::Util.snake_case("merb_core")).must_equal "merb_core" end end end diff --git a/test/xml_test.rb b/test/xml_test.rb index b71b2d5..5ea6f56 100644 --- a/test/xml_test.rb +++ b/test/xml_test.rb @@ -3,7 +3,7 @@ describe Crack::XML do it "should transform a simple tag with content" do xml = "This is the contents" - Crack::XML.parse(xml).must_equal({ 'tag' => 'This is the contents' }) + expect(Crack::XML.parse(xml)).must_equal({ 'tag' => 'This is the contents' }) end it "should work with cdata tags" do @@ -14,13 +14,13 @@ ]]> END - Crack::XML.parse(xml)["tag"].strip.must_equal "text inside cdata" + expect(Crack::XML.parse(xml)["tag"].strip).must_equal "text inside cdata" end it "should transform a simple tag with attributes" do xml = "" hash = { 'tag' => { 'attr1' => '1', 'attr2' => '2' } } - Crack::XML.parse(xml).must_equal hash + expect(Crack::XML.parse(xml)).must_equal hash end it "should transform repeating siblings into an array" do @@ -31,7 +31,7 @@ XML - Crack::XML.parse(xml)['opt']['user'].class.must_equal Array + expect(Crack::XML.parse(xml)['opt']['user'].class).must_equal Array hash = { 'opt' => { @@ -45,7 +45,7 @@ } } - Crack::XML.parse(xml).must_equal hash + expect(Crack::XML.parse(xml)).must_equal hash end it "should not transform non-repeating siblings into an array" do @@ -55,7 +55,7 @@ XML - Crack::XML.parse(xml)['opt']['user'].class.must_equal Hash + expect(Crack::XML.parse(xml)['opt']['user'].class).must_equal Hash hash = { 'opt' => { @@ -66,7 +66,7 @@ } } - Crack::XML.parse(xml).must_equal hash + expect(Crack::XML.parse(xml)).must_equal hash end describe "Parsing xml with text and attributes" do @@ -81,7 +81,7 @@ end it "correctly parse text nodes" do - @data.must_equal({ + expect(@data).must_equal({ 'opt' => { 'user' => [ 'Gary R Epstein', @@ -92,48 +92,48 @@ end it "be parse attributes for text node if present" do - @data['opt']['user'][0].attributes.must_equal({'login' => 'grep'}) + expect(@data['opt']['user'][0].attributes).must_equal({'login' => 'grep'}) end it "default attributes to empty hash if not present" do - @data['opt']['user'][1].attributes.must_equal({}) + expect(@data['opt']['user'][1].attributes).must_equal({}) end it "add 'attributes' accessor methods to parsed instances of String" do - @data['opt']['user'][0].respond_to?(:attributes).must_equal(true) - @data['opt']['user'][0].respond_to?(:attributes=).must_equal(true) + expect(@data['opt']['user'][0].respond_to?(:attributes)).must_equal(true) + expect(@data['opt']['user'][0].respond_to?(:attributes=)).must_equal(true) end it "not add 'attributes' accessor methods to all instances of String" do - "some-string".respond_to?(:attributes).must_equal(false) - "some-string".respond_to?(:attributes=).must_equal(false) + expect("some-string".respond_to?(:attributes)).must_equal(false) + expect("some-string".respond_to?(:attributes=)).must_equal(false) end end it "should typecast an integer" do xml = "10" - Crack::XML.parse(xml)['tag'].must_equal 10 + expect(Crack::XML.parse(xml)['tag']).must_equal 10 end it "should typecast a true boolean" do xml = "true" - Crack::XML.parse(xml)['tag'].must_equal(true) + expect(Crack::XML.parse(xml)['tag']).must_equal(true) end it "should typecast a false boolean" do ["false"].each do |w| - Crack::XML.parse("#{w}")['tag'].must_equal(false) + expect(Crack::XML.parse("#{w}")['tag']).must_equal(false) end end it "should typecast a datetime" do xml = "2007-12-31 10:32" - Crack::XML.parse(xml)['tag'].must_equal Time.parse( '2007-12-31 10:32' ).utc + expect(Crack::XML.parse(xml)['tag']).must_equal Time.parse( '2007-12-31 10:32' ).utc end it "should typecast a date" do xml = "2007-12-31" - Crack::XML.parse(xml)['tag'].must_equal Date.parse('2007-12-31') + expect(Crack::XML.parse(xml)['tag']).must_equal Date.parse('2007-12-31') end xml_entities = { @@ -146,51 +146,51 @@ it "should unescape html entities" do xml_entities.each do |k,v| xml = "Some content #{v}" - Crack::XML.parse(xml)['tag'].must_match Regexp.new(k) + expect(Crack::XML.parse(xml)['tag']).must_match Regexp.new(k) end end it "should unescape XML entities in attributes" do xml_entities.each do |k,v| xml = "" - Crack::XML.parse(xml)['tag']['attr'].must_match Regexp.new(k) + expect(Crack::XML.parse(xml)['tag']['attr']).must_match Regexp.new(k) end end it "should undasherize keys as tags" do xml = "Stuff" - Crack::XML.parse(xml).keys.must_include( 'tag_1' ) + expect(Crack::XML.parse(xml).keys).must_include( 'tag_1' ) end it "should undasherize keys as attributes" do xml = "" - Crack::XML.parse(xml)['tag1'].keys.must_include( 'attr_1') + expect(Crack::XML.parse(xml)['tag1'].keys).must_include( 'attr_1') end it "should undasherize keys as tags and attributes" do xml = "" - Crack::XML.parse(xml).keys.must_include( 'tag_1' ) - Crack::XML.parse(xml)['tag_1'].keys.must_include( 'attr_1') + expect(Crack::XML.parse(xml).keys).must_include( 'tag_1' ) + expect(Crack::XML.parse(xml)['tag_1'].keys).must_include( 'attr_1') end it "should render nested content correctly" do xml = "Tag1 Content This is strong" - Crack::XML.parse(xml)['root']['tag1'].must_equal "Tag1 Content This is strong" + expect(Crack::XML.parse(xml)['root']['tag1']).must_equal "Tag1 Content This is strong" end it "should render nested content with splshould text nodes correctly" do xml = "Tag1 ContentStuff Hi There" - Crack::XML.parse(xml)['root'].must_equal "Tag1 ContentStuff Hi There" + expect(Crack::XML.parse(xml)['root']).must_equal "Tag1 ContentStuff Hi There" end it "should ignore attributes when a child is a text node" do xml = "Stuff" - Crack::XML.parse(xml).must_equal({ "root" => "Stuff" }) + expect(Crack::XML.parse(xml)).must_equal({ "root" => "Stuff" }) end it "should ignore attributes when any child is a text node" do xml = "Stuff in italics" - Crack::XML.parse(xml).must_equal({ "root" => "Stuff in italics" }) + expect(Crack::XML.parse(xml)).must_equal({ "root" => "Stuff in italics" }) end it "should correctly transform multiple children" do @@ -215,7 +215,7 @@ } } - Crack::XML.parse(xml).must_equal hash + expect(Crack::XML.parse(xml)).must_equal hash end it "should properly handle nil values (ActiveSupport Compatible)" do @@ -238,7 +238,7 @@ 'viewed_at' => nil, 'parent_id' => nil } - Crack::XML.parse(topic_xml)["topic"].must_equal expected_topic_hash + expect(Crack::XML.parse(topic_xml)["topic"]).must_equal expected_topic_hash end it "should handle a single record from xml (ActiveSupport Compatible)" do @@ -277,7 +277,11 @@ } Crack::XML.parse(topic_xml)["topic"].each do |k,v| - v.must_equal expected_topic_hash[k] + if expected_topic_hash[k].nil? + assert_nil(v) + else + expect(v).must_equal expected_topic_hash[k] + end end end @@ -327,8 +331,12 @@ 'parent_id' => nil } # puts Crack::XML.parse(topics_xml)['topics'].first.inspect - Crack::XML.parse(topics_xml)["topics"].first.each do |k,v| - v.must_equal expected_topic_hash[k] + Crack::XML.parse(topics_xml)["topics"].first.each do |k, v| + if expected_topic_hash[k].nil? + assert_nil(v) + else + expect(v).must_equal expected_topic_hash[k] + end end end @@ -352,7 +360,7 @@ 'isfamily' => "0", } Crack::XML.parse(topic_xml)["rsp"]["photos"]["photo"].each do |k,v| - v.must_equal expected_topic_hash[k] + expect(v).must_equal expected_topic_hash[k] end end @@ -363,7 +371,7 @@ XML expected_blog_hash = {"blog" => {"posts" => []}} - Crack::XML.parse(blog_xml).must_equal expected_blog_hash + expect(Crack::XML.parse(blog_xml)).must_equal expected_blog_hash end it "should handle empty array with whitespace from xml (ActiveSupport Compatible)" do @@ -374,7 +382,7 @@ XML expected_blog_hash = {"blog" => {"posts" => []}} - Crack::XML.parse(blog_xml).must_equal expected_blog_hash + expect(Crack::XML.parse(blog_xml)).must_equal expected_blog_hash end it "should handle array with one entry from_xml (ActiveSupport Compatible)" do @@ -386,7 +394,7 @@ XML expected_blog_hash = {"blog" => {"posts" => ["a post"]}} - Crack::XML.parse(blog_xml).must_equal expected_blog_hash + expect(Crack::XML.parse(blog_xml)).must_equal expected_blog_hash end it "should handle array with multiple entries from xml (ActiveSupport Compatible)" do @@ -399,7 +407,7 @@ XML expected_blog_hash = {"blog" => {"posts" => ["a post", "another post"]}} - Crack::XML.parse(blog_xml).must_equal expected_blog_hash + expect(Crack::XML.parse(blog_xml)).must_equal expected_blog_hash end it "should handle file types (ActiveSupport Compatible)" do @@ -410,12 +418,12 @@ XML hash = Crack::XML.parse(blog_xml) - hash.keys.must_include('blog') - hash['blog'].keys.must_include('logo') + expect(hash.keys).must_include('blog') + expect(hash['blog'].keys).must_include('logo') file = hash['blog']['logo'] - file.original_filename.must_equal 'logo.png' - file.content_type.must_equal 'image/png' + expect(file.original_filename).must_equal 'logo.png' + expect(file.content_type).must_equal 'image/png' end it "should handle file from xml with defaults (ActiveSupport Compatible)" do @@ -426,8 +434,8 @@ XML file = Crack::XML.parse(blog_xml)['blog']['logo'] - file.original_filename.must_equal 'untitled' - file.content_type.must_equal 'application/octet-stream' + expect(file.original_filename).must_equal 'untitled' + expect(file.content_type).must_equal 'application/octet-stream' end it "should handle xsd like types from xml (ActiveSupport Compatible)" do @@ -451,7 +459,7 @@ 'illustration' => "babe.png" } - Crack::XML.parse(bacon_xml)["bacon"].must_equal expected_bacon_hash + expect(Crack::XML.parse(bacon_xml)["bacon"]).must_equal expected_bacon_hash end it "should let type trickle through when unknown (ActiveSupport Compatible)" do @@ -468,7 +476,7 @@ 'image' => {'type' => 'ProductImage', 'filename' => 'image.gif' }, } - Crack::XML.parse(product_xml)["product"].must_equal expected_product_hash + expect(Crack::XML.parse(product_xml)["product"]).must_equal expected_product_hash end it "should handle unescaping from xml (ActiveResource Compatible)" do @@ -478,16 +486,16 @@ 'pre_escaped_string' => 'First & Last Name' } - Crack::XML.parse(xml_string)['person'].must_equal expected_hash + expect(Crack::XML.parse(xml_string)['person']).must_equal expected_hash end it "handle an empty xml string" do - Crack::XML.parse('').must_equal({}) + expect(Crack::XML.parse('')).must_equal({}) end # As returned in the response body by the unfuddle XML API when creating objects it "handle an xml string containing a single space" do - Crack::XML.parse(' ').must_equal({}) + expect(Crack::XML.parse(' ')).must_equal({}) end it "can dump parsed xml" do @@ -509,6 +517,6 @@ EOT - Crack::XML.parse(example_xml).must_equal({"disk"=>{"driver"=>{"name"=>"qemu", "type"=>"raw", "cache"=>"none", "io"=>"native"}, "source"=>{"file"=>"/tmp/cdrom.iso"}, "type"=>"file", "device"=>"cdrom"}}) + expect(Crack::XML.parse(example_xml)).must_equal({"disk"=>{"driver"=>{"name"=>"qemu", "type"=>"raw", "cache"=>"none", "io"=>"native"}, "source"=>{"file"=>"/tmp/cdrom.iso"}, "type"=>"file", "device"=>"cdrom"}}) end end