require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe 'CLI' do before do @plist_filename = File.expand_path('~/Library/LaunchAgents/com.buycheapviagraonlinenow.ruby__foo_rb.plist') end after do `launchctl unload -w #{@plist_filename}` if `launchctl list | grep ruby__foo_rb` =~ /ruby__foo.rb/ File.unlink(@plist_filename) if File.exists?(@plist_filename) end it 'should load/unload daemon-like agent' do command = File.expand_path(File.dirname(__FILE__) + '/../bin/launchagent --daemon --env FOO=BAR ruby foo.rb') system(command) File.exists?(@plist_filename).should be_true open(@plist_filename).read.should eql(< EnvironmentVariables FOO BAR KeepAlive SuccessfulExit Label com.buycheapviagraonlinenow.ruby__foo_rb ProgramArguments ruby foo.rb RunAtLoad PLIST (`launchctl list | grep ruby__foo_rb` =~ /ruby__foo.rb/).should_not be_nil system(command) File.exists?(@plist_filename).should be_false (`launchctl list | grep ruby__foo_rb` =~ /ruby__foo.rb/).should be_nil end it 'should load/unload periodic agent' do command = File.expand_path(File.dirname(__FILE__) + '/../bin/launchagent --interval 120 --env FOO=BAR ruby foo.rb') system(command) File.exists?(@plist_filename).should be_true open(@plist_filename).read.should eql(< EnvironmentVariables FOO BAR Label com.buycheapviagraonlinenow.ruby__foo_rb ProgramArguments ruby foo.rb StartInterval 120 PLIST (`launchctl list | grep ruby__foo_rb` =~ /ruby__foo.rb/).should_not be_nil system(command) File.exists?(@plist_filename).should be_false (`launchctl list | grep ruby__foo_rb` =~ /ruby__foo.rb/).should be_nil end end