Method: Onceover::Test#initialize

Defined in:
lib/onceover/test.rb

#initialize(on_this, test_this, test_config) ⇒ Test

This can accept a bunch of stuff. It can accept nodes, classes or groups anywhere it will then detect them and expand them out into their respective objects so that we just end up with a list of nodes and classes def initialize(on_this,test_config,options = {})



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
# File 'lib/onceover/test.rb', line 15

def initialize(on_this,test_this,test_config)

  @default_test_config = {
    'check_idempotency' => true,
    'runs_before_idempotency' => 1
  }

  # Add defaults if they do not exist
  test_config = @default_test_config.merge(test_config)

  @nodes = []
  @classes = []
  @test_config = test_config
  @test_config.delete('classes') # remove classes from the config
  @tags = @test_config['tags']


  # Make sure that tags are an array
  @test_config['tags'] = [@test_config['tags']].flatten if @test_config['tags']

  # Get the nodes we are working on
  if Onceover::Group.find(on_this)
    @nodes << Onceover::Group.find(on_this).members
  elsif Onceover::Node.find(on_this)
    @nodes << Onceover::Node.find(on_this)
  else
    raise "#{on_this} was not found in the list of nodes or groups!"
  end

  @nodes.flatten!

  # Check that our nodes list contains only nodes
  raise "#{@nodes} contained a non-node object." unless @nodes.all? { |item| item.is_a?(Onceover::Node) }

  if test_this.is_a?(String)
    # If we have just given a string then grab all the classes it corresponds to
    if Onceover::Group.find(test_this)
      @classes << Onceover::Group.find(test_this).members
    elsif Onceover::Class.find(test_this)
      @classes << Onceover::Class.find(test_this)
    else
      raise "#{test_this} was not found in the list of classes or groups!"
    end
    @classes.flatten!
  elsif test_this.is_a?(Hash)
    @classes = Onceover::TestConfig.subtractive_to_list(test_this)
  elsif test_this.is_a?(Onceover::Class)
    @classes << test_this
  end
end