Class: TestKitchen::Project::Base

Inherits:
Object
  • Object
show all
Includes:
Chef::Mixin::ParamsValidate
Defined in:
lib/test-kitchen/project/base.rb

Direct Known Subclasses

Ruby

Constant Summary collapse

PROJECT_ROOT_INDICATORS =
["Gemfile", "metadata.rb"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent = nil, &block) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
41
# File 'lib/test-kitchen/project/base.rb', line 32

def initialize(name, parent=nil, &block)
  raise ArgumentError, "Project name must be specified" if name.nil? || name.empty?
  @name = name
  @parent = parent
  @configurations = {}
  @exclusions = []
  @guest_source_root = '/test-kitchen/source'
  @guest_test_root = '/test-kitchen/test'
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#configurationsObject



59
60
61
# File 'lib/test-kitchen/project/base.rb', line 59

def configurations
  @configurations.empty? ? {:default => self} : @configurations
end

#exclusionsObject (readonly)

Returns the value of attribute exclusions.



28
29
30
# File 'lib/test-kitchen/project/base.rb', line 28

def exclusions
  @exclusions
end

#guest_source_rootObject (readonly)

Returns the value of attribute guest_source_root.



28
29
30
# File 'lib/test-kitchen/project/base.rb', line 28

def guest_source_root
  @guest_source_root
end

#guest_test_rootObject (readonly)

Returns the value of attribute guest_test_root.



28
29
30
# File 'lib/test-kitchen/project/base.rb', line 28

def guest_test_root
  @guest_test_root
end

#install(arg = nil) ⇒ Object



96
97
98
99
# File 'lib/test-kitchen/project/base.rb', line 96

def install(arg=nil)
  set_or_return(:install, arg,
    :default => language == 'ruby' ? 'bundle install' : '')
end

#language(arg = nil) ⇒ Object



83
84
85
# File 'lib/test-kitchen/project/base.rb', line 83

def language(arg=nil)
  set_or_return(:language, arg, :default => 'ruby')
end

#memory(arg = nil) ⇒ Object



105
106
107
# File 'lib/test-kitchen/project/base.rb', line 105

def memory(arg=nil)
  set_or_return(:memory, arg, {})
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/test-kitchen/project/base.rb', line 28

def name
  @name
end

#root_pathObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/test-kitchen/project/base.rb', line 117

def root_path
  return @root_path if defined?(@root_path)

  root_finder = lambda do |path|
    found = PROJECT_ROOT_INDICATORS.find do |rootfile|
      File.exist?(File.join(path.to_s, rootfile))
    end

    return path if found
    return nil if path.root? || !File.exist?(path)
    root_finder.call(path.parent)
  end

  @root_path = root_finder.call(Pathname.new(Dir.pwd))
end

#runtimes(arg = nil) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/test-kitchen/project/base.rb', line 87

def runtimes(arg=nil)
  set_or_return(:runtimes, arg, :default =>
    if language == 'ruby' || language == 'chef'
      ['1.9.2']
    else
      []
    end)
end

#script(arg = nil) ⇒ Object



101
102
103
# File 'lib/test-kitchen/project/base.rb', line 101

def script(arg=nil)
  set_or_return(:script, arg, :default => 'rspec spec')
end

#vmObject

Returns the value of attribute vm.



30
31
32
# File 'lib/test-kitchen/project/base.rb', line 30

def vm
  @vm
end

Instance Method Details

#configuration(name, &block) ⇒ Object



55
56
57
# File 'lib/test-kitchen/project/base.rb', line 55

def configuration(name, &block)
  @configurations[name] = self.class.new(name, self, &block)
end

#each_build(platforms, active_config = nil) ⇒ Object

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/test-kitchen/project/base.rb', line 43

def each_build(platforms, active_config=nil)
  raise ArgumentError if platforms.nil? || ! block_given?
  c = Array(active_config ?
    configurations[active_config] : configurations.values)
  platforms.to_a.product(c).each do |platform,configuration|
    yield [platform, configuration] unless exclusions.any? do |e|
      e[:platform] == platform.split('-').first &&
        ((! e[:configuration]) || e[:configuration] == configuration.name)
    end
  end
end

#exclude(exclusion) ⇒ Object



67
68
69
# File 'lib/test-kitchen/project/base.rb', line 67

def exclude(exclusion)
  @exclusions << exclusion
end

#features(arg = nil) ⇒ Object



113
114
115
# File 'lib/test-kitchen/project/base.rb', line 113

def features(arg=nil)
  set_or_return(:features, arg, {:default => true})
end

#install_command(runtime = nil) ⇒ Object

Raises:

  • (NotImplementedError)


141
142
143
# File 'lib/test-kitchen/project/base.rb', line 141

def install_command(runtime=nil)
  raise NotImplementedError
end

#preflight_commandObject



137
138
139
# File 'lib/test-kitchen/project/base.rb', line 137

def preflight_command
  nil
end

#run_listObject



71
72
73
# File 'lib/test-kitchen/project/base.rb', line 71

def run_list
  ['test-kitchen::default'] + run_list_extras
end

#run_list_extras(arg = nil) ⇒ Object



75
76
77
# File 'lib/test-kitchen/project/base.rb', line 75

def run_list_extras(arg=nil)
  set_or_return(:run_list_extras, arg, :default => [])
end

#runner(arg = nil) ⇒ Object



79
80
81
# File 'lib/test-kitchen/project/base.rb', line 79

def runner(arg=nil)
  set_or_return(:runner, arg, :default => 'vagrant')
end

#specs(arg = nil) ⇒ Object



109
110
111
# File 'lib/test-kitchen/project/base.rb', line 109

def specs(arg=nil)
  set_or_return(:specs, arg, {:default => true})
end

#test_command(runtime = nil) ⇒ Object

Raises:

  • (NotImplementedError)


145
146
147
# File 'lib/test-kitchen/project/base.rb', line 145

def test_command(runtime=nil)
  raise NotImplementedError
end

#tests_tagObject



63
64
65
# File 'lib/test-kitchen/project/base.rb', line 63

def tests_tag
  @parent.nil? ? 'default' : name
end

#to_hashObject



149
150
151
152
153
154
155
156
# File 'lib/test-kitchen/project/base.rb', line 149

def to_hash
  self.runtimes # hack
  hash = {}
  self.instance_variables.each do |var|
    hash[var[1..-1].to_sym] = self.instance_variable_get(var)
  end
  hash
end

#update_code_commandObject



133
134
135
# File 'lib/test-kitchen/project/base.rb', line 133

def update_code_command
  "rsync -aHv --update --progress --checksum #{guest_source_root}/ #{guest_test_root}"
end