Skip to content

Commit

Permalink
Merge pull request #160 from dylanratcliffe/fix_function_mocking
Browse files Browse the repository at this point in the history
Fix function mocking
  • Loading branch information
dylanratcliffe authored Mar 8, 2018
2 parents aee1579 + fe6bbe7 commit 80e5db1
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 2 deletions.
7 changes: 6 additions & 1 deletion features/run.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@run
Feature: Run rspec and acceptance test suits
Feature: Run rspec and acceptance test suites
Onceover should allow to run rspec and acceptance test for all profvile and role classes
or for any part of them. Use should set if he wants to see only summary of tests or full
log info.
Expand Down Expand Up @@ -41,3 +41,8 @@ Feature: Run rspec and acceptance test suits
And I make local modifications
And I run onceover command "run spec --force"
Then I should see message pattern "Overwriting local modifications"

Scenario: Mocking functions should work and return the correct data types
Given control repo "function_mocking"
When I run onceover command "run spec"
Then I should not see any errors
1 change: 1 addition & 0 deletions spec/fixtures/controlrepos/function_mocking/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.onceover
3 changes: 3 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'onceover'
17 changes: 17 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/Puppetfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
forge "http://forge.puppetlabs.com"
#
# I want to download some modules to check if r10k feature in Onceover works correctly.
#

# Versions should be updated to be the latest at the time you start
mod "puppetlabs/stdlib", '4.11.0'

# Modules from Git
# Examples: https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd#examples
mod 'apache',
:git => 'https://github.com/puppetlabs/puppetlabs-apache',
:commit => '83401079053dca11d61945bd9beef9ecf7576cbf'

#mod 'apache',
# :git => 'https://github.com/puppetlabs/puppetlabs-apache',
# :branch => 'docs_experiment'
1 change: 1 addition & 0 deletions spec/fixtures/controlrepos/function_mocking/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'onceover/rake_tasks'
2 changes: 2 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/environment.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
modulepath = site:modules:$basemodulepath
config_version = 'scripts/config_version.sh $environmentpath $environment'
32 changes: 32 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/manifests/site.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## site.pp ##

# This file (/etc/puppetlabs/puppet/manifests/site.pp) is the main entry point
# used when an agent connects to a master and asks for an updated configuration.
#
# Global objects like filebuckets and resource defaults should go in this file,
# as should the default node definition. (The default node can be omitted
# if you use the console and don't define any other nodes in site.pp. See
# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on
# node definitions.)

## Active Configurations ##

# Disable filebucket by default for all File resources:
#https://docs.puppet.com/pe/2015.3/release_notes.html#filebucket-resource-no-longer-created-by-default
File { backup => false }

# DEFAULT NODE
# Node definitions in this file are merged with node data from the console. See
# http://docs.puppetlabs.com/guides/language_guide.html#nodes for more on
# node definitions.

# The default node definition matches any node lacking a more specific node
# definition. If there are no other nodes in this file, classes declared here
# will be included in every node's catalog, *in addition* to any classes
# specified in the console for that node.

node default {
# This is where you can declare classes for all nodes.
# Example:
# class { 'my_class': }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# == Class: role::test_functions
#
class role::test_functions {
unless string('foo') =~ String {
fail('string() did not return a string')
}
unless number('foo') =~ Numeric {
fail('string() did not return a string')
}
unless boolean('foo') =~ Boolean {
fail('string() did not return a string')
}
unless array('foo') =~ Array {
fail('string() did not return a string')
}
unless hash('foo') =~ Hash {
fail('string() did not return a string')
}
}
43 changes: 43 additions & 0 deletions spec/fixtures/controlrepos/function_mocking/spec/onceover.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Classes to be tested
classes:
- role::test_functions

# Nodes to tests classes on, this refers to a 'factset' or 'nodeset'
# depending on weather you are running 'spec' or 'acceptance' tests
nodes:
- CentOS-7.0-64

# You can group classes here to save typing
class_groups:

# You can group nodes here to save typing
# We have created a 'non_windows_nodes' group because we can't
# give you Windows vagrant boxes to test with because licensing,
# we can give you fact sets though so go crazy with spec testing!
node_groups:

test_matrix:
- all_nodes:
classes: 'all_classes'
tests: 'spec'

functions:
string:
type: rvalue
returns: string
number:
type: rvalue
returns: 400
boolean:
type: rvalue
returns: true
array:
type: rvalue
returns:
- 1
- 2
- 3
hash:
type: rvalue
returns:
foo: bar
2 changes: 1 addition & 1 deletion templates/test_spec.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe "<%= cls.name %>" do
MockFunction.new('<%= function %>', {:type => :statement})
<% else -%>
let!(:<%= function %>) { MockFunction.new('<%= function %>') { |f|
f.stubbed.returns(<%= params['returns'] %>)
f.stubbed.returns(<%= params['returns'].inspect %>)
}
}
<% end -%>
Expand Down

0 comments on commit 80e5db1

Please sign in to comment.