File: base.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 (64 lines) | stat: -rw-r--r-- 1,668 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
54
55
56
57
58
59
60
61
62
63
64
require File.expand_path('../../project/generator', __FILE__)

module IntegrationTests
  module Base
    class FailWithOutputMatcher < Struct.new(:pattern)
      def matches?(result)
        result.output =~ pattern
      end

      def description
        "fail with output #{pattern.inspect}"
      end

      def failure_message_for_should
        "Expected running the test to produce output #{pattern.inspect} but it didn't"
      end

      def failure_message_for_should_not
        "Expected running the test to not produce output #{pattern.inspect} but it did"
      end
    end

    class HaveErrorsOrFailuresMatcher
      def matches?(result)
        match = result.output.match(/(\d+) error|(\d+) failure/)
        match && match.captures.any? {|value| value && value.to_i > 0 }
      end

      def description
        "have errors or failures"
      end

      def failure_message_for_should
        "Expected running the test to result in errors or failures but it did not"
      end

      def failure_message_for_should_not
        "Expected running the test to not result in errors or failures, but it did "
      end
    end

    def build_project_generator
      Project::Generator.factory do |project_generator|
        configure_project_generator(project_generator)
        yield project_generator if block_given?
      end
    end

    def generate_project(&block)
      build_project_generator.call(&block)
    end

    def configure_project_generator(generator)
    end

    def fail_with_output(pattern)
      FailWithOutputMatcher.new(pattern)
    end

    def have_errors_or_failures
      HaveErrorsOrFailuresMatcher.new
    end
  end
end