File: generator.rb

package info (click to toggle)
ruby-rr 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,424 kB
  • sloc: ruby: 11,405; makefile: 7
file content (53 lines) | stat: -rw-r--r-- 1,025 bytes parent folder | download | duplicates (6)
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
require File.expand_path('../../generator', __FILE__)

module TestCase
  class Generator
    include ::Generator

    attr_reader :test_file, :string

    def setup(test_file)
      super
      @test_file = test_file
      @prelude = ""
      @before_tests = ""
      @body = ""
      @number_of_tests = 0
    end

    def add_to_prelude(string)
      @prelude << string + "\n"
    end

    def add_to_before_tests(content)
      @before_tests << content + "\n"
    end

    def add_to_body(content)
      @body << content + "\n"
    end

    def add_test(body)
      @body << build_test(@number_of_tests, body) + "\n"
      @number_of_tests += 1
    end

    def add_working_test
      add_test <<-EOT
        object = Object.new
        mock(object).foo
        object.foo
      EOT
    end

    def call
      lines = []
      lines << @prelude
      lines << start_of_test_case
      lines << @before_tests
      lines << @body
      lines << "end"
      @string = lines.map { |line| line + "\n" }.join
    end
  end
end