class PoiseService::SpecHelper::Helper
Not using Halite::HelperBase to avoid the dependency.
Public Class Methods
install()
click to toggle source
# File lib/poise_service/spec_helper/helper.rb, line 27 def self.install # Load and configure Serverspec. require 'serverspec' set :backend, :exec # Set up the shared example for poise_service_test. RSpec.shared_examples 'a poise_service_test' do |name, base_port, check_service=true| def json_http(uri) JSON.parse(Net::HTTP.get(URI(uri))) end describe 'default service' do describe service("poise_test_#{name}") do it { is_expected.to be_enabled } it { is_expected.to be_running } end if check_service describe 'process environment' do subject { json_http("http://localhost:#{base_port}/") } it { is_expected.to include({ 'user' => 'root', 'euser' => 'root', 'group' => 'root', 'egroup' => 'root', 'directory' => '/', }) } end end # /describe default service describe 'service with parameters' do describe service("poise_test_#{name}_params") do it { is_expected.to be_enabled } it { is_expected.to be_running } end if check_service describe 'process environment' do subject { json_http("http://localhost:#{base_port+1}/") } it { is_expected.to include({ 'user' => 'poise', 'euser' => 'poise', 'group' => 'poise', 'egroup' => 'poise', 'directory' => '/tmp', 'environment' => include({'POISE_ENV' => name}), }) } end end # /describe service with parameters describe 'noterm service' do describe service("poise_test_#{name}_noterm") do it { is_expected.to_not be_enabled } it { is_expected.to_not be_running } end if check_service describe 'process environment' do subject { json_http("http://localhost:#{base_port+2}/") } it { expect { subject }.to raise_error Errno::ECONNREFUSED } end end # /describe noterm service describe 'restart service' do describe service("poise_test_#{name}_restart") do it { is_expected.to be_enabled } it { is_expected.to be_running } end if check_service describe 'process environment' do subject { json_http("http://localhost:#{base_port+3}/") } it do is_expected.to include({ 'file_data' => 'second', }) end end end # /describe restart service describe 'reload service' do describe service("poise_test_#{name}_reload") do it { is_expected.to be_enabled } it { is_expected.to be_running } end if check_service describe 'process environment' do subject { json_http("http://localhost:#{base_port+4}/") } it do is_expected.to include({ 'file_data' => 'second', }) end end end # /describe reload service describe 'pid file' do subject { IO.read("/tmp/poise_test_#{name}_pid") } it { is_expected.to match /\d+/ } its(:to_i) { is_expected.to eq json_http("http://localhost:#{base_port}/")['pid'] } it { Process.kill(0, subject.to_i) } end # /describe pid file describe 'change service' do describe port(base_port+5) do it { is_expected.to_not be_listening } end describe port(base_port+6) do it { is_expected.to be_listening } end end # /describe change service end # /shared_examples a poise_service_test end
Public Instance Methods
json_http(uri)
click to toggle source
# File lib/poise_service/spec_helper/helper.rb, line 34 def json_http(uri) JSON.parse(Net::HTTP.get(URI(uri))) end