Module: Beaker::DSL::Structure

Included in:
Beaker::DSL
Defined in:
lib/beaker/dsl/structure.rb

Overview

These are simple structural elements necessary for writing understandable tests and ensuring cleanup actions happen. If using a third party test runner they are unnecessary.

To include this in your own test runner a method #logger should be available to yield a logger that implements Logger‘s interface. As well as a method #teardown_procs that yields an array.

Examples:

Structuring a test case.

test_name 'Look at me testing things!' do
  teardown do
    ...clean up actions...
  end

  step 'Prepare the things' do
    ...setup steps...
  end

  step 'Test the things' do
    ...tests...
  end
end

Instance Method Summary collapse

Instance Method Details

#step(step_name, &block) ⇒ Object

Provides a method to help structure tests into coherent steps.

Parameters:

  • step_name (String)

    The name of the step to be logged.

  • block (Proc)

    The actions to be performed in this step.



33
34
35
36
# File 'lib/beaker/dsl/structure.rb', line 33

def step step_name, &block
  logger.notify "\n  * #{step_name}\n"
  yield if block_given?
end

#teardown(&block) ⇒ Object

Declare a teardown process that will be called after a test case is complete.

Examples:

Always remove /etc/puppet/modules

teardown do
  on(master, puppet_resource('file', '/etc/puppet/modules',
    'ensure=absent', 'purge=true'))
end

Parameters:

  • block (Proc)

    block of code to execute during teardown



58
59
60
# File 'lib/beaker/dsl/structure.rb', line 58

def teardown &block
  @teardown_procs << block
end

#test_name(my_name, &block) ⇒ Object

Provides a method to name tests.

Parameters:

  • my_name (String)

    The name of the test to be logged.

  • block (Proc)

    The actions to be performed during this test.



44
45
46
47
# File 'lib/beaker/dsl/structure.rb', line 44

def test_name my_name, &block
  logger.notify "\n#{my_name}\n"
  yield if block_given?
end