Class: Mrubyc::Test::Generator::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/mrubyc/test/generator/test_case.rb

Class Method Summary collapse

Class Method Details

.run(attributes) ⇒ Object



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
# File 'lib/mrubyc/test/generator/test_case.rb', line 8

def run(attributes)
  test_cases = []
  attributes[:method_locations].each do |klass, methods|
    methods.each do |method|
      if attributes[:description_locations].size > 0
        found_desc = attributes[:description_locations][klass].find do |hash|
          hash[:line] == method[:line] -1
        end
      end
      description = found_desc ? found_desc[:text] : ''
      information = {
        test_class_name: klass.to_s,
        method_name: method[:method_name],
        path: method[:path],
        line: method[:line],
        description: description
      }
      stubs = []
      mocks = []
      attributes[:double_method_locations][klass].each do |hash|
        if hash.keys[0] == method[:method_name]
          hash[method[:method_name]].each do |double|
            stub_or_mock = { class_name: double[:class].to_s,
              instance_variables: nil, # TODO
              method_name: double[:method_name].to_s,
              args: double[:args],
              method_parameters: double[:method_parameters],
              return_value: double[:block],
              line: double[:line]
            }
            if double[:type] == :stub
              stubs << stub_or_mock
            else
              mocks << stub_or_mock
            end
          end
        end
      end
      test_cases << {
        information: information,
        stubs: stubs,
        mocks: mocks
      }
    end
  end
  test_cases
end