File: formatter_spec.rb

package info (click to toggle)
ruby-oembed 0.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,468 kB
  • sloc: ruby: 2,351; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require File.dirname(__FILE__) + '/spec_helper'

describe OEmbed::Formatter do
  include OEmbedSpecHelper

  it "should support JSON" do
    expect {
      OEmbed::Formatter.supported?(:json)
    }.to_not raise_error
  end

  it "should default to JSON" do
    expect(OEmbed::Formatter.default).to eq('json')
  end

  it "should decode a JSON String" do
    decoded = OEmbed::Formatter.decode(:json, valid_response(:json))
    # We need to compare keys & values separately because we don't expect all
    # non-string values to be recognized correctly.
    expect(decoded.keys).to eq(valid_response(:object).keys)
    expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
  end

  it "should support XML" do
    expect {
      OEmbed::Formatter.supported?(:xml)
    }.to_not raise_error
  end

  it "should decode an XML String" do
    decoded = OEmbed::Formatter.decode(:xml, valid_response(:xml))
    # We need to compare keys & values separately because we don't expect all
    # non-string values to be recognized correctly.
    expect(decoded.keys).to eq(valid_response(:object).keys)
    expect(decoded.values.map{|v|v.to_s}).to eq(valid_response(:object).values.map{|v|v.to_s})
  end
end