File: test_listener.rb

package info (click to toggle)
mikutter 4.1.3%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,260 kB
  • sloc: ruby: 20,126; sh: 183; makefile: 19
file content (66 lines) | stat: -rw-r--r-- 1,629 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-

require 'test/unit'
require 'rubygems'
require 'mocha/setup'
listener = File.expand_path File.join(__dir__, 'listener')
require File.expand_path(__dir__ + '/../../utils')
require 'lib/test_unit_extensions'

class Plugin; end
class Plugin::Settings; end
class UserConfig; end
require listener

class TC_Listener < Test::Unit::TestCase
  must "no value given" do
    n = Plugin::Settings::Listener.new
    n.set :a
    assert_equal(:a, n.get)
  end

  must "set hooked" do
    x = nil
    n = Plugin::Settings::Listener.new :set => lambda{ |new| x = new }
    n.set :a
    assert_equal(:a, n.get)
    assert_equal(:a, x)
  end

  must "get hooked" do
    x = nil
    n = Plugin::Settings::Listener.new :get => lambda{ x }
    assert_nil(n.get)
    x = :a
    assert_equal(:a, n.get)
    n.set :b
    assert_equal(:a, n.get)
  end

  must "between hooked" do
    x = nil
    n = Plugin::Settings::Listener.new(:set => lambda{ |new| x = new },
                                      :get => lambda{ x })
    assert_nil(n.get)
    x = :a
    assert_equal(:a, n.get)
    n.set :b
    assert_equal(:b, n.get)
  end

  must "slash" do
    UserConfig.stubs(:[]).with(:setting_test).returns(HYDE).once
    UserConfig.stubs(:[]=).with(:setting_test, HYDE).returns(HYDE).once
    assert_equal(156, Plugin::Settings::Listener[:setting_test].get)
    assert_equal(156, Plugin::Settings::Listener[:setting_test].set(HYDE))
  end

end
# >> Loaded suite -
# >> Started
# >> .....
# >> Finished in 0.001353 seconds.
# >> 
# >> 5 tests, 13 assertions, 0 failures, 0 errors, 0 skips
# >> 
# >> Test run options: --seed 49676