diff --git a/bin/haproxyctl b/bin/haproxyctl index 8c02286..2b0c010 100755 --- a/bin/haproxyctl +++ b/bin/haproxyctl @@ -114,7 +114,7 @@ begin printf "%-30s %-30s %-7s %3s\n", data[0], data[1], data[17], data[18] end when /disable all EXCEPT (.+)/ - servername = Regexp.last_match[ 1] + servername = Regexp.last_match(1) status = unixsock('show stat') backend = status.grep(/#{servername}/) backend.each do |line| @@ -127,7 +127,7 @@ begin end end when /disable all (.+)/ - servername = Regexp.last_match[ 1] + servername = Regexp.last_match(1) status = unixsock('show stat') status.each do |line| data = line.split(',') @@ -136,7 +136,7 @@ begin end end when /enable all EXCEPT (.+)/ - servername = Regexp.last_match[ 1] + servername = Regexp.last_match(1) status = unixsock('show stat') backend = status.grep(/#{servername}/) backend.each do |line| @@ -149,7 +149,7 @@ begin end end when /show stat (.+)/ - fieldnames = Regexp.last_match[ 1] + fieldnames = Regexp.last_match(1) status = unixsock('show stat') indices = fieldnames.split(' ').map do |name| status.first.split(',').index(name) || begin @@ -164,7 +164,7 @@ begin puts (row[0...2] + filtered).compact.join(',') end when /enable all (.+)/ - servername = Regexp.last_match[ 1] + servername = Regexp.last_match(1) status = unixsock('show stat') status.each do |line| data = line.split(',') diff --git a/lib/haproxyctl/environment.rb b/lib/haproxyctl/environment.rb index aee53fd..f591059 100644 --- a/lib/haproxyctl/environment.rb +++ b/lib/haproxyctl/environment.rb @@ -39,7 +39,7 @@ def exec def nbproc @nbproc ||= begin config.match /nbproc \s*(\d*)\s*/ - Regexp.last_match[1].to_i || 1 + Regexp.last_match(1).to_i || 1 end end @@ -54,13 +54,13 @@ def socket else config.match /stats\s+socket \s*([^\s]*)/ end - Regexp.last_match[1] || fail("Expecting 'stats socket ' in #{config_path}") + Regexp.last_match(1) || fail("Expecting 'stats socket ' in #{config_path}") end end def pidfile if config.match(/pidfile \s*([^\s]*)/) - @pidfile = Regexp.last_match[1] + @pidfile = Regexp.last_match(1) else std_pid = '/var/run/haproxy.pid' if File.exists?(std_pid) diff --git a/rhapr/lib/rhapr/environment.rb b/rhapr/lib/rhapr/environment.rb index c999f8a..efd1cab 100644 --- a/rhapr/lib/rhapr/environment.rb +++ b/rhapr/lib/rhapr/environment.rb @@ -71,7 +71,7 @@ def socket def socket_path @socket_path ||= begin config.match /stats\s+socket\s+([^\s]*)/ - Regexp.last_match[1] || fail(RuntimeError.new "Expecting 'stats socket ' in #{config_path}") + Regexp.last_match(1) || fail(RuntimeError.new "Expecting 'stats socket ' in #{config_path}") end end @@ -81,7 +81,7 @@ def socket_path def pid @pid ||= begin config.match /pidfile ([^\s]*)/ - Regexp.last_match[1] || '/var/run/haproxy.pid' + Regexp.last_match(1) || '/var/run/haproxy.pid' end end diff --git a/rhapr/lib/rhapr/interface.rb b/rhapr/lib/rhapr/interface.rb index 0acbd89..97b8f8c 100644 --- a/rhapr/lib/rhapr/interface.rb +++ b/rhapr/lib/rhapr/interface.rb @@ -68,7 +68,7 @@ def get_weight(backend, server) resp = send "get weight #{backend}/#{server}" resp.match /([[:digit:]]+) \(initial ([[:digit:]]+)\)/ - weight, initial = Regexp.last_match[1], Regexp.last_match[2] + weight, initial = Regexp.last_match(1), Regexp.last_match(2) return [weight.to_i, initial.to_i] if weight and initial diff --git a/rhapr/spec/rhapr/environment_spec.rb b/rhapr/spec/rhapr/environment_spec.rb index 09bec73..b2df1f3 100644 --- a/rhapr/spec/rhapr/environment_spec.rb +++ b/rhapr/spec/rhapr/environment_spec.rb @@ -20,14 +20,14 @@ class EnvTest end it 'should go down a list of pre-defined file names' do - File.stub!(:exists?).and_return(false) + File.stub(:exists?).and_return(false) File.should_receive(:exists?).with('/etc/haproxy.cfg').and_return(true) @env_test.config_path.should == '/etc/haproxy.cfg' end it 'should select the first configuration found, from the pre-defined list' do - File.stub!(:exists?).and_return(false) + File.stub(:exists?).and_return(false) File.should_receive(:exists?).with('/etc/haproxy/haproxy.cfg').and_return(true) File.should_receive(:exists?).with('/etc/haproxy.cfg').and_return(true) @@ -35,14 +35,14 @@ class EnvTest end it 'should be nil if config files do not exist and $HAPROXY_CONFIG is not set' do - File.stub!(:exists?).and_return(false) + File.stub(:exists?).and_return(false) @env_test.config_path.should be_nil end end describe '#config' do before(:each) do - File.stub!(:exists?).and_return(false) + File.stub(:exists?).and_return(false) File.should_receive(:exists?).with('/etc/haproxy.cfg').and_return(true) end @@ -55,7 +55,7 @@ class EnvTest end it 'should read and return the contents of a file' do - File.should_receive(:read).and_return { "I can haz cfg ?\n" } + File.should_receive(:read).and_return("I can haz cfg ?\n") @env_test.config.should == "I can haz cfg ?\n" end @@ -98,13 +98,13 @@ class EnvTest describe '#socket_path' do it 'should parse out the io socket from the config file' do - @env_test.should_receive(:config).and_return { config_for(:basic_haproxy) } + @env_test.should_receive(:config).and_return(config_for(:basic_haproxy)) @env_test.socket_path.should == '/tmp/haproxy' end it 'should raise an error if it cannot derive an io socket from the config file' do - @env_test.should_receive(:config).and_return { config_for(:crappy_haproxy) } + @env_test.should_receive(:config).and_return(config_for(:crappy_haproxy)) lambda do @env_test.socket_path @@ -114,19 +114,19 @@ class EnvTest describe '#pid' do it 'should parse out the pidfile from the config file' do - @env_test.should_receive(:config).and_return { config_for(:pid_test_haproxy) } + @env_test.should_receive(:config).and_return(config_for(:pid_test_haproxy)) @env_test.pid.should == '/some/other/run/haproxy.pid' end it 'should return a default path if it cannot derive an io socket from the config file' do - @env_test.should_receive(:config).and_return { config_for(:crappy_haproxy) } + @env_test.should_receive(:config).and_return(config_for(:crappy_haproxy)) @env_test.pid.should == '/var/run/haproxy.pid' end end describe '#check_running, #pidof' do - pending 'TBD' + skip 'TBD' end end diff --git a/rhapr/spec/rhapr/interface_spec.rb b/rhapr/spec/rhapr/interface_spec.rb index 3cb9550..8e548a8 100644 --- a/rhapr/spec/rhapr/interface_spec.rb +++ b/rhapr/spec/rhapr/interface_spec.rb @@ -22,7 +22,7 @@ it 'should send the "clear counters" message to HAProxy' do subject.should_receive(:send).with('clear counters').and_return("\n") - subject.clear_counters.should be_true + subject.clear_counters.should be true end end