Class: TargetPracticeTestCase

Inherits:
MiniTest::Unit::TestCase
  • Object
show all
Defined in:
lib/target_practice/target_practice_test_case.rb

Constant Summary collapse

@@meta_assertions =
{}

Instance Method Summary collapse

Instance Method Details

#assert_attributes(obj, hash = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/target_practice/target_practice_test_case.rb', line 16

def assert_attributes(obj, hash={})
  return if hash.nil?

  hash.each do |k,v|
    assert obj.send(k.to_sym) if !is_meta_command?(k)

    if is_meta_command? k
      perform_meta_assertion(obj, k, v)
    elsif v.kind_of? Array
      index = 0
      v.each do |i|
        assert_attributes(obj.send(k.to_sym)[index], i)
        index += 1
      end
    elsif v.kind_of? Hash
      assert_attributes(obj.send(k.to_sym), v)
    elsif v.kind_of? String
      assert_equal v, obj.send(k.to_sym)
    end
  end
end

#filesObject



8
9
10
# File 'lib/target_practice/target_practice_test_case.rb', line 8

def files
  @@files
end

#files=(f) ⇒ Object



12
13
14
# File 'lib/target_practice/target_practice_test_case.rb', line 12

def files=(f)
  @@files = f
end

#is_meta_command?(v) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/target_practice/target_practice_test_case.rb', line 38

def is_meta_command?(v)
  @@meta_assertions.keys.include? v
end

#perform_meta_assertion(obj, command, v) ⇒ Object



42
43
44
# File 'lib/target_practice/target_practice_test_case.rb', line 42

def perform_meta_assertion(obj, command, v)
  @@meta_assertions[command].call(self, obj, v) if @@meta_assertions[command]
end

#setupObject



4
5
6
# File 'lib/target_practice/target_practice_test_case.rb', line 4

def setup
  assert @@files, "File data was not set!"
end