require "test_helper"
class TestEntity < MiniTest::Test
def test_parses_floats
xml = <<-EOF
10.0
EOF
entity= build_entity(xml)
float = entity.float_at_xpath("Float")
assert_equal 10.0, float
end
def test_parses_integers
xml = <<-EOF
10
EOF
entity= build_entity(xml)
integer = entity.integer_at_xpath("Integer")
assert_equal 10, integer
end
def test_parses_money
xml = <<-EOF
USD
10.00
EOF
entity= build_entity(xml)
money = entity.money_at_xpath("Price")
assert_equal "$10.00", money.format
end
def test_parses_japanese_yen
xml = <<-EOF
JPY
1000.00
EOF
entity= build_entity(xml)
money = entity.money_at_xpath("Price")
assert_equal "¥1,000", money.format
end
def test_parses_text
xml = <<-EOF
Foo
EOF
entity= build_entity(xml)
text = entity.text_at_xpath("Text")
assert_equal "Foo", text
end
def test_strips_text
xml = <<-EOF
Foo
EOF
entity= build_entity(xml)
text = entity.text_at_xpath("Text")
assert_equal "Foo", text
end
def test_parses_time
xml = <<-EOF
EOF
entity= build_entity(xml)
time = entity.time_at_xpath("Time")
assert_kind_of Time, time
end
def test_handles_nil_values
xml = <<-EOF
EOF
entity= build_entity(xml)
assert_nil entity.float_at_xpath("Bar")
assert_nil entity.integer_at_xpath("Bar")
assert_nil entity.money_at_xpath("Bar")
assert_nil entity.time_at_xpath("Bar")
assert_nil entity.text_at_xpath("Bar")
end
private
def build_entity(xml)
Entity.new(Nokogiri(xml))
end
end