Skip to content

Commit

Permalink
Ruby 3.2 compatibility (#119)
Browse files Browse the repository at this point in the history
* Replace `File.exists?` with `File.exist?`
* Upgrade rake and rspec
  • Loading branch information
malmckay authored Jan 5, 2023
1 parent eb98b8a commit 4ae276c
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 242 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- ubuntu-20.04
- macos-latest
ruby:
- '2.5'
Expand All @@ -30,6 +31,10 @@ jobs:
exclude:
- os: macos-latest
gcc: 7
- os: ubuntu-latest
gcc: 7
- os: ubuntu-20.04
gcc: latest

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.5.4
* Ruby 3.2 compatibility (h/t: @cheister & @EricRoos)

v1.5.3
* Ruby 3.1 compatibility (h/t: @casperisfine)

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ source 'https://rubygems.org'

gemspec

gem 'rake', '~> 0.9.0'
gem 'rake', '>= 13.0'

group :test do
gem "rspec" , "~> 2.11"
gem "rspec" , "~> 3.0"
gem 'eventmachine', '1.0.4'
gem 'evented-spec', '~> 0.9.0'
gem 'zk-server', '~> 1.0', :git => 'https://github.com/zk-ruby/zk-server.git'
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ release_ops_path = File.expand_path('../releaseops/lib', __FILE__)
# we use a submodule because it doesn't depend on anything else (*cough* bundler)
# and can be shared across projects
#
if File.exists?(release_ops_path)
if File.exist?(release_ops_path)
require File.join(release_ops_path, 'releaseops')

# sets up the multi-ruby zk:test_all rake tasks
Expand All @@ -17,7 +17,7 @@ if File.exists?(release_ops_path)
# Define a task to run code coverage tests
ReleaseOps::TestTasks.define_simplecov_tasks

# set up yard:server, yard:gems, and yard:clean tasks
# set up yard:server, yard:gems, and yard:clean tasks
# for doing documentation stuff
ReleaseOps::YardTasks.define

Expand Down
4 changes: 2 additions & 2 deletions ext/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ ZKRB_WRAPPER = %w[zkrb_wrapper.c zkrb_wrapper.h]

namespace :zkrb do
task :clean do
if File.exists?('Makefile')
if File.exist?('Makefile')
sh 'make clean'
rm 'Makefile' # yep, regenerate this
FileUtils.rm('Makefile') # yep, regenerate this
else
$stderr.puts "nothing to clean, no Makefile"
end
Expand Down
4 changes: 2 additions & 2 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def safe_sh(cmd)
else
puts "Building zkc."

unless File.exists?('c')
unless File.exist?('c')
safe_sh "tar xzf #{BUNDLE} 2>&1"
PATCHES.each do |patch|
safe_sh "patch -p0 < #{patch} 2>&1"
Expand Down Expand Up @@ -87,7 +87,7 @@ def safe_sh(cmd)
%w[a la dylib].each do |ext|
origin_lib_name = "libzookeeper_#{stmt}.#{ext}"
dest_lib_name = "libzookeeper_#{stmt}_gem.#{ext}"
system("cp -f #{origin_lib_name} #{dest_lib_name}") if File.exists?(origin_lib_name)
system("cp -f #{origin_lib_name} #{dest_lib_name}") if File.exist?(origin_lib_name)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zookeeper/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Zookeeper
VERSION = '1.5.3'
VERSION = '1.5.4'
DRIVER_VERSION = '3.4.5'
end
12 changes: 6 additions & 6 deletions spec/c_zookeeper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ def wait_until_connected(timeout=10)
end

it %[should be in connected state within a reasonable amount of time] do
wait_until_connected.should be_true
expect(wait_until_connected).to be_truthy
end

describe :after_connected do
before do
wait_until_connected.should be_true
expect(wait_until_connected).to be_truthy
end

it %[should have a connection event after being connected] do
event = wait_until(10) { @event_queue.pop }
event.should be
event[:req_id].should == Zookeeper::Constants::ZKRB_GLOBAL_CB_REQ
event[:type].should == Zookeeper::Constants::ZOO_SESSION_EVENT
event[:state].should == Zookeeper::Constants::ZOO_CONNECTED_STATE
expect(event).to be
expect(event[:req_id]).to eq(Zookeeper::Constants::ZKRB_GLOBAL_CB_REQ)
expect(event[:type]).to eq(Zookeeper::Constants::ZOO_SESSION_EVENT)
expect(event[:state]).to eq(Zookeeper::Constants::ZOO_CONNECTED_STATE)
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions spec/chrooted_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe 'Zookeeper chrooted' do
let(:path) { "/_zkchroottest_" }
let(:data) { "underpants" }
let(:data) { "underpants" }
let(:chroot_path) { '/slyphon-zookeeper-chroot' }

let(:connection_string) { "#{Zookeeper.default_cnx_str}#{chroot_path}" }
Expand Down Expand Up @@ -35,8 +35,8 @@ def zk

it %[should successfully create the path] do
rv = zk.create(:path => '/', :data => '')
rv[:rc].should be_zero
rv[:path].should == ''
expect(rv[:rc]).to be_zero
expect(rv[:path]).to eq('')
end
end
end
Expand All @@ -53,24 +53,24 @@ def zk

it %[should return ZNONODE] do
rv = zk.create(:path => '/', :data => '')
rv[:rc].should_not be_zero
rv[:rc].should == Zookeeper::Exceptions::ZNONODE
expect(rv[:rc]).not_to be_zero
expect(rv[:rc]).to eq(Zookeeper::Exceptions::ZNONODE)
end
end
end
end


describe do
before :all do
logger.warn "running before :all"
before :each do
logger.warn "running before :each"

with_open_zk do |z|
z.create(:path => chroot_path, :data => '')
end
end

after :all do
after :each do
with_open_zk do |z|
rm_rf(z, chroot_path)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/compatibilty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'Compatibiliy layer' do
it %[should raise the correct error when a const is missing] do
lambda { Zookeeper::THISISANINVALIDCONST }.should raise_error(NameError)
expect { Zookeeper::THISISANINVALIDCONST }.to raise_error(NameError)
end
end

12 changes: 6 additions & 6 deletions spec/default_watcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
describe :initialize, 'with watcher block' do
before do
@events = []
@watch_block = lambda do |hash|
@watch_block = lambda do |hash|
logger.debug "watch_block: #{hash.inspect}"
@events << hash
end

@zk = Zookeeper.new(Zookeeper.default_cnx_str, 10, @watch_block)

wait_until(2) { @zk.connected? }
@zk.should be_connected
expect(@zk).to be_connected
logger.debug "connected!"

wait_until(2) { !@events.empty? }
Expand All @@ -24,17 +24,17 @@
end

it %[should receive initial connection state events] do
@events.should_not be_empty
@events.length.should == 1
@events.first[:state].should == Zookeeper::ZOO_CONNECTED_STATE
expect(@events).not_to be_empty
expect(@events.length).to eq(1)
expect(@events.first[:state]).to eq(Zookeeper::ZOO_CONNECTED_STATE)
end

it %[should receive disconnection events] do
pending "the C driver doesn't appear to deliver disconnection events (?)"
@events.clear
@zk.close
wait_until(2) { !@events.empty? }
@events.should_not be_empty
expect(@events).not_to be_empty
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/em_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setup_zk
end

def teardown_and_done
@zk.close do
@zk.close do
logger.debug { "TEST: about to call done" }
EM.next_tick do
done
Expand All @@ -31,15 +31,15 @@ def teardown_and_done
describe 'callbacks' do
it %[should be called on the reactor thread] do
cb = lambda do |h|
EM.reactor_thread?.should be_true
expect(EM.reactor_thread?).to be_truthy
logger.debug { "called back on the reactor thread? #{EM.reactor_thread?}" }
teardown_and_done
end

setup_zk do
@zk.on_attached do |*|
logger.debug { "on_attached called" }
rv = @zk.get(:path => '/', :callback => cb)
rv = @zk.get(:path => '/', :callback => cb)
logger.debug { "rv from @zk.get: #{rv.inspect}" }
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ext/zookeeper_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

it %[should have an original_pid assigned] do
@zk.original_pid.should == Process.pid
expect(@zk.original_pid).to eq(Process.pid)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/forked_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def wait_for_child_safely(pid, timeout=5)
status = wait_for_child_safely(@pid)
raise "Child process did not exit, likely hung" unless status

status.should_not be_signaled
status.should be_success
expect(status).not_to be_signaled
expect(status).to be_success

event_waiter_th.join(5).should == event_waiter_th
@event.should_not be_nil
expect(event_waiter_th.join(5)).to eq(event_waiter_th)
expect(@event).not_to be_nil
end
end
end
2 changes: 1 addition & 1 deletion spec/latch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

other_latch.await
th.join(1).should == th
expect(th.join(1)).to eq(th)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/shared/all_success_return_values.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
shared_examples_for "all success return values" do
it %[should have a return code of Zookeeper::ZOK] do
@rv[:rc].should == Zookeeper::ZOK
expect(@rv[:rc]).to eq(Zookeeper::ZOK)
end

it %[should have a req_id integer] do
@rv[:req_id].should be_kind_of(Integer)
expect(@rv[:req_id]).to be_kind_of(Integer)
end
end

Loading

0 comments on commit 4ae276c

Please sign in to comment.