Top Level Namespace

Defined Under Namespace

Modules: ComposeWorld

Instance Method Summary collapse

Instance Method Details

#check_services(table) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/compose_cucumber/steps.rb', line 52

def check_services(table)
  table.hashes.each do |row|
    assert row.key?('Name')
    services = services_by_name row['Name']
    service = services.first

    row.each do |key, value|
      next if key == 'Name'

      if key == 'Count'
        assert_equal(value.to_i, services.length, "Expected #{value} services, but got #{services.length}")
        next
      end
      assert(service.info.key?(key), "service #{service.info} should have key #{key}")
      actual = service.info[key]
      actual = actual.map { |port| format_port(port) } if key == 'Ports'
      actual = actual.join ', ' if actual.is_a? Array
      assert actual.match(value), "#{actual} should match #{value}"
    end
  end
end

#ensure_services(count) ⇒ Object



47
48
49
50
# File 'lib/compose_cucumber/steps.rb', line 47

def ensure_services(count)
  actual = services.map { |service| service.info['Labels']['com.docker.compose.service'] }.uniq.sort.length
  assert_equal(count.to_i, actual, "expected #{count}, but got #{actual} services")
end

#format_port(actual) ⇒ Object



85
86
87
88
89
# File 'lib/compose_cucumber/steps.rb', line 85

def format_port(actual)
  return "#{actual['IP']}:#{actual['PublicPort']}" if actual.key? 'IP'

  actual['PublicPort'].to_s
end

#to_regex(matcher) ⇒ Object



91
92
93
# File 'lib/compose_cucumber/steps.rb', line 91

def to_regex(matcher)
  "^#{matcher.gsub('.', '\.').gsub('\.\.\.', '.*')}$"
end