Create the following folder structure in your cookbook:
test
└── integrationq
├── helpers
│ ├── serverspec
│ │ ├── shared_serverspec_tests
│ │ │ └── shared_tests2.rb
│ │ └── spec_helper.rb
│ └── shared_tests
│ └── shared_tests1.rb
├── prod
│ └── serverspec
│ └── prod_spec.rb
└── qa
└── serverspec
└── qa_spec.rb
And the following test suite setup in your .kitchen.yml
suites:
- name: qa
environment: qa
run_list:
- recipe[test-tk::default]
- name: prod
environment: prod
run_list:
- recipe[test-tk::default]
This will create the following suite structure on the test nodes when you run kitchen verify
:
QA Node
ubuntu@ip-172-31-18-237:/tmp/busser/suites$ tree .
.
├── serverspec
│ ├── qa_spec.rb
│ ├── shared_serverspec_tests
│ │ └── shared_tests2.rb
│ └── spec_helper.rb
└── shared_tests
└── shared_tests1.rb
Prod Node
ubuntu@ip-172-31-21-211:/tmp/busser/suites$ tree .
.
├── serverspec
│ ├── prod_spec.rb
│ ├── shared_serverspec_tests
│ │ └── shared_tests2.rb
│ └── spec_helper.rb
└── shared_tests
└── shared_tests1.rb
This will allow you to write the following from within either prod_spec.rb
or qa_spec.rb
:
require 'spec_helper.rb'
require_relative '../shared_tests/shared_tests1.rb'
require_relative 'shared_serverspec_tests/shared_tests2.rb'
Inside shared_tests/shared_tests1.rb
require 'rspec' # You could require a spec_helper here - you just need to RSpec functionality to defined shared examples
require 'serverspec' # If you want to use serverspec matchers, you will need this too
RSpec.shared_examples "user examples" do
describe user('apache') do
it { should belong_to_group apache_group }
end
end
Inside your QA test:
require 'spec_helper.rb'
require_relative '../shared_tests/shared_tests1.rb'
describe "qa environment" do
let(:apache_group) { 'qa' }
include_examples "user examples"
end
And your prod test:
require 'spec_helper.rb'
require_relative '../shared_tests/shared_tests1.rb'
describe "qa environment" do
let(:apache_group) { 'prod' }
include_examples "user examples"
end