Skip to content

Commit

Permalink
Add before and after blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Macchi committed Feb 22, 2018
1 parent 649e682 commit 6d78c8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/onceover/testconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class TestConfig
attr_accessor :filter_classes
attr_accessor :filter_nodes
attr_accessor :mock_functions
attr_accessor :before_conditions
attr_accessor :after_conditions
attr_accessor :skip_r10k
attr_accessor :strict_variables

Expand All @@ -35,15 +37,17 @@ def initialize(file, opts = {})
raise "Could not parse #{file}, check that it is valid YAML and that the encoding is correct"
end

@classes = []
@nodes = []
@node_groups = []
@class_groups = []
@spec_tests = []
@acceptance_tests = []
@opts = opts
@mock_functions = config['functions']
@strict_variables = opts[:strict_variables] ? 'yes' : 'no'
@classes = []
@nodes = []
@node_groups = []
@class_groups = []
@spec_tests = []
@acceptance_tests = []
@opts = opts
@mock_functions = config['functions']
@before_conditions = config['before']
@after_conditions = config['after']
@strict_variables = opts[:strict_variables] ? 'yes' : 'no'

# Initialise all of the classes and nodes
config['classes'].each { |clarse| Onceover::Class.new(clarse) } unless config['classes'] == nil
Expand Down
14 changes: 14 additions & 0 deletions templates/test_spec.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ let!(:<%= function %>) { MockFunction.new('<%= function %>') { |f|
<% test.nodes.each do |node| -%>
context "using fact set <%= node.name %>" do
let(:facts) { <%= node.fact_set %> }
<% if @before_conditions -%>
before :each do
<% @before_conditions.each do |function| -%>
<%= function %>
<% end -%>
end
<% end -%>
<% if @after_conditions -%>
after :each do
<% @after_conditions.each do |function| -%>
<%= function %>
<% end -%>
end
<% end -%>
<% if pre_condition -%>
let(:pre_condition) {
pp = <%= '<<' %>-END
Expand Down

0 comments on commit 6d78c8a

Please sign in to comment.