require 'spec_helper' describe Puppet::Type.type(:service).provider(:freebsd) do before :each do @provider = subject() allow(@provider).to receive(:initscript) allow(Facter).to receive(:value).with(:osfamily).and_return('FreeBSD') end it "should correctly parse rcvar for FreeBSD < 7" do allow(@provider).to receive(:execute).and_return(<= 8.1" do allow(@provider).to receive(:execute).and_return(<= 7" do allow(@provider).to receive(:rcvar).and_return(['# ntpd', 'ntpd_enable="YES"', '# (default: "")']) expect(@provider.rcvar_value).to eq("YES") end it "should find the right rcvar_name" do allow(@provider).to receive(:rcvar).and_return(['# ntpd', 'ntpd_enable="YES"']) expect(@provider.rcvar_name).to eq("ntpd") end it "should enable only the selected service" do allow(Puppet::FileSystem).to receive(:exist?).with('/etc/rc.conf').and_return(true) allow(File).to receive(:read).with('/etc/rc.conf').and_return("openntpd_enable=\"NO\"\nntpd_enable=\"NO\"\n") fh = double('fh') allow(File).to receive(:open).with('/etc/rc.conf', File::WRONLY).and_yield(fh) expect(fh).to receive(:<<).with("openntpd_enable=\"NO\"\nntpd_enable=\"YES\"\n") allow(Puppet::FileSystem).to receive(:exist?).with('/etc/rc.conf.local').and_return(false) allow(Puppet::FileSystem).to receive(:exist?).with('/etc/rc.conf.d/ntpd').and_return(false) @provider.rc_replace('ntpd', 'ntpd', 'YES') end end