test/test_vacuum.rb in vacuum-1.1.1 vs test/test_vacuum.rb in vacuum-1.2.0

- old
+ new

@@ -20,25 +20,53 @@ def test_defaults_to_us_endpoint assert_equal 'http://webservices.amazon.com/onca/xml', @req.aws_endpoint end def test_fetches_parsable_response - Excon.stub({}, { body: '<foo>bar</foo>' }) - @req.configure(aws_access_key_id: 'key', aws_secret_access_key: 'secret', associate_tag: 'tag') + Excon.stub({}, body: '<foo/>') res = @req.item_lookup({}, mock: true) - refute_empty res.to_h + refute_empty res.parse end def test_alternative_query_syntax - Excon.stub({}, { body: '<foo>bar</foo>' }) - req = Request.new - req.configure(aws_access_key_id: 'key', aws_secret_access_key: 'secret', associate_tag: 'tag') - res = req.item_lookup(query: {}, mock: true) - refute_empty res.to_h + Excon.stub({}, body: '<foo/>') + res = @req.item_lookup(query: {}, mock: true) + refute_empty res.parse end def test_force_encodes_body res = Object.new - def res.body; String.new.force_encoding('ASCII-8BIT'); end + def res.body + ''.force_encoding('ASCII-8BIT') + end assert_equal 'UTF-8', Response.new(res).body.encoding.name + end + + def test_sets_custom_parser_on_class_level + original_parser = Response.parser + Excon.stub({}, body: '<foo/>') + parser = MiniTest::Mock.new + parser.expect(:parse, '123', ['<foo/>']) + Response.parser = parser + res = @req.item_lookup(query: {}, mock: true) + assert_equal '123', res.parse + Response.parser = original_parser # clean up + end + + def test_sets_custom_parser_on_instance_level + Excon.stub({}, body: '<foo/>') + res = @req.item_lookup(query: {}, mock: true) + parser = MiniTest::Mock.new + parser.expect(:parse, '123', ['<foo/>']) + res.parser = parser + assert_equal '123', res.parse + end + + def test_casts_to_hash + Excon.stub({}, body: '<foo/>') + parser = MiniTest::Mock.new + res = @req.item_lookup(query: {}, mock: true) + assert_kind_of Hash, res.to_h + res.parser = parser + assert_kind_of Hash, res.to_h end end