Module: FedoraLens::LensTests

Defined in:
lib/fedora_lens/lens_tests.rb

Instance Method Summary collapse

Instance Method Details

#test_lens(lens, source, value) {|converter| ... } ⇒ Object

See page 6 of the manual for the Harmony language for a description on how lenses work www.seas.upenn.edu/~harmony/manual.pdf

Examples:

testing a lens that converts xml to a dom and back

test_lens(lens, Nokogiri::XML("<a/>"), Nokogiri::XML("<b/>") do |v|
  v.to_xml
end

Parameters:

  • the (lens)

    lens to test

  • the (value)

    value to test with (when calling put)

  • the (source)

    source document this lens operates on

Yields:

  • (converter)

    a block that converts the value from the lens to something that can be compared with #== (defaults to the identity function)

Yield Parameters:

  • a (value or source)

    value that will be compared


21
22
23
24
25
# File 'lib/fedora_lens/lens_tests.rb', line 21

def test_lens(lens, source, value, &block)
  test_lens_get_put(lens, source, &block)
  test_lens_put_get(lens, source, value, &block)
  test_lens_create_get(lens, value, &block)
end

#test_lens_create_get(lens, value) ⇒ Object


49
50
51
52
53
54
55
56
57
58
# File 'lib/fedora_lens/lens_tests.rb', line 49

def test_lens_create_get(lens, value)
  it "is well-behaved (CreateGet: get(create(value)) == value)" do
    created = lens.get(lens.create(value))
    if block_given?
      yield(created).should eq yield(value)
    else
      created.should eq value
    end
  end
end

#test_lens_get_put(lens, source) ⇒ Object


27
28
29
30
31
32
33
34
35
36
# File 'lib/fedora_lens/lens_tests.rb', line 27

def test_lens_get_put(lens, source)
  it "is well-behaved (GetPut: put(source, get(source)) == source)" do
    converted = lens.put(source, lens.get(source))
    if block_given?
      yield(converted).should eq yield(source)
    else
      converted.should eq source
    end
  end
end

#test_lens_put_get(lens, source, value) ⇒ Object


38
39
40
41
42
43
44
45
46
47
# File 'lib/fedora_lens/lens_tests.rb', line 38

def test_lens_put_get(lens, source, value)
  it "is well-behaved (PutGet: get(put(source, value)) == value)" do
    converted = lens.get(lens.put(source, value))
    if block_given?
      yield(converted).should eq yield(value)
    else
      converted.should eq value
    end
  end
end