diff --git a/Gemfile b/Gemfile index 1eff8ad9f..48e5858ae 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ group :development do end group :testing do - gem 'rspec', '~> 2.14.1' + gem 'rspec', '~> 3.0.0' gem 'simplecov', '~> 0.8.2', :require => false gem 'coveralls', '~> 0.7.0', :require => false gem 'timecop', '~> 0.7.1' diff --git a/spec/concurrent/actress_spec.rb b/spec/concurrent/actress_spec.rb index 2dfe6a681..939d75443 100644 --- a/spec/concurrent/actress_spec.rb +++ b/spec/concurrent/actress_spec.rb @@ -67,23 +67,23 @@ def on_message(message) actor = Ping.spawn :ping, queue # when spawn returns children are set - Concurrent::Actress.root.send(:core).instance_variable_get(:@children).should include(actor) + expect(Concurrent::Actress.root.send(:core).instance_variable_get(:@children)).to include(actor) actor << 'a' << 1 - queue.pop.should eq 'a' - actor.ask(2).value.should eq 2 + expect(queue.pop).to eq 'a' + expect(actor.ask(2).value).to eq 2 - actor.parent.should eq Concurrent::Actress.root - Concurrent::Actress.root.path.should eq '/' - actor.path.should eq '/ping' + expect(actor.parent).to eq Concurrent::Actress.root + expect(Concurrent::Actress.root.path).to eq '/' + expect(actor.path).to eq '/ping' child = actor.ask(:child).value - child.path.should eq '/ping/pong' + expect(child.path).to eq '/ping/pong' queue.clear child.ask(3) - queue.pop.should eq 3 + expect(queue.pop).to eq 3 actor << :terminate - actor.ask(:blow_up).wait.should be_rejected + expect(actor.ask(:blow_up).wait).to be_rejected terminate_actors actor, child end end @@ -102,15 +102,31 @@ def on_message(message) subjects.each do |desc, subject_definition| describe desc do - subject &subject_definition - after { terminate_actors subject } - its(:path) { should eq '/ping' } - its(:parent) { pending('intermittent JRuby deadlock'); should eq Actress.root } - its(:name) { should eq 'ping' } - it('executor should be global') { subject.executor.should eq Concurrent.configuration.global_task_pool } - its(:reference) { should eq subject } + subject(:actor, &subject_definition) + after { terminate_actors actor } + + describe '#path' do + subject { super().path } + it { is_expected.to eq '/ping' } + end + + describe '#parent' do + subject { super().parent } + it { is_expected.to eq Actress.root } + end + + describe '#name' do + subject { super().name } + it { is_expected.to eq 'ping' } + end + it('executor should be global') { expect(subject.executor).to eq Concurrent.configuration.global_task_pool } + + describe '#reference' do + subject { super().reference } + it { is_expected.to eq subject } + end it 'returns arg' do - subject.ask!(:anything).should eq 'arg' + expect(subject.ask!(:anything)).to eq 'arg' end end end @@ -118,8 +134,8 @@ def on_message(message) it 'terminates on failed initialization' do a = AdHoc.spawn(name: :fail, logger: Concurrent.configuration.no_logger) { raise } - a.ask(nil).wait.rejected?.should be_true - a.terminated?.should be_true + expect(a.ask(nil).wait.rejected?).to be_truthy + expect(a.terminated?).to be_truthy end it 'terminates on failed initialization and raises with spawn!' do @@ -130,8 +146,8 @@ def on_message(message) it 'terminates on failed message processing' do a = AdHoc.spawn(name: :fail, logger: Concurrent.configuration.no_logger) { -> _ { raise } } - a.ask(nil).wait.rejected?.should be_true - a.terminated?.should be_true + expect(a.ask(nil).wait.rejected?).to be_truthy + expect(a.terminated?).to be_truthy end end @@ -140,7 +156,7 @@ def on_message(message) specify do subject.tell(1).tell(1) subject << 1 << 1 - subject.ask(0).value!.should eq 4 + expect(subject.ask(0).value!).to eq 4 end after { terminate_actors subject } end @@ -160,8 +176,8 @@ def on_message(message) it 'has children set after a child is created' do child = parent.ask!(:child) - parent.ask!(nil).should include(child) - child.ask!(nil).should eq parent + expect(parent.ask!(nil)).to include(child) + expect(child.ask!(nil)).to eq parent terminate_actors parent, child end @@ -171,11 +187,11 @@ def on_message(message) subject { AdHoc.spawn(:subject) { -> _ { envelope } } } specify do envelope = subject.ask!('a') - envelope.should be_a_kind_of Envelope - envelope.message.should eq 'a' - envelope.ivar.should be_completed - envelope.ivar.value.should eq envelope - envelope.sender.should eq Thread.current + expect(envelope).to be_a_kind_of Envelope + expect(envelope.message).to eq 'a' + expect(envelope.ivar).to be_completed + expect(envelope.ivar.value).to eq envelope + expect(envelope.sender).to eq Thread.current terminate_actors subject end end @@ -196,11 +212,11 @@ def on_message(message) it 'terminates with all its children' do child = subject.ask! :child - subject.terminated?.should be_false + expect(subject.terminated?).to be_falsey subject.ask(:terminate).wait - subject.terminated?.should be_true + expect(subject.terminated?).to be_truthy child.terminated.wait - child.terminated?.should be_true + expect(child.terminated?).to be_truthy terminate_actors subject, child end diff --git a/spec/concurrent/agent_spec.rb b/spec/concurrent/agent_spec.rb index d8b5af7ff..2948f471b 100644 --- a/spec/concurrent/agent_spec.rb +++ b/spec/concurrent/agent_spec.rb @@ -26,7 +26,7 @@ module Concurrent subject.post { |v| v + 2 } subject.post_off { |v| v * 3 } subject.await - subject.value.should eq 12 + expect(subject.value).to eq 12 end end @@ -68,37 +68,37 @@ def trigger_observable(observable) let(:executor) { ImmediateExecutor.new } it 'sets the value to the given initial state' do - Agent.new(10).value.should eq 10 + expect(Agent.new(10).value).to eq 10 end it 'sets the timeout to the given value' do - Agent.new(0, timeout: 5).timeout.should eq 5 + expect(Agent.new(0, timeout: 5).timeout).to eq 5 end it 'sets the timeout to the default when nil' do - Agent.new(0).timeout.should eq Agent::TIMEOUT + expect(Agent.new(0).timeout).to eq Agent::TIMEOUT end it 'uses the executor given with the :executor option' do - executor.should_receive(:post).with(any_args).and_return(0) + expect(executor).to receive(:post).with(any_args).and_return(0) agent = Agent.new(0, executor: executor) agent.post { |value| 0 } end it 'uses the global operation pool when :operation is true' do - Concurrent.configuration.should_receive(:global_operation_pool).and_return(executor) + expect(Concurrent.configuration).to receive(:global_operation_pool).and_return(executor) agent = Agent.new(0, operation: true) agent.post { |value| 0 } end it 'uses the global task pool when :task is true' do - Concurrent.configuration.should_receive(:global_task_pool).and_return(executor) + expect(Concurrent.configuration).to receive(:global_task_pool).and_return(executor) agent = Agent.new(0, task: true) agent.post { |value| 0 } end it 'uses the global task pool by default' do - Concurrent.configuration.should_receive(:global_task_pool).and_return(executor) + expect(Concurrent.configuration).to receive(:global_task_pool).and_return(executor) agent = Agent.new(0) agent.post { |value| 0 } end @@ -110,25 +110,25 @@ def trigger_observable(observable) a1 = subject a2 = a1.rescue {} - a2.should be a1 + expect(a2).to be a1 end it 'returns self when no block is given' do a1 = subject a2 = a1.rescue - a2.should be a1 + expect(a2).to be a1 end it 'accepts an exception class as the first parameter' do - lambda { + expect { subject.rescue(StandardError) {} - }.should_not raise_error + }.not_to raise_error end it 'ignores rescuers without a block' do subject.rescue - subject.instance_variable_get(:@rescuers).should be_empty + expect(subject.instance_variable_get(:@rescuers)).to be_empty end end @@ -138,39 +138,39 @@ def trigger_observable(observable) a1 = subject a2 = a1.validate {} - a2.should be a1 + expect(a2).to be a1 end it 'returns self when no block is given' do a1 = subject a2 = a1.validate - a2.should be a1 + expect(a2).to be a1 end it 'ignores validators without a block' do default_validator = subject.instance_variable_get(:@validator) subject.validate - subject.instance_variable_get(:@validator).should be default_validator + expect(subject.instance_variable_get(:@validator)).to be default_validator end end context '#post' do it 'adds the given block to the queue' do - executor.should_receive(:post).with(no_args).exactly(1).times + expect(executor).to receive(:post).with(no_args).exactly(1).times subject.post { sleep(1) } subject.post { nil } subject.post { nil } sleep(0.1) - subject. + expect(subject. instance_variable_get(:@serialized_execution). instance_variable_get(:@stash). - size.should eq 2 + size).to eq 2 end it 'does not add to the queue when no block is given' do - executor.should_receive(:post).with(no_args).exactly(0).times + expect(executor).to receive(:post).with(no_args).exactly(0).times subject.post sleep(0.1) end @@ -179,7 +179,7 @@ def trigger_observable(observable) agent = Agent.new(0, executor: ImmediateExecutor.new) agent.post { |old| old + 1 } agent.post { |old| old + 1 } - agent.value.should eq 2 + expect(agent.value).to eq 2 end end @@ -190,20 +190,20 @@ def trigger_observable(observable) fn = false subject.post { fn = true; sleep 0.1 } subject.await - fn.should be_true + expect(fn).to be_truthy end it 'does not waits until updates sent after are done' do fn = false subject.await subject.post { fn = true; sleep 0.1 } - fn.should be_false + expect(fn).to be_falsey end it 'does not alter the value' do subject.post { |v| v + 1 } subject.await - subject.value.should eq 1 + expect(subject.value).to eq 1 end end @@ -215,7 +215,7 @@ def trigger_observable(observable) subject.post { latch.count_down } subject.post { latch.count_down } subject.post { latch.count_down } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'passes the current value to the handler' do @@ -223,21 +223,21 @@ def trigger_observable(observable) Agent.new(latch.count, executor: executor).post do |i| i.times{ latch.count_down } end - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'sets the value to the handler return value on success' do agent = Agent.new(10, executor: Concurrent::ImmediateExecutor.new) - agent.value.should eq 10 + expect(agent.value).to eq 10 agent.post { 100 } - agent.value.should eq 100 + expect(agent.value).to eq 100 end it 'rejects the handler after timeout reached' do agent = Agent.new(0, timeout: 0.1, executor: executor) agent.post { sleep(1); 10 } sleep(0.2) - agent.value.should eq 0 + expect(agent.value).to eq 0 end end @@ -247,7 +247,7 @@ def trigger_observable(observable) latch = Concurrent::CountDownLatch.new(1) subject.validate { latch.count_down; true } subject.post { nil } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'passes the new value to the validator' do @@ -256,25 +256,25 @@ def trigger_observable(observable) subject.validate { |v| expected.value = v; latch.count_down; true } subject.post { 10 } latch.wait(1) - expected.value.should eq 10 + expect(expected.value).to eq 10 end it 'sets the new value when the validator returns true' do agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new).validate { true } agent.post { 10 } - agent.value.should eq 10 + expect(agent.value).to eq 10 end it 'does not change the value when the validator returns false' do agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new).validate { false } agent.post { 10 } - agent.value.should eq 0 + expect(agent.value).to eq 0 end it 'does not change the value when the validator raises an exception' do agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new).validate { raise StandardError } agent.post { 10 } - agent.value.should eq 0 + expect(agent.value).to eq 0 end end @@ -287,7 +287,7 @@ def trigger_observable(observable) rescue(StandardError) { |ex| expected = 2 }. rescue(StandardError) { |ex| expected = 3 } agent.post { raise StandardError } - expected.should eq 1 + expect(expected).to eq 1 end it 'matches all with a rescue with no class given' do @@ -297,7 +297,7 @@ def trigger_observable(observable) rescue { |ex| expected = 2 }. rescue(StandardError) { |ex| expected = 3 } agent.post { raise NoMethodError } - expected.should eq 2 + expect(expected).to eq 2 end it 'searches associated rescue handlers in order' do @@ -307,7 +307,7 @@ def trigger_observable(observable) rescue(LoadError) { |ex| expected = 2 }. rescue(StandardError) { |ex| expected = 3 } agent.post { raise ArgumentError } - expected.should eq 1 + expect(expected).to eq 1 expected = nil agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new). @@ -315,7 +315,7 @@ def trigger_observable(observable) rescue(LoadError) { |ex| expected = 2 }. rescue(StandardError) { |ex| expected = 3 } agent.post { raise LoadError } - expected.should eq 2 + expect(expected).to eq 2 expected = nil agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new). @@ -323,7 +323,7 @@ def trigger_observable(observable) rescue(LoadError) { |ex| expected = 2 }. rescue(StandardError) { |ex| expected = 3 } agent.post { raise StandardError } - expected.should eq 3 + expect(expected).to eq 3 end it 'passes the exception object to the matched block' do @@ -333,7 +333,7 @@ def trigger_observable(observable) rescue(LoadError) { |ex| expected = ex }. rescue(StandardError) { |ex| expected = ex } agent.post { raise StandardError } - expected.should be_a(StandardError) + expect(expected).to be_a(StandardError) end it 'ignores rescuers without a block' do @@ -342,24 +342,24 @@ def trigger_observable(observable) rescue(StandardError). rescue(StandardError) { |ex| expected = ex } agent.post { raise StandardError } - expected.should be_a(StandardError) + expect(expected).to be_a(StandardError) end it 'supresses the exception if no rescue matches' do - lambda { + expect { agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new). rescue(ArgumentError) { |ex| @expected = ex }. rescue(NotImplementedError) { |ex| @expected = ex }. rescue(NoMethodError) { |ex| @expected = ex } agent.post { raise StandardError } - }.should_not raise_error + }.not_to raise_error end it 'suppresses exceptions thrown from rescue handlers' do - lambda { + expect { agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new).rescue(StandardError) { raise StandardError } agent.post { raise ArgumentError } - }.should_not raise_error + }.not_to raise_error end end @@ -369,7 +369,7 @@ def trigger_observable(observable) agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new) agent.add_observer(observer) agent.post { 10 } - observer.value.should eq 10 + expect(observer.value).to eq 10 end it 'does not notify removed observers when the value changes' do @@ -377,7 +377,7 @@ def trigger_observable(observable) agent.add_observer(observer) agent.delete_observer(observer) agent.post { 10 } - observer.value.should be_nil + expect(observer.value).to be_nil end it 'does not notify observers when validation fails' do @@ -385,14 +385,14 @@ def trigger_observable(observable) agent.validate { false } agent.add_observer(observer) agent.post { 10 } - observer.value.should be_nil + expect(observer.value).to be_nil end it 'does not notify observers when the handler raises an exception' do agent = Agent.new(0, executor: Concurrent::ImmediateExecutor.new) agent.add_observer(observer) agent.post { raise StandardError } - observer.value.should be_nil + expect(observer.value).to be_nil end end @@ -402,7 +402,7 @@ def trigger_observable(observable) agent = Agent.new(0, executor: executor) agent.post { |old| old + continue.value } sleep 0.1 - Concurrent.timeout(0.2) { agent.value.should eq 0 } + Concurrent.timeout(0.2) { expect(agent.value).to eq 0 } continue.set 1 sleep 0.1 end @@ -416,21 +416,21 @@ def trigger_observable(observable) agent.post { |old| f2 = true; old + continue2.value } sleep 0.1 - f1.should eq true - f2.should eq false - agent.value.should eq 0 + expect(f1).to eq true + expect(f2).to eq false + expect(agent.value).to eq 0 continue1.set 1 sleep 0.1 - f1.should eq true - f2.should eq true - agent.value.should eq 1 + expect(f1).to eq true + expect(f2).to eq true + expect(agent.value).to eq 1 continue2.set 1 sleep 0.1 - f1.should eq true - f2.should eq true - agent.value.should eq 2 + expect(f1).to eq true + expect(f2).to eq true + expect(agent.value).to eq 2 end it 'waits with sending functions to other agents until update is done' @@ -439,28 +439,28 @@ def trigger_observable(observable) context 'aliases' do it 'aliases #deref for #value' do - Agent.new(10, executor: executor).deref.should eq 10 + expect(Agent.new(10, executor: executor).deref).to eq 10 end it 'aliases #validates for :validate' do latch = Concurrent::CountDownLatch.new(1) subject.validates { latch.count_down; true } subject.post { nil } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'aliases #validate_with for :validate' do latch = Concurrent::CountDownLatch.new(1) subject.validate_with { latch.count_down; true } subject.post { nil } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'aliases #validates_with for :validate' do latch = Concurrent::CountDownLatch.new(1) subject.validates_with { latch.count_down; true } subject.post { nil } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'aliases #catch for #rescue' do @@ -468,7 +468,7 @@ def trigger_observable(observable) expected = nil agent.catch { expected = true } agent.post { raise StandardError } - agent.should be_true + expect(agent).to be_truthy end it 'aliases #on_error for #rescue' do @@ -476,7 +476,7 @@ def trigger_observable(observable) expected = nil agent.on_error { expected = true } agent.post { raise StandardError } - agent.should be_true + expect(agent).to be_truthy end end end diff --git a/spec/concurrent/async_spec.rb b/spec/concurrent/async_spec.rb index 4ace2086e..ad2dbdb03 100644 --- a/spec/concurrent/async_spec.rb +++ b/spec/concurrent/async_spec.rb @@ -106,7 +106,7 @@ def many(*args, &block) nil; end context 'executor' do it 'returns the default executor when #executor= has never been called' do - Concurrent.configuration.should_receive(:global_operation_pool). + expect(Concurrent.configuration).to receive(:global_operation_pool). and_return(ImmediateExecutor.new) subject = async_class.new subject.async.echo(:foo) @@ -114,7 +114,7 @@ def many(*args, &block) nil; end it 'returns the memo after #executor= has been called' do executor = ImmediateExecutor.new - executor.should_receive(:post) + expect(executor).to receive(:post) subject = async_class.new subject.executor = executor subject.async.echo(:foo) @@ -152,13 +152,13 @@ def many(*args, &block) nil; end it 'returns a :pending IVar' do val = subject.async.wait(5) - val.should be_a Concurrent::IVar - val.should be_pending + expect(val).to be_a Concurrent::IVar + expect(val).to be_pending end it 'runs the future on the memoized executor' do executor = ImmediateExecutor.new - executor.should_receive(:post).with(any_args) + expect(executor).to receive(:post).with(any_args) subject = async_class.new subject.executor = executor subject.async.echo(:foo) @@ -166,23 +166,23 @@ def many(*args, &block) nil; end it 'sets the value on success' do val = subject.async.echo(:foo) - val.value.should eq :foo - val.should be_fulfilled + expect(val.value).to eq :foo + expect(val).to be_fulfilled end it 'sets the reason on failure' do ex = ArgumentError.new val = subject.async.boom(ex) sleep(0.1) - val.reason.should eq ex - val.should be_rejected + expect(val.reason).to eq ex + expect(val).to be_rejected end it 'sets the reason when giving too many optional arguments' do val = subject.async.gather(1, 2, 3, 4, 5) sleep(0.1) - val.reason.should be_a StandardError - val.should be_rejected + expect(val.reason).to be_a StandardError + expect(val).to be_rejected end it 'supports attribute accessors' do @@ -190,19 +190,19 @@ def many(*args, &block) nil; end sleep(0.1) val = subject.async.accessor sleep(0.1) - val.value.should eq :foo - subject.accessor.should eq :foo + expect(val.value).to eq :foo + expect(subject.accessor).to eq :foo end it 'supports methods with blocks' do val = subject.async.with_block{ :foo } sleep(0.1) - val.value.should eq :foo + expect(val.value).to eq :foo end it 'is aliased as #future' do val = subject.future.wait(5) - val.should be_a Concurrent::IVar + expect(val).to be_a Concurrent::IVar end context '#method_missing' do @@ -244,44 +244,44 @@ def many(*args, &block) nil; end it 'returns a :fulfilled IVar' do val = subject.await.echo(5) - val.should be_a Concurrent::IVar - val.should be_fulfilled + expect(val).to be_a Concurrent::IVar + expect(val).to be_fulfilled end it 'sets the value on success' do val = subject.await.echo(:foo) - val.value.should eq :foo - val.should be_fulfilled + expect(val.value).to eq :foo + expect(val).to be_fulfilled end it 'sets the reason on failure' do ex = ArgumentError.new val = subject.await.boom(ex) - val.reason.should eq ex - val.should be_rejected + expect(val.reason).to eq ex + expect(val).to be_rejected end it 'sets the reason when giving too many optional arguments' do val = subject.await.gather(1, 2, 3, 4, 5) - val.reason.should be_a StandardError - val.should be_rejected + expect(val.reason).to be_a StandardError + expect(val).to be_rejected end it 'supports attribute accessors' do subject.await.accessor = :foo val = subject.await.accessor - val.value.should eq :foo - subject.accessor.should eq :foo + expect(val.value).to eq :foo + expect(subject.accessor).to eq :foo end it 'supports methods with blocks' do val = subject.await.with_block{ :foo } - val.value.should eq :foo + expect(val.value).to eq :foo end it 'is aliased as #delay' do val = subject.delay.echo(5) - val.should be_a Concurrent::IVar + expect(val).to be_a Concurrent::IVar end context '#method_missing' do @@ -316,7 +316,7 @@ def gather(seconds, first, *rest) object.async.gather(0.5, :a, :b) object.await.gather(0, :c, :d) - object.bucket.should eq [:a, :b, :c, :d] + expect(object.bucket).to eq [:a, :b, :c, :d] end context 'raises an InitializationError' do diff --git a/spec/concurrent/atomic/atomic_boolean_spec.rb b/spec/concurrent/atomic/atomic_boolean_spec.rb index d87b71e86..f83582ba2 100644 --- a/spec/concurrent/atomic/atomic_boolean_spec.rb +++ b/spec/concurrent/atomic/atomic_boolean_spec.rb @@ -1,23 +1,23 @@ require 'spec_helper' -share_examples_for :atomic_boolean do +shared_examples :atomic_boolean do describe 'construction' do it 'sets the initial value' do - described_class.new(true).value.should be_true + expect(described_class.new(true).value).to be_truthy end it 'defaults the initial value to false' do - described_class.new.value.should be_false + expect(described_class.new.value).to be_falsey end it 'evaluates the truthiness of a true value' do - described_class.new(10).value.should be_true + expect(described_class.new(10).value).to be_truthy end it 'evaluates the truthiness of a false value' do - described_class.new(nil).value.should be_false + expect(described_class.new(nil).value).to be_falsey end end @@ -25,11 +25,11 @@ it 'returns the current value' do counter = described_class.new(true) - counter.value.should be_true + expect(counter.value).to be_truthy counter.make_false - counter.value.should be_false + expect(counter.value).to be_falsey counter.make_true - counter.value.should be_true + expect(counter.value).to be_truthy end end @@ -38,53 +38,53 @@ it 'sets the #value to the given `Boolean`' do atomic = described_class.new(true) atomic.value = false - atomic.value.should be_false + expect(atomic.value).to be_falsey end it 'returns the new value' do atomic = described_class.new(false) - (atomic.value = true).should be_true + expect(atomic.value = true).to be_truthy end it 'evaluates the truthiness of a true value' do atomic = described_class.new(false) atomic.value = 10 - atomic.value.should be_true + expect(atomic.value).to be_truthy end it 'evaluates the truthiness of a false value' do atomic = described_class.new(true) atomic.value = nil - atomic.value.should be_false + expect(atomic.value).to be_falsey end end describe '#true?' do - specify { described_class.new(true).true?.should be_true } + specify { expect(described_class.new(true).true?).to be_truthy } - specify { described_class.new(false).true?.should be_false } + specify { expect(described_class.new(false).true?).to be_falsey } end describe '#false?' do - specify { described_class.new(true).false?.should be_false } + specify { expect(described_class.new(true).false?).to be_falsey } - specify { described_class.new(false).false?.should be_true } + specify { expect(described_class.new(false).false?).to be_truthy } end describe '#make_true' do it 'makes a false value true and returns true' do subject = described_class.new(false) - subject.make_true.should be_true - subject.value.should be_true + expect(subject.make_true).to be_truthy + expect(subject.value).to be_truthy end it 'keeps a true value true and returns false' do subject = described_class.new(true) - subject.make_true.should be_false - subject.value.should be_true + expect(subject.make_true).to be_falsey + expect(subject.value).to be_truthy end end @@ -92,14 +92,14 @@ it 'makes a true value false and returns true' do subject = described_class.new(true) - subject.make_false.should be_true - subject.value.should be_false + expect(subject.make_false).to be_truthy + expect(subject.value).to be_falsey end it 'keeps a false value false and returns false' do subject = described_class.new(false) - subject.make_false.should be_false - subject.value.should be_false + expect(subject.make_false).to be_falsey + expect(subject.value).to be_falsey end end end @@ -112,7 +112,7 @@ module Concurrent specify 'construction is synchronized' do mutex = double('mutex') - Mutex.should_receive(:new).once.with(no_args).and_return(mutex) + expect(Mutex).to receive(:new).once.with(no_args).and_return(mutex) described_class.new end @@ -120,9 +120,9 @@ module Concurrent before(:each) do mutex = double('mutex') - Mutex.stub(:new).with(no_args).and_return(mutex) - mutex.should_receive(:lock) - mutex.should_receive(:unlock) + allow(Mutex).to receive(:new).with(no_args).and_return(mutex) + expect(mutex).to receive(:lock) + expect(mutex).to receive(:unlock) end specify 'value is synchronized' do @@ -161,11 +161,11 @@ module Concurrent describe AtomicBoolean do if jruby? it 'inherits from JavaAtomicBoolean' do - AtomicBoolean.ancestors.should include(JavaAtomicBoolean) + expect(AtomicBoolean.ancestors).to include(JavaAtomicBoolean) end else it 'inherits from MutexAtomicBoolean' do - AtomicBoolean.ancestors.should include(MutexAtomicBoolean) + expect(AtomicBoolean.ancestors).to include(MutexAtomicBoolean) end end end diff --git a/spec/concurrent/atomic/atomic_fixnum_spec.rb b/spec/concurrent/atomic/atomic_fixnum_spec.rb index 282175ece..389791190 100644 --- a/spec/concurrent/atomic/atomic_fixnum_spec.rb +++ b/spec/concurrent/atomic/atomic_fixnum_spec.rb @@ -1,21 +1,21 @@ require 'spec_helper' -share_examples_for :atomic_fixnum do +shared_examples :atomic_fixnum do context 'construction' do it 'sets the initial value' do - described_class.new(10).value.should eq 10 + expect(described_class.new(10).value).to eq 10 end it 'defaults the initial value to zero' do - described_class.new.value.should eq 0 + expect(described_class.new.value).to eq 0 end it 'raises en exception if the initial value is not a Fixnum' do - lambda { + expect { described_class.new(10.01) - }.should raise_error + }.to raise_error end end @@ -23,11 +23,11 @@ it 'returns the current value' do counter = described_class.new(10) - counter.value.should eq 10 + expect(counter.value).to eq 10 counter.increment - counter.value.should eq 11 + expect(counter.value).to eq 11 counter.decrement - counter.value.should eq 10 + expect(counter.value).to eq 10 end end @@ -36,12 +36,12 @@ it 'sets the #value to the given `Fixnum`' do atomic = described_class.new(0) atomic.value = 10 - atomic.value.should eq 10 + expect(atomic.value).to eq 10 end it 'returns the new value' do atomic = described_class.new(0) - (atomic.value = 10).should eq 10 + expect(atomic.value = 10).to eq 10 end it 'raises and exception if the value is not a `Fixnum`' do @@ -57,16 +57,16 @@ it 'increases the value by one' do counter = described_class.new(10) 3.times{ counter.increment } - counter.value.should eq 13 + expect(counter.value).to eq 13 end it 'returns the new value' do counter = described_class.new(10) - counter.increment.should eq 11 + expect(counter.increment).to eq 11 end it 'is aliased as #up' do - described_class.new(10).up.should eq 11 + expect(described_class.new(10).up).to eq 11 end end @@ -75,39 +75,39 @@ it 'decreases the value by one' do counter = described_class.new(10) 3.times{ counter.decrement } - counter.value.should eq 7 + expect(counter.value).to eq 7 end it 'returns the new value' do counter = described_class.new(10) - counter.decrement.should eq 9 + expect(counter.decrement).to eq 9 end it 'is aliased as #down' do - described_class.new(10).down.should eq 9 + expect(described_class.new(10).down).to eq 9 end end context '#compare_and_set' do it 'returns false if the value is not found' do - described_class.new(14).compare_and_set(2, 14).should eq false + expect(described_class.new(14).compare_and_set(2, 14)).to eq false end it 'returns true if the value is found' do - described_class.new(14).compare_and_set(14, 2).should eq true + expect(described_class.new(14).compare_and_set(14, 2)).to eq true end it 'sets if the value is found' do f = described_class.new(14) f.compare_and_set(14, 2) - f.value.should eq 2 + expect(f.value).to eq 2 end it 'does not set if the value is not found' do f = described_class.new(14) f.compare_and_set(2, 12) - f.value.should eq 14 + expect(f.value).to eq 14 end end end @@ -120,47 +120,47 @@ module Concurrent specify 'construction is synchronized' do mutex = double('mutex') - Mutex.should_receive(:new).once.with(no_args).and_return(mutex) + expect(Mutex).to receive(:new).once.with(no_args).and_return(mutex) described_class.new end specify 'value is synchronized' do mutex = double('mutex') - Mutex.stub(:new).with(no_args).and_return(mutex) - mutex.should_receive(:lock) - mutex.should_receive(:unlock) + allow(Mutex).to receive(:new).with(no_args).and_return(mutex) + expect(mutex).to receive(:lock) + expect(mutex).to receive(:unlock) described_class.new.value end specify 'value= is synchronized' do mutex = double('mutex') - Mutex.stub(:new).with(no_args).and_return(mutex) - mutex.should_receive(:lock) - mutex.should_receive(:unlock) + allow(Mutex).to receive(:new).with(no_args).and_return(mutex) + expect(mutex).to receive(:lock) + expect(mutex).to receive(:unlock) described_class.new.value = 10 end specify 'increment is synchronized' do mutex = double('mutex') - Mutex.stub(:new).with(no_args).and_return(mutex) - mutex.should_receive(:lock) - mutex.should_receive(:unlock) + allow(Mutex).to receive(:new).with(no_args).and_return(mutex) + expect(mutex).to receive(:lock) + expect(mutex).to receive(:unlock) described_class.new.increment end specify 'decrement is synchronized' do mutex = double('mutex') - Mutex.stub(:new).with(no_args).and_return(mutex) - mutex.should_receive(:lock) - mutex.should_receive(:unlock) + allow(Mutex).to receive(:new).with(no_args).and_return(mutex) + expect(mutex).to receive(:lock) + expect(mutex).to receive(:unlock) described_class.new.decrement end specify 'compare_and_set is synchronized' do mutex = double('mutex') - Mutex.stub(:new).with(no_args).and_return(mutex) - mutex.should_receive(:lock) - mutex.should_receive(:unlock) + allow(Mutex).to receive(:new).with(no_args).and_return(mutex) + expect(mutex).to receive(:lock) + expect(mutex).to receive(:unlock) described_class.new(14).compare_and_set(14, 2) end end @@ -175,11 +175,11 @@ module Concurrent describe AtomicFixnum do if jruby? it 'inherits from JavaAtomicFixnum' do - AtomicFixnum.ancestors.should include(JavaAtomicFixnum) + expect(AtomicFixnum.ancestors).to include(JavaAtomicFixnum) end else it 'inherits from MutexAtomicFixnum' do - AtomicFixnum.ancestors.should include(MutexAtomicFixnum) + expect(AtomicFixnum.ancestors).to include(MutexAtomicFixnum) end end end diff --git a/spec/concurrent/atomic/condition_spec.rb b/spec/concurrent/atomic/condition_spec.rb index 247ad504f..be42185ef 100644 --- a/spec/concurrent/atomic/condition_spec.rb +++ b/spec/concurrent/atomic/condition_spec.rb @@ -16,13 +16,13 @@ module Concurrent context 'with no waiting threads' do describe '#signal' do it 'should return immediately' do - subject.signal.should be_true + expect(subject.signal).to be_truthy end end describe '#broadcast' do it 'should return immediately' do - subject.broadcast.should be_true + expect(subject.broadcast).to be_truthy end end end @@ -36,7 +36,7 @@ module Concurrent it 'should block the thread' do t = Thread.new { mutex.synchronize { subject.wait(mutex) } } sleep(0.1) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' t.kill end @@ -46,10 +46,10 @@ module Concurrent sleep(0.1) mutex.synchronize { subject.signal } sleep(0.1) - result.should be_woken_up - result.should_not be_timed_out - result.remaining_time.should be_nil - t.status.should be_false + expect(result).to be_woken_up + expect(result).not_to be_timed_out + expect(result.remaining_time).to be_nil + expect(t.status).to be_falsey end it 'should return a woken up result when is woken up by #broadcast' do @@ -58,10 +58,10 @@ module Concurrent sleep(0.1) mutex.synchronize { subject.broadcast } sleep(0.1) - result.should be_woken_up - result.should_not be_timed_out - result.remaining_time.should be_nil - t.status.should be_false + expect(result).to be_woken_up + expect(result).not_to be_timed_out + expect(result.remaining_time).to be_nil + expect(t.status).to be_falsey end end @@ -74,7 +74,7 @@ module Concurrent it 'should block the thread' do t = Thread.new { mutex.synchronize { subject.wait(mutex, 1) } } sleep(0.1) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' t.kill end @@ -84,10 +84,10 @@ module Concurrent sleep(0.1) mutex.synchronize { subject.signal } sleep(0.1) - result.should be_woken_up - result.should_not be_timed_out - result.remaining_time.should be_within(0.1).of(0.85) - t.status.should be_false + expect(result).to be_woken_up + expect(result).not_to be_timed_out + expect(result.remaining_time).to be_within(0.1).of(0.85) + expect(t.status).to be_falsey end it 'should return remaining time when is woken up by #broadcast' do @@ -96,20 +96,20 @@ module Concurrent sleep(0.1) mutex.synchronize { subject.broadcast } sleep(0.1) - result.should be_woken_up - result.should_not be_timed_out - result.remaining_time.should be_within(0.1).of(0.85) - t.status.should be_false + expect(result).to be_woken_up + expect(result).not_to be_timed_out + expect(result.remaining_time).to be_within(0.1).of(0.85) + expect(t.status).to be_falsey end it 'should return 0 or negative number if timed out' do result = nil t = Thread.new { mutex.synchronize { result = subject.wait(mutex, 0.1) } } sleep(0.2) - result.should_not be_woken_up - result.should be_timed_out - result.remaining_time.should be_less_than_or_equal_to(0) - t.status.should be_false + expect(result).not_to be_woken_up + expect(result).to be_timed_out + expect(result.remaining_time).to be_less_than_or_equal_to(0) + expect(t.status).to be_falsey end end @@ -126,7 +126,7 @@ module Concurrent t1 = Thread.new { mutex.synchronize { subject.wait(mutex) } } t2 = Thread.new { mutex.synchronize { subject.wait(mutex) } } sleep(0.1) - [t1, t2].each { |t| t.status.should eq 'sleep' } + [t1, t2].each { |t| expect(t.status).to eq 'sleep' } [t1, t2].each { |t| t.kill } end @@ -143,7 +143,7 @@ module Concurrent mutex.synchronize { subject.signal } sleep(0.2) - latch.count.should eq 1 + expect(latch.count).to eq 1 [t1, t2].each { |t| t.kill } end end @@ -159,7 +159,7 @@ module Concurrent mutex.synchronize { subject.broadcast } sleep(0.2) - latch.count.should eq 0 + expect(latch.count).to eq 0 [t1, t2].each { |t| t.kill } end end diff --git a/spec/concurrent/atomic/count_down_latch_spec.rb b/spec/concurrent/atomic/count_down_latch_spec.rb index 8e3a58607..c9f52162b 100644 --- a/spec/concurrent/atomic/count_down_latch_spec.rb +++ b/spec/concurrent/atomic/count_down_latch_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -share_examples_for :count_down_latch do +shared_examples :count_down_latch do let(:latch) { described_class.new(3) } let(:zero_count_latch) { described_class.new(0) } @@ -23,17 +23,17 @@ describe '#count' do it 'should be the value passed to the constructor' do - latch.count.should eq 3 + expect(latch.count).to eq 3 end it 'should be decreased after every count down' do latch.count_down - latch.count.should eq 2 + expect(latch.count).to eq 2 end it 'should not go below zero' do 5.times { latch.count_down } - latch.count.should eq 0 + expect(latch.count).to eq 0 end end @@ -42,12 +42,12 @@ context 'count set to zero' do it 'should return true immediately' do result = zero_count_latch.wait - result.should be_true + expect(result).to be_truthy end it 'should return true immediately with timeout' do result = zero_count_latch.wait(5) - result.should be_true + expect(result).to be_truthy end end @@ -59,8 +59,8 @@ end result = latch.wait - result.should be_true - latch.count.should eq 0 + expect(result).to be_truthy + expect(latch.count).to eq 0 end it 'should block until counter is set to zero with timeout' do @@ -69,15 +69,15 @@ end result = latch.wait(1) - result.should be_true - latch.count.should eq 0 + expect(result).to be_truthy + expect(latch.count).to eq 0 end it 'should block until timeout and return false when counter is not set to zero' do result = latch.wait(0.1) - result.should be_false - latch.count.should eq 3 + expect(result).to be_falsey + expect(latch.count).to eq 3 end end end @@ -110,7 +110,7 @@ def subject.simulate_spurious_wake_up subject.simulate_spurious_wake_up sleep(0.1) - @expected.should be_false + expect(@expected).to be_falsey end it 'should resist to spurious wake ups with timeout' do @@ -121,10 +121,10 @@ def subject.simulate_spurious_wake_up subject.simulate_spurious_wake_up sleep(0.1) - @expected.should be_false + expect(@expected).to be_falsey sleep(0.4) - @expected.should be_true + expect(@expected).to be_truthy end end end @@ -140,11 +140,11 @@ def subject.simulate_spurious_wake_up describe CountDownLatch do if jruby? it 'inherits from JavaCountDownLatch' do - CountDownLatch.ancestors.should include(JavaCountDownLatch) + expect(CountDownLatch.ancestors).to include(JavaCountDownLatch) end else it 'inherits from MutexCountDownLatch' do - CountDownLatch.ancestors.should include(MutexCountDownLatch) + expect(CountDownLatch.ancestors).to include(MutexCountDownLatch) end end end diff --git a/spec/concurrent/atomic/cyclic_barrier_spec.rb b/spec/concurrent/atomic/cyclic_barrier_spec.rb index 3cd47d661..787d144bf 100644 --- a/spec/concurrent/atomic/cyclic_barrier_spec.rb +++ b/spec/concurrent/atomic/cyclic_barrier_spec.rb @@ -25,7 +25,7 @@ module Concurrent describe '#parties' do it 'should be the value passed to the constructor' do - barrier.parties.should eq 3 + expect(barrier.parties).to eq 3 end end @@ -33,7 +33,7 @@ module Concurrent describe '#number_waiting' do context 'without any waiting thread' do it 'should be equal to zero' do - barrier.number_waiting.should eq 0 + expect(barrier.number_waiting).to eq 0 end end @@ -44,19 +44,19 @@ module Concurrent sleep(0.1) - barrier.number_waiting.should eq 2 + expect(barrier.number_waiting).to eq 2 end end end describe '#broken?' do it 'should not be broken when created' do - barrier.broken?.should eq false + expect(barrier.broken?).to eq false end it 'should not be broken when reset is called without waiting thread' do barrier.reset - barrier.broken?.should eq false + expect(barrier.broken?).to eq false end end @@ -67,10 +67,10 @@ module Concurrent Thread.new { barrier.wait; latch.count_down } sleep(0.1) barrier.reset - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy - barrier.should_not be_broken - barrier.number_waiting.should eq 0 + expect(barrier).not_to be_broken + expect(barrier.number_waiting).to eq 0 end end @@ -80,23 +80,23 @@ module Concurrent t = Thread.new { barrier.wait } sleep(0.1) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end it 'should release all threads when their number matches the desired one' do latch = CountDownLatch.new(parties) parties.times { Thread.new { barrier.wait; latch.count_down } } - latch.wait(0.1).should be_true - barrier.number_waiting.should eq 0 - barrier.should_not be_broken + expect(latch.wait(0.1)).to be_truthy + expect(barrier.number_waiting).to eq 0 + expect(barrier).not_to be_broken end it 'returns true when released' do latch = CountDownLatch.new(parties) parties.times { Thread.new { latch.count_down if barrier.wait == true } } - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy end it 'executes the block once' do @@ -106,19 +106,19 @@ module Concurrent latch = CountDownLatch.new(parties) parties.times { Thread.new { latch.count_down if barrier.wait == true } } - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy - counter.value.should eq 1 + expect(counter.value).to eq 1 end it 'can be reused' do first_latch = CountDownLatch.new(parties) parties.times { Thread.new { barrier.wait; first_latch.count_down } } - first_latch.wait(0.1).should be_true + expect(first_latch.wait(0.1)).to be_truthy latch = CountDownLatch.new(parties) parties.times { Thread.new { barrier.wait; latch.count_down } } - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy end it 'return false if barrier has been reset' do @@ -127,7 +127,7 @@ module Concurrent Thread.new { latch.count_down if barrier.wait == false } sleep(0.1) barrier.reset - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy end end @@ -137,22 +137,22 @@ module Concurrent t = Thread.new { barrier.wait(1) } sleep(0.1) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end it 'should release all threads when their number matches the desired one' do latch = CountDownLatch.new(parties) parties.times { Thread.new { barrier.wait(1); latch.count_down } } - latch.wait(0.2).should be_true - barrier.number_waiting.should eq 0 + expect(latch.wait(0.2)).to be_truthy + expect(barrier.number_waiting).to eq 0 end it 'returns true when released' do latch = CountDownLatch.new(parties) parties.times { Thread.new { latch.count_down if barrier.wait(1) == true } } - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy end end @@ -162,7 +162,7 @@ module Concurrent latch = CountDownLatch.new(1) Thread.new { latch.count_down if barrier.wait(0.1) == false } - latch.wait(0.2).should be_true + expect(latch.wait(0.2)).to be_truthy end it 'breaks the barrier and release all other threads' do @@ -171,8 +171,8 @@ module Concurrent Thread.new { barrier.wait(0.1); latch.count_down } Thread.new { barrier.wait; latch.count_down } - latch.wait(0.2).should be_true - barrier.should be_broken + expect(latch.wait(0.2)).to be_truthy + expect(barrier).to be_broken end it 'does not execute the block on timeout' do @@ -181,7 +181,7 @@ module Concurrent barrier.wait(0.1) - counter.value.should eq 0 + expect(counter.value).to eq 0 end end end @@ -191,20 +191,20 @@ module Concurrent Thread.new { barrier.wait(0.1) } sleep(0.2) - barrier.should be_broken + expect(barrier).to be_broken - barrier.wait.should be_false + expect(barrier.wait).to be_falsey end it 'can be reset' do Thread.new { barrier.wait(0.1) } sleep(0.2) - barrier.should be_broken + expect(barrier).to be_broken barrier.reset - barrier.should_not be_broken + expect(barrier).not_to be_broken end end end @@ -228,7 +228,7 @@ def barrier.simulate_spurious_wake_up barrier.simulate_spurious_wake_up sleep(0.1) - @expected.should be_false + expect(@expected).to be_falsey end it 'should resist to spurious wake ups with timeout' do @@ -239,7 +239,7 @@ def barrier.simulate_spurious_wake_up barrier.simulate_spurious_wake_up sleep(0.1) - @expected.should be_false + expect(@expected).to be_falsey end end diff --git a/spec/concurrent/atomic/event_spec.rb b/spec/concurrent/atomic/event_spec.rb index 3eae3c610..34d0deb38 100644 --- a/spec/concurrent/atomic/event_spec.rb +++ b/spec/concurrent/atomic/event_spec.rb @@ -9,7 +9,7 @@ module Concurrent context '#initialize' do it 'sets the state to unset' do - subject.should_not be_set + expect(subject).not_to be_set end end @@ -17,11 +17,11 @@ module Concurrent it 'returns true when the event has been set' do subject.set - subject.should be_set + expect(subject).to be_set end it 'returns false if the event is unset' do - subject.should_not be_set + expect(subject).not_to be_set end end @@ -32,12 +32,12 @@ module Concurrent Thread.new{ subject.wait.tap{ latch.count_down } } sleep(0.1) subject.set - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'sets the state to set' do subject.set - subject.should be_set + expect(subject).to be_set end end @@ -45,16 +45,16 @@ module Concurrent it 'triggers the event if not already set' do subject.try? - subject.should be_set + expect(subject).to be_set end it 'returns true if not previously set' do - subject.try?.should be_true + expect(subject.try?).to be_truthy end it 'returns false if previously set' do subject.set - subject.try?.should be_false + expect(subject.try?).to be_falsey end end @@ -62,40 +62,40 @@ module Concurrent it 'does not change the state of an unset event' do subject.reset - subject.should_not be_set + expect(subject).not_to be_set end it 'does not trigger an unset event' do latch = CountDownLatch.new(1) Thread.new{ subject.wait.tap{ latch.count_down } } subject.reset - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey end it 'does not interrupt waiting threads when event is unset' do latch = CountDownLatch.new(1) Thread.new{ subject.wait.tap{ latch.count_down } } subject.reset - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey subject.set - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy end it 'returns true when called on an unset event' do - subject.reset.should be_true + expect(subject.reset).to be_truthy end it 'sets the state of a set event to unset' do subject.set - subject.should be_set + expect(subject).to be_set subject.reset - subject.should_not be_set + expect(subject).not_to be_set end it 'returns true when called on a set event' do subject.set - subject.should be_set - subject.reset.should be_true + expect(subject).to be_set + expect(subject.reset).to be_truthy end end @@ -133,34 +133,34 @@ module Concurrent latch = CountDownLatch.new(1) subject.set Thread.new{ subject.wait(1000); latch.count_down } - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy end it 'returns true once the event is set' do subject.set - subject.wait.should be_true + expect(subject.wait).to be_truthy end it 'blocks indefinitely when the timer is nil' do subject.reset latch = CountDownLatch.new(1) Thread.new{ subject.wait.tap{ latch.count_down } } - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey subject.set - latch.wait(0.1).should be_true + expect(latch.wait(0.1)).to be_truthy end it 'stops waiting when the timer expires' do subject.reset latch = CountDownLatch.new(1) Thread.new{ subject.wait(0.2); latch.count_down } - latch.wait(0.1).should be_false - latch.wait.should be_true + expect(latch.wait(0.1)).to be_falsey + expect(latch.wait).to be_truthy end it 'returns false when the timer expires' do subject.reset - subject.wait(1).should be_false + expect(subject.wait(1)).to be_falsey end it 'triggers multiple waiting threads' do @@ -168,7 +168,7 @@ module Concurrent subject.reset 5.times{ Thread.new{ subject.wait; latch.count_down } } subject.set - latch.wait(0.2).should be_true + expect(latch.wait(0.2)).to be_truthy end it 'behaves appropriately if wait begins while #set is processing' do @@ -177,7 +177,7 @@ module Concurrent 5.times{ Thread.new{ subject.wait(5) } } subject.set 5.times{ Thread.new{ subject.wait; latch.count_down } } - latch.wait(0.2).should be_true + expect(latch.wait(0.2)).to be_truthy end end @@ -199,7 +199,7 @@ def subject.simulate_spurious_wake_up sleep(0.1) subject.simulate_spurious_wake_up - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey end it 'should resist to spurious wake ups with timeout' do @@ -209,8 +209,8 @@ def subject.simulate_spurious_wake_up sleep(0.1) subject.simulate_spurious_wake_up - latch.wait(0.1).should be_false - latch.wait(1).should be_true + expect(latch.wait(0.1)).to be_falsey + expect(latch.wait(1)).to be_truthy end end end diff --git a/spec/concurrent/atomic/observer_set_shared.rb b/spec/concurrent/atomic/observer_set_shared.rb index eb55ef82d..f8beed948 100644 --- a/spec/concurrent/atomic/observer_set_shared.rb +++ b/spec/concurrent/atomic/observer_set_shared.rb @@ -10,21 +10,21 @@ context 'with arguments' do it 'should return the observer' do - observer_set.add_observer(observer, :a_method).should == observer + expect(observer_set.add_observer(observer, :a_method)).to eq(observer) end end context 'with a block' do it 'should return the observer based on a block' do observer = observer_set.add_observer { :block } - observer.call.should == :block + expect(observer.call).to eq(:block) end end end describe '#notify_observers' do it 'should return the observer set' do - observer_set.notify_observers.should be(observer_set) + expect(observer_set.notify_observers).to be(observer_set) end context 'with a single observer' do @@ -97,8 +97,8 @@ context 'with a block' do before(:each) do - observer.stub(:update).with(any_args) - another_observer.stub(:update).with(any_args) + allow(observer).to receive(:update).with(any_args) + allow(another_observer).to receive(:update).with(any_args) end it 'calls the block once for every observer' do @@ -146,12 +146,12 @@ context '#count_observers' do it 'should be zero after initialization' do - observer_set.count_observers.should eq 0 + expect(observer_set.count_observers).to eq 0 end it 'should be 1 after the first observer is added' do observer_set.add_observer(observer) - observer_set.count_observers.should eq 1 + expect(observer_set.count_observers).to eq 1 end it 'should be 1 if the same observer is added many times' do @@ -159,7 +159,7 @@ observer_set.add_observer(observer, :another_method) observer_set.add_observer(observer, :yet_another_method) - observer_set.count_observers.should eq 1 + expect(observer_set.count_observers).to eq 1 end it 'should be equal to the number of unique observers' do @@ -168,7 +168,7 @@ observer_set.add_observer(double('observer 3')) observer_set.add_observer(double('observer 4')) - observer_set.count_observers.should eq 4 + expect(observer_set.count_observers).to eq 4 end end @@ -187,7 +187,7 @@ end it 'should return the observer' do - observer_set.delete_observer(observer).should be(observer) + expect(observer_set.delete_observer(observer)).to be(observer) end end @@ -205,7 +205,7 @@ end it 'should return the observer set' do - observer_set.delete_observers.should be(observer_set) + expect(observer_set.delete_observers).to be(observer_set) end end @@ -225,7 +225,7 @@ it 'should clear observers' do observer_set.notify_and_delete_observers('args') - observer_set.count_observers.should eq(0) + expect(observer_set.count_observers).to eq(0) end it 'can be called many times without any other notification' do @@ -235,7 +235,7 @@ end it 'should return the observer set' do - observer_set.notify_and_delete_observers('args').should be(observer_set) + expect(observer_set.notify_and_delete_observers('args')).to be(observer_set) end end diff --git a/spec/concurrent/atomic/thread_local_var_spec.rb b/spec/concurrent/atomic/thread_local_var_spec.rb index 2e65c7b77..ebd40ee26 100644 --- a/spec/concurrent/atomic/thread_local_var_spec.rb +++ b/spec/concurrent/atomic/thread_local_var_spec.rb @@ -11,33 +11,33 @@ module Concurrent it 'can set an initial value' do v = ThreadLocalVar.new(14) - v.value.should eq 14 + expect(v.value).to eq 14 end it 'sets nil as a default initial value' do v = ThreadLocalVar.new - v.value.should be_nil + expect(v.value).to be_nil end it 'sets the same initial value for all threads' do v = ThreadLocalVar.new(14) t1 = Thread.new { v.value } t2 = Thread.new { v.value } - t1.value.should eq 14 - t2.value.should eq 14 + expect(t1.value).to eq 14 + expect(t2.value).to eq 14 end if jruby? it 'uses ThreadLocalJavaStorage' do - subject.class.ancestors.should include(Concurrent::ThreadLocalJavaStorage) + expect(subject.class.ancestors).to include(Concurrent::ThreadLocalJavaStorage) end elsif rbx? || RbConfig::CONFIG['ruby_version'] =~ /^1\.9/ it 'uses ThreadLocalOldStorage' do - subject.class.ancestors.should include(Concurrent::ThreadLocalOldStorage) + expect(subject.class.ancestors).to include(Concurrent::ThreadLocalOldStorage) end else it 'uses ThreadLocalNewStorage' do - subject.class.ancestors.should include(Concurrent::ThreadLocalNewStorage) + expect(subject.class.ancestors).to include(Concurrent::ThreadLocalNewStorage) end end end @@ -46,13 +46,13 @@ module Concurrent it 'returns the current value' do v = ThreadLocalVar.new(14) - v.value.should eq 14 + expect(v.value).to eq 14 end it 'returns the value after modification' do v = ThreadLocalVar.new(14) v.value = 2 - v.value.should eq 2 + expect(v.value).to eq 2 end end @@ -62,19 +62,19 @@ module Concurrent it 'sets a new value' do v = ThreadLocalVar.new(14) v.value = 2 - v.value.should eq 2 + expect(v.value).to eq 2 end it 'returns the new value' do v = ThreadLocalVar.new(14) - (v.value = 2).should eq 2 + expect(v.value = 2).to eq 2 end it 'does not modify the initial value for other threads' do v = ThreadLocalVar.new(14) v.value = 2 t = Thread.new { v.value } - t.value.should eq 14 + expect(t.value).to eq 14 end it 'does not modify the value for other threads' do @@ -102,8 +102,8 @@ module Concurrent v.value end - t1.value.should eq 1 - t2.value.should eq 2 + expect(t1.value).to eq 1 + expect(t2.value).to eq 2 end end diff --git a/spec/concurrent/atomic_spec.rb b/spec/concurrent/atomic_spec.rb index 3ab3bbe20..c98a49ecd 100644 --- a/spec/concurrent/atomic_spec.rb +++ b/spec/concurrent/atomic_spec.rb @@ -1,20 +1,20 @@ require 'spec_helper' -share_examples_for :atomic do +shared_examples :atomic do specify :test_construct do atomic = described_class.new - atomic.value.should be_nil + expect(atomic.value).to be_nil atomic = described_class.new(0) - atomic.value.should eq 0 + expect(atomic.value).to eq 0 end specify :test_value do atomic = described_class.new(0) atomic.value = 1 - atomic.value.should eq 1 + expect(atomic.value).to eq 1 end specify :test_update do @@ -22,8 +22,8 @@ atomic = described_class.new(1000) res = atomic.update {|v| v + 1} - atomic.value.should eq 1001 - res.should eq 1001 + expect(atomic.value).to eq 1001 + expect(res).to eq 1001 end specify :test_try_update do @@ -31,16 +31,16 @@ atomic = described_class.new(1000) res = atomic.try_update {|v| v + 1} - atomic.value.should eq 1001 - res.should eq 1001 + expect(atomic.value).to eq 1001 + expect(res).to eq 1001 end specify :test_swap do atomic = described_class.new(1000) res = atomic.swap(1001) - atomic.value.should eq 1001 - res.should eq 1000 + expect(atomic.value).to eq 1001 + expect(res).to eq 1000 end specify :test_try_update_fails do @@ -59,7 +59,7 @@ # assigning within block exploits implementation detail for test atomic.update{|v| tries += 1 ; atomic.value = 1001 ; v + 1} - tries.should eq 2 + expect(tries).to eq 2 end specify :test_numeric_cas do @@ -71,12 +71,12 @@ atomic.set(max_8) max_8.upto(max_8 + 2) do |i| - atomic.compare_and_swap(i, i+1).should be_true, "CAS failed for numeric #{i} => #{i + 1}" + expect(atomic.compare_and_swap(i, i+1)).to be_truthy, "CAS failed for numeric #{i} => #{i + 1}" end atomic.set(min_8) min_8.downto(min_8 - 2) do |i| - atomic.compare_and_swap(i, i-1).should be_true, "CAS failed for numeric #{i} => #{i - 1}" + expect(atomic.compare_and_swap(i, i-1)).to be_truthy, "CAS failed for numeric #{i} => #{i - 1}" end # 64-bit idempotent Fixnum (MRI, Rubinius) @@ -85,12 +85,12 @@ atomic.set(max_64) max_64.upto(max_64 + 2) do |i| - atomic.compare_and_swap(i, i+1).should be_true, "CAS failed for numeric #{i} => #{i + 1}" + expect(atomic.compare_and_swap(i, i+1)).to be_truthy, "CAS failed for numeric #{i} => #{i + 1}" end atomic.set(min_64) min_64.downto(min_64 - 2) do |i| - atomic.compare_and_swap(i, i-1).should be_true, "CAS failed for numeric #{i} => #{i - 1}" + expect(atomic.compare_and_swap(i, i-1)).to be_truthy, "CAS failed for numeric #{i} => #{i - 1}" end ## 64-bit overflow into Bignum (JRuby) @@ -99,31 +99,31 @@ atomic.set(max_64) max_64.upto(max_64 + 2) do |i| - atomic.compare_and_swap(i, i+1).should be_true, "CAS failed for numeric #{i} => #{i + 1}" + expect(atomic.compare_and_swap(i, i+1)).to be_truthy, "CAS failed for numeric #{i} => #{i + 1}" end atomic.set(min_64) min_64.downto(min_64 - 2) do |i| - atomic.compare_and_swap(i, i-1).should be_true, "CAS failed for numeric #{i} => #{i - 1}" + expect(atomic.compare_and_swap(i, i-1)).to be_truthy, "CAS failed for numeric #{i} => #{i - 1}" end # non-idempotent Float (JRuby, Rubinius, MRI < 2.0.0 or 32-bit) atomic.set(1.0 + 0.1) - atomic.compare_and_set(1.0 + 0.1, 1.2).should be_true, "CAS failed for #{1.0 + 0.1} => 1.2" + expect(atomic.compare_and_set(1.0 + 0.1, 1.2)).to be_truthy, "CAS failed for #{1.0 + 0.1} => 1.2" # Bignum atomic.set(2**100) - atomic.compare_and_set(2**100, 0).should be_true, "CAS failed for #{2**100} => 0" + expect(atomic.compare_and_set(2**100, 0)).to be_truthy, "CAS failed for #{2**100} => 0" # Rational require 'rational' unless ''.respond_to? :to_r atomic.set(Rational(1,3)) - atomic.compare_and_set(Rational(1,3), 0).should be_true, "CAS failed for #{Rational(1,3)} => 0" + expect(atomic.compare_and_set(Rational(1,3), 0)).to be_truthy, "CAS failed for #{Rational(1,3)} => 0" # Complex require 'complex' unless ''.respond_to? :to_c atomic.set(Complex(1,2)) - atomic.compare_and_set(Complex(1,2), 0).should be_true, "CAS failed for #{Complex(1,2)} => 0" + expect(atomic.compare_and_set(Complex(1,2), 0)).to be_truthy, "CAS failed for #{Complex(1,2)} => 0" end end @@ -154,19 +154,19 @@ module Concurrent describe Atomic do if TestHelpers.use_c_extensions? it 'inherits from CAtomic' do - Atomic.ancestors.should include(CAtomic) + expect(Atomic.ancestors).to include(CAtomic) end elsif TestHelpers.jruby? it 'inherits from JavaAtomic' do - Atomic.ancestors.should include(JavaAtomic) + expect(Atomic.ancestors).to include(JavaAtomic) end elsif TestHelpers.rbx? it 'inherits from RbxAtomic' do - Atomic.ancestors.should include(RbxAtomic) + expect(Atomic.ancestors).to include(RbxAtomic) end else it 'inherits from MutexAtomic' do - Atomic.ancestors.should include(MutexAtomic) + expect(Atomic.ancestors).to include(MutexAtomic) end end end diff --git a/spec/concurrent/channel/buffered_channel_spec.rb b/spec/concurrent/channel/buffered_channel_spec.rb index 916e6387f..b246e577e 100644 --- a/spec/concurrent/channel/buffered_channel_spec.rb +++ b/spec/concurrent/channel/buffered_channel_spec.rb @@ -12,12 +12,12 @@ module Concurrent describe '#push' do it 'adds elements to buffer' do - channel.buffer_queue_size.should be 0 + expect(channel.buffer_queue_size).to be 0 channel.push('a') channel.push('a') - channel.buffer_queue_size.should be 2 + expect(channel.buffer_queue_size).to be 2 end it 'should block when buffer is full' do @@ -26,7 +26,7 @@ module Concurrent t = Thread.new { channel.push 3 } sleep(0.05) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end it 'restarts thread when buffer is no more full' do @@ -43,13 +43,13 @@ module Concurrent sleep(0.1) - result.should eq 42 + expect(result).to eq 42 end it 'should assign value to a probe if probe set is not empty' do channel.select(probe) Thread.new { sleep(0.1); channel.push 3 } - probe.value.should eq 3 + expect(probe.value).to eq 3 end end @@ -57,22 +57,22 @@ module Concurrent it 'should block if buffer is empty' do t = Thread.new { channel.pop } sleep(0.05) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end it 'returns value if buffer is not empty' do channel.push 1 result = channel.pop - result.should eq 1 + expect(result).to eq 1 end it 'removes the first value from the buffer' do channel.push 'a' channel.push 'b' - channel.pop.should eq 'a' - channel.buffer_queue_size.should eq 1 + expect(channel.pop).to eq 'a' + expect(channel.buffer_queue_size).to eq 1 end end @@ -85,7 +85,7 @@ module Concurrent sleep(0.05) - t.status.should eq false + expect(t.status).to eq false end it 'gets notified by writer thread' do @@ -93,7 +93,7 @@ module Concurrent Thread.new { channel.push 82 } - probe.value.should eq 82 + expect(probe.value).to eq 82 end end @@ -107,8 +107,8 @@ module Concurrent channel.push 27 - channel.buffer_queue_size.should eq 1 - channel.probe_set_size.should eq 0 + expect(channel.buffer_queue_size).to eq 1 + expect(channel.probe_set_size).to eq 0 end end @@ -120,9 +120,9 @@ module Concurrent channel.select(probe) - channel.buffer_queue_size.should eq 1 + expect(channel.buffer_queue_size).to eq 1 - channel.pop.should eq 82 + expect(channel.pop).to eq 82 end end @@ -131,18 +131,18 @@ module Concurrent describe 'probe set' do it 'has size zero after creation' do - channel.probe_set_size.should eq 0 + expect(channel.probe_set_size).to eq 0 end it 'increases size after a select' do channel.select(probe) - channel.probe_set_size.should eq 1 + expect(channel.probe_set_size).to eq 1 end it 'decreases size after a removal' do channel.select(probe) channel.remove_probe(probe) - channel.probe_set_size.should eq 0 + expect(channel.probe_set_size).to eq 0 end end diff --git a/spec/concurrent/channel/channel_spec.rb b/spec/concurrent/channel/channel_spec.rb index 22a749e62..596773708 100644 --- a/spec/concurrent/channel/channel_spec.rb +++ b/spec/concurrent/channel/channel_spec.rb @@ -14,20 +14,20 @@ module Concurrent value, channel = Channel.select(*channels) - value.should eq 77 - channel.should be channels[1] + expect(value).to eq 77 + expect(channel).to be channels[1] end it 'cleans up' do channels = [ UnbufferedChannel.new, UnbufferedChannel.new] - channels.each { |ch| ch.stub(:remove_probe).with( an_instance_of(Channel::Probe) )} + channels.each { |ch| allow(ch).to receive(:remove_probe).with( an_instance_of(Channel::Probe) )} Thread.new { channels[1].push 77 } value, channel = Channel.select(*channels) - value.should eq 77 - channel.should be channels[1] + expect(value).to eq 77 + expect(channel).to be channels[1] channels.each { |ch| expect(ch).to have_received(:remove_probe).with( an_instance_of(Channel::Probe) ) } end diff --git a/spec/concurrent/channel/probe_spec.rb b/spec/concurrent/channel/probe_spec.rb index c282c5410..eab220c84 100644 --- a/spec/concurrent/channel/probe_spec.rb +++ b/spec/concurrent/channel/probe_spec.rb @@ -25,16 +25,16 @@ def trigger_observable(observable) context 'empty probe' do it 'assigns the value' do probe.set_unless_assigned(32, channel) - probe.value.should eq 32 + expect(probe.value).to eq 32 end it 'assign the channel' do probe.set_unless_assigned(32, channel) - probe.channel.should be channel + expect(probe.channel).to be channel end it 'returns true' do - probe.set_unless_assigned('hi', channel).should eq true + expect(probe.set_unless_assigned('hi', channel)).to eq true end end @@ -43,11 +43,11 @@ def trigger_observable(observable) it 'does not assign the value' do probe.set_unless_assigned(88, channel) - probe.value.should eq 27 + expect(probe.value).to eq 27 end it 'returns false' do - probe.set_unless_assigned('hello', channel).should eq false + expect(probe.set_unless_assigned('hello', channel)).to eq false end end @@ -56,19 +56,19 @@ def trigger_observable(observable) it 'does not assign the value' do probe.set_unless_assigned(88, channel) - probe.should be_rejected + expect(probe).to be_rejected end it 'has a nil value' do - probe.value.should be_nil + expect(probe.value).to be_nil end it 'has a nil channel' do - probe.channel.should be_nil + expect(probe.channel).to be_nil end it 'returns false' do - probe.set_unless_assigned('hello', channel).should eq false + expect(probe.set_unless_assigned('hello', channel)).to eq false end end end diff --git a/spec/concurrent/channel/unbuffered_channel_spec.rb b/spec/concurrent/channel/unbuffered_channel_spec.rb index fafb39aef..c9d803230 100644 --- a/spec/concurrent/channel/unbuffered_channel_spec.rb +++ b/spec/concurrent/channel/unbuffered_channel_spec.rb @@ -15,7 +15,7 @@ module Concurrent it 'should block' do t = Thread.new { channel.push 5 } sleep(0.05) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end end @@ -23,7 +23,7 @@ module Concurrent it 'should block' do t = Thread.new { channel.pop } sleep(0.05) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end end @@ -41,7 +41,7 @@ module Concurrent sleep(0.1) - result.should eq 42 + expect(result).to eq 42 end it 'passes the pushed value to only one thread' do @@ -53,7 +53,7 @@ module Concurrent sleep(0.1) - result.should have(1).items + expect(result.size).to eq(1) end it 'gets the pushed value when ready' do @@ -64,7 +64,7 @@ module Concurrent sleep(0.1) - result.should eq 57 + expect(result).to eq 57 end end @@ -75,7 +75,7 @@ module Concurrent sleep(0.05) - t.status.should eq false + expect(t.status).to eq false end it 'gets notified by writer thread' do @@ -83,7 +83,7 @@ module Concurrent Thread.new { channel.push 82 } - probe.value.should eq 82 + expect(probe.value).to eq 82 end it 'ignores already set probes and waits for a new one' do @@ -95,7 +95,7 @@ module Concurrent sleep(0.05) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' new_probe = Channel::Probe.new @@ -103,7 +103,7 @@ module Concurrent sleep(0.05) - new_probe.value.should eq 72 + expect(new_probe.value).to eq 72 end end @@ -111,18 +111,18 @@ module Concurrent describe 'probe set' do it 'has size zero after creation' do - channel.probe_set_size.should eq 0 + expect(channel.probe_set_size).to eq 0 end it 'increases size after a select' do channel.select(probe) - channel.probe_set_size.should eq 1 + expect(channel.probe_set_size).to eq 1 end it 'decreases size after a removal' do channel.select(probe) channel.remove_probe(probe) - channel.probe_set_size.should eq 0 + expect(channel.probe_set_size).to eq 0 end end diff --git a/spec/concurrent/collection/blocking_ring_buffer_spec.rb b/spec/concurrent/collection/blocking_ring_buffer_spec.rb index cf4bedcdb..6d1e245e1 100644 --- a/spec/concurrent/collection/blocking_ring_buffer_spec.rb +++ b/spec/concurrent/collection/blocking_ring_buffer_spec.rb @@ -13,21 +13,21 @@ def fill_buffer describe '#capacity' do it 'returns the value passed in constructor' do - buffer.capacity.should eq capacity + expect(buffer.capacity).to eq capacity end end describe '#count' do it 'is zero when created' do - buffer.count.should eq 0 + expect(buffer.count).to eq 0 end it 'increases when an element is added' do buffer.put 5 - buffer.count.should eq 1 + expect(buffer.count).to eq 1 buffer.put 1 - buffer.count.should eq 2 + expect(buffer.count).to eq 2 end it 'decreases when an element is removed' do @@ -35,29 +35,29 @@ def fill_buffer buffer.take - buffer.count.should eq 0 + expect(buffer.count).to eq 0 end end describe '#empty?' do it 'is true when count is zero' do - buffer.empty?.should be_true + expect(buffer.empty?).to be_truthy end it 'is false when count is not zero' do buffer.put 82 - buffer.empty?.should be_false + expect(buffer.empty?).to be_falsey end end describe '#full?' do it 'is true when count is capacity' do fill_buffer - buffer.full?.should be_true + expect(buffer.full?).to be_truthy end it 'is false when count is not capacity' do - buffer.full?.should be_false + expect(buffer.full?).to be_falsey end end @@ -69,7 +69,7 @@ def fill_buffer sleep(0.1) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end it 'continues when an element is removed' do @@ -78,7 +78,7 @@ def fill_buffer Thread.new { (capacity + 1).times { buffer.put 'hi' }; latch.count_down } Thread.new { sleep(0.1); buffer.take } - latch.wait(0.2).should be_true + expect(latch.wait(0.2)).to be_truthy end end @@ -88,7 +88,7 @@ def fill_buffer sleep(0.1) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end it 'continues when an element is added' do @@ -97,7 +97,7 @@ def fill_buffer Thread.new { buffer.take; latch.count_down } Thread.new { sleep(0.1); buffer.put 3 } - latch.wait(0.2).should be_true + expect(latch.wait(0.2)).to be_truthy end it 'returns the first added value' do @@ -105,16 +105,16 @@ def fill_buffer buffer.put 'foo' buffer.put 'bar' - buffer.take.should eq 'hi' - buffer.take.should eq 'foo' - buffer.take.should eq 'bar' + expect(buffer.take).to eq 'hi' + expect(buffer.take).to eq 'foo' + expect(buffer.take).to eq 'bar' end end describe '#peek' do context 'buffer empty' do it 'returns nil when buffer is empty' do - buffer.peek.should be_nil + expect(buffer.peek).to be_nil end end @@ -123,12 +123,12 @@ def fill_buffer before(:each) { buffer.put 'element' } it 'returns the first value' do - buffer.peek.should eq 'element' + expect(buffer.peek).to eq 'element' end it 'does not change buffer' do buffer.peek - buffer.count.should eq 1 + expect(buffer.count).to eq 1 end end end @@ -140,8 +140,8 @@ def fill_buffer buffer.put 'hi' - buffer.take.should eq 'hi' - buffer.capacity.should eq capacity + expect(buffer.take).to eq 'hi' + expect(buffer.capacity).to eq capacity end end diff --git a/spec/concurrent/collection/priority_queue_spec.rb b/spec/concurrent/collection/priority_queue_spec.rb index e942a5c06..b689a37bd 100644 --- a/spec/concurrent/collection/priority_queue_spec.rb +++ b/spec/concurrent/collection/priority_queue_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -share_examples_for :priority_queue do +shared_examples :priority_queue do subject{ described_class.new } @@ -8,40 +8,40 @@ it 'sorts from high to low when :order is :max' do subject = described_class.from_list([2, 1, 4, 5, 3, 0], order: :max) - subject.pop.should eq 5 - subject.pop.should eq 4 - subject.pop.should eq 3 + expect(subject.pop).to eq 5 + expect(subject.pop).to eq 4 + expect(subject.pop).to eq 3 end it 'sorts from high to low when :order is :high' do subject = described_class.new(order: :high) [2, 1, 4, 5, 3, 0].each{|item| subject << item } - subject.pop.should eq 5 - subject.pop.should eq 4 - subject.pop.should eq 3 + expect(subject.pop).to eq 5 + expect(subject.pop).to eq 4 + expect(subject.pop).to eq 3 end it 'sorts from low to high when :order is :min' do subject = described_class.from_list([2, 1, 4, 5, 3, 0], order: :min) - subject.pop.should eq 0 - subject.pop.should eq 1 - subject.pop.should eq 2 + expect(subject.pop).to eq 0 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 2 end it 'sorts from low to high when :order is :low' do subject = described_class.new(order: :low) [2, 1, 4, 5, 3, 0].each{|item| subject << item } - subject.pop.should eq 0 - subject.pop.should eq 1 - subject.pop.should eq 2 + expect(subject.pop).to eq 0 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 2 end it 'sorts from high to low by default' do subject = described_class.new subject = described_class.from_list([2, 1, 4, 5, 3, 0]) - subject.pop.should eq 5 - subject.pop.should eq 4 - subject.pop.should eq 3 + expect(subject.pop).to eq 5 + expect(subject.pop).to eq 4 + expect(subject.pop).to eq 3 end end @@ -50,15 +50,15 @@ it 'removes all items from a populated queue' do 10.times{|i| subject << i} subject.clear - subject.should be_empty + expect(subject).to be_empty end it 'has no effect on an empty queue' do subject.clear - subject.should be_empty + expect(subject).to be_empty end - specify { subject.clear.should be_true } + specify { expect(subject.clear).to be_truthy } end context '#delete' do @@ -66,78 +66,78 @@ it 'deletes the requested item when found' do 10.times{|item| subject << item } subject.delete(5) - subject.pop.should eq 9 - subject.pop.should eq 8 - subject.pop.should eq 7 - subject.pop.should eq 6 - subject.pop.should eq 4 - subject.pop.should eq 3 - subject.pop.should eq 2 - subject.pop.should eq 1 - subject.pop.should eq 0 + expect(subject.pop).to eq 9 + expect(subject.pop).to eq 8 + expect(subject.pop).to eq 7 + expect(subject.pop).to eq 6 + expect(subject.pop).to eq 4 + expect(subject.pop).to eq 3 + expect(subject.pop).to eq 2 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 0 end it 'deletes the requested item when it is the first element' do 10.times{|item| subject << item } subject.delete(9) - subject.length.should eq 9 - subject.pop.should eq 8 - subject.pop.should eq 7 - subject.pop.should eq 6 - subject.pop.should eq 5 - subject.pop.should eq 4 - subject.pop.should eq 3 - subject.pop.should eq 2 - subject.pop.should eq 1 - subject.pop.should eq 0 + expect(subject.length).to eq 9 + expect(subject.pop).to eq 8 + expect(subject.pop).to eq 7 + expect(subject.pop).to eq 6 + expect(subject.pop).to eq 5 + expect(subject.pop).to eq 4 + expect(subject.pop).to eq 3 + expect(subject.pop).to eq 2 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 0 end it 'deletes the requested item when it is the last element' do 10.times{|item| subject << item } subject.delete(2) - subject.length.should eq 9 - subject.pop.should eq 9 - subject.pop.should eq 8 - subject.pop.should eq 7 - subject.pop.should eq 6 - subject.pop.should eq 5 - subject.pop.should eq 4 - subject.pop.should eq 3 - subject.pop.should eq 1 - subject.pop.should eq 0 + expect(subject.length).to eq 9 + expect(subject.pop).to eq 9 + expect(subject.pop).to eq 8 + expect(subject.pop).to eq 7 + expect(subject.pop).to eq 6 + expect(subject.pop).to eq 5 + expect(subject.pop).to eq 4 + expect(subject.pop).to eq 3 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 0 end it 'deletes multiple matching items when present' do [2, 1, 2, 2, 2, 3, 2].each{|item| subject << item } subject.delete(2) - subject.pop.should eq 3 - subject.pop.should eq 1 + expect(subject.pop).to eq 3 + expect(subject.pop).to eq 1 end it 'returns true when found' do 10.times{|i| subject << i} - subject.delete(2).should be_true + expect(subject.delete(2)).to be_truthy end it 'returns false when not found' do 10.times{|i| subject << i} - subject.delete(100).should be_false + expect(subject.delete(100)).to be_falsey end it 'returns false when called on an empty queue' do - subject.delete(:foo).should be_false + expect(subject.delete(:foo)).to be_falsey end end context '#empty?' do it 'returns true for an empty queue' do - subject.should be_empty + expect(subject).to be_empty end it 'returns false for a populated queue' do 10.times{|i| subject << i} - subject.should_not be_empty + expect(subject).not_to be_empty end end @@ -145,21 +145,21 @@ it 'returns true if the item is found' do 10.times{|i| subject << i} - subject.should include(5) + expect(subject).to include(5) end it 'returns false if the item is not found' do 10.times{|i| subject << i} - subject.should_not include(50) + expect(subject).not_to include(50) end it 'returns false when the queue is empty' do - subject.should_not include(1) + expect(subject).not_to include(1) end it 'is aliased as #has_priority?' do 10.times{|i| subject << i} - subject.should have_priority(5) + expect(subject).to have_priority(5) end end @@ -167,16 +167,16 @@ it 'returns the length of a populated queue' do 10.times{|i| subject << i} - subject.length.should eq 10 + expect(subject.length).to eq 10 end it 'returns zero when the queue is empty' do - subject.length.should eq 0 + expect(subject.length).to eq 0 end it 'is aliased as #size' do 10.times{|i| subject << i} - subject.size.should eq 10 + expect(subject.size).to eq 10 end end @@ -184,18 +184,18 @@ it 'returns the item at the head of the queue' do 10.times{|i| subject << i} - subject.peek.should eq 9 + expect(subject.peek).to eq 9 end it 'does not remove the item from the queue' do 10.times{|i| subject << i} subject.peek - subject.length.should eq 10 - subject.should include(9) + expect(subject.length).to eq 10 + expect(subject).to include(9) end it 'returns nil when the queue is empty' do - subject.peek.should be_nil + expect(subject.peek).to be_nil end end @@ -203,28 +203,28 @@ it 'returns the item at the head of the queue' do 10.times{|i| subject << i} - subject.pop.should eq 9 + expect(subject.pop).to eq 9 end it 'removes the item from the queue' do 10.times{|i| subject << i} subject.pop - subject.length.should eq 9 - subject.should_not include(9) + expect(subject.length).to eq 9 + expect(subject).not_to include(9) end it 'returns nil when the queue is empty' do - subject.pop.should be_nil + expect(subject.pop).to be_nil end it 'is aliased as #deq' do 10.times{|i| subject << i} - subject.deq.should eq 9 + expect(subject.deq).to eq 9 end it 'is aliased as #shift' do 10.times{|i| subject << i} - subject.shift.should eq 9 + expect(subject.shift).to eq 9 end end @@ -232,35 +232,35 @@ it 'adds the item to the queue' do subject.push(1) - subject.should include(1) + expect(subject).to include(1) end it 'sorts the new item in priority order' do 3.times{|i| subject << i} - subject.pop.should eq 2 - subject.pop.should eq 1 - subject.pop.should eq 0 + expect(subject.pop).to eq 2 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 0 end it 'arbitrarily orders equal items with respect to each other' do 3.times{|i| subject << i} subject.push(1) - subject.pop.should eq 2 - subject.pop.should eq 1 - subject.pop.should eq 1 - subject.pop.should eq 0 + expect(subject.pop).to eq 2 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 0 end - specify { subject.push(10).should be_true } + specify { expect(subject.push(10)).to be_truthy } it 'is aliased as <<' do subject << 1 - subject.should include(1) + expect(subject).to include(1) end it 'is aliased as enq' do subject.enq(1) - subject.should include(1) + expect(subject).to include(1) end end @@ -268,22 +268,22 @@ it 'creates an empty queue from an empty list' do subject = described_class.from_list([]) - subject.should be_empty + expect(subject).to be_empty end it 'creates a sorted, populated queue from an Array' do subject = described_class.from_list([2, 1, 4, 5, 3, 0]) - subject.pop.should eq 5 - subject.pop.should eq 4 - subject.pop.should eq 3 - subject.pop.should eq 2 - subject.pop.should eq 1 - subject.pop.should eq 0 + expect(subject.pop).to eq 5 + expect(subject.pop).to eq 4 + expect(subject.pop).to eq 3 + expect(subject.pop).to eq 2 + expect(subject.pop).to eq 1 + expect(subject.pop).to eq 0 end it 'creates a sorted, populated queue from a Hash' do subject = described_class.from_list(two: 2, one: 1, three: 3, zero: 0) - subject.length.should eq 4 + expect(subject.length).to eq 4 end end end @@ -306,11 +306,11 @@ module Concurrent describe PriorityQueue do if jruby? it 'inherits from JavaPriorityQueue' do - PriorityQueue.ancestors.should include(JavaPriorityQueue) + expect(PriorityQueue.ancestors).to include(JavaPriorityQueue) end else it 'inherits from MutexPriorityQueue' do - PriorityQueue.ancestors.should include(MutexPriorityQueue) + expect(PriorityQueue.ancestors).to include(MutexPriorityQueue) end end end diff --git a/spec/concurrent/collection/ring_buffer_spec.rb b/spec/concurrent/collection/ring_buffer_spec.rb index 77a007b5e..033aacbd9 100644 --- a/spec/concurrent/collection/ring_buffer_spec.rb +++ b/spec/concurrent/collection/ring_buffer_spec.rb @@ -13,61 +13,61 @@ def fill_buffer describe '#capacity' do it 'returns the value passed in constructor' do - buffer.capacity.should eq capacity + expect(buffer.capacity).to eq capacity end end describe '#count' do it 'is zero when created' do - buffer.count.should eq 0 + expect(buffer.count).to eq 0 end it 'increases when an element is added' do buffer.offer 5 - buffer.count.should eq 1 + expect(buffer.count).to eq 1 buffer.offer 1 - buffer.count.should eq 2 + expect(buffer.count).to eq 2 end it 'decreases when an element is removed' do buffer.offer 10 buffer.poll - buffer.count.should eq 0 + expect(buffer.count).to eq 0 end end describe '#empty?' do it 'is true when count is zero' do - buffer.empty?.should be_true + expect(buffer.empty?).to be_truthy end it 'is false when count is not zero' do buffer.offer 82 - buffer.empty?.should be_false + expect(buffer.empty?).to be_falsey end end describe '#full?' do it 'is true when count is capacity' do fill_buffer - buffer.full?.should be_true + expect(buffer.full?).to be_truthy end it 'is false when count is not capacity' do - buffer.full?.should be_false + expect(buffer.full?).to be_falsey end end describe '#offer' do it 'returns false when buffer is full' do fill_buffer - buffer.offer(3).should be_false + expect(buffer.offer(3)).to be_falsey end it 'returns true when the buffer is not full' do - buffer.offer(5).should be_true + expect(buffer.offer(5)).to be_truthy end end @@ -78,20 +78,20 @@ def fill_buffer buffer.offer 'foo' buffer.offer 'bar' - buffer.poll.should eq 'hi' - buffer.poll.should eq 'foo' - buffer.poll.should eq 'bar' + expect(buffer.poll).to eq 'hi' + expect(buffer.poll).to eq 'foo' + expect(buffer.poll).to eq 'bar' end it 'returns nil when buffer is empty' do - buffer.poll.should be_nil + expect(buffer.poll).to be_nil end end describe '#peek' do context 'buffer empty' do it 'returns nil when buffer is empty' do - buffer.peek.should be_nil + expect(buffer.peek).to be_nil end end @@ -100,12 +100,12 @@ def fill_buffer before(:each) { buffer.offer 'element' } it 'returns the first value' do - buffer.peek.should eq 'element' + expect(buffer.peek).to eq 'element' end it 'does not change buffer' do buffer.peek - buffer.count.should eq 1 + expect(buffer.count).to eq 1 end end end @@ -117,8 +117,8 @@ def fill_buffer buffer.offer 'hi' - buffer.poll.should eq 'hi' - buffer.capacity.should eq capacity + expect(buffer.poll).to eq 'hi' + expect(buffer.capacity).to eq capacity end end diff --git a/spec/concurrent/configuration_spec.rb b/spec/concurrent/configuration_spec.rb index b2090f0aa..c0c8e04f9 100644 --- a/spec/concurrent/configuration_spec.rb +++ b/spec/concurrent/configuration_spec.rb @@ -4,15 +4,15 @@ module Concurrent describe Configuration do it 'creates a global timer pool' do - Concurrent.configuration.global_timer_set.should_not be_nil - Concurrent.configuration.global_timer_set.should respond_to(:post) + expect(Concurrent.configuration.global_timer_set).not_to be_nil + expect(Concurrent.configuration.global_timer_set).to respond_to(:post) end context 'global task pool' do specify 'reader creates a default pool when first called if none exists' do - Concurrent.configuration.global_task_pool.should_not be_nil - Concurrent.configuration.global_task_pool.should respond_to(:post) + expect(Concurrent.configuration.global_task_pool).not_to be_nil + expect(Concurrent.configuration.global_task_pool).to respond_to(:post) end specify 'writer memoizes the given executor' do @@ -20,7 +20,7 @@ module Concurrent Concurrent.configure do |config| config.global_task_pool = executor end - Concurrent.configuration.global_task_pool.should eq executor + expect(Concurrent.configuration.global_task_pool).to eq executor end specify 'writer raises an exception if called after initialization' do @@ -40,8 +40,8 @@ module Concurrent context 'global operation pool' do specify 'reader creates a default pool when first called if none exists' do - Concurrent.configuration.global_operation_pool.should_not be_nil - Concurrent.configuration.global_operation_pool.should respond_to(:post) + expect(Concurrent.configuration.global_operation_pool).not_to be_nil + expect(Concurrent.configuration.global_operation_pool).to respond_to(:post) end specify 'writer memoizes the given executor' do @@ -49,7 +49,7 @@ module Concurrent Concurrent.configure do |config| config.global_operation_pool = executor end - Concurrent.configuration.global_operation_pool.should eq executor + expect(Concurrent.configuration.global_operation_pool).to eq executor end specify 'writer raises an exception if called after initialization' do diff --git a/spec/concurrent/dataflow_spec.rb b/spec/concurrent/dataflow_spec.rb index c706ed9db..b57b225e8 100644 --- a/spec/concurrent/dataflow_spec.rb +++ b/spec/concurrent/dataflow_spec.rb @@ -14,7 +14,7 @@ module Concurrent specify '#dataflow uses the global task pool' do input = Future.execute{0} - Concurrent.should_receive(:dataflow_with).once. + expect(Concurrent).to receive(:dataflow_with).once. with(Concurrent.configuration.global_task_pool, input) Concurrent::dataflow(input){0} end @@ -23,7 +23,7 @@ module Concurrent input = Future.execute{0} result = Future.new{0} - Future.should_receive(:new).with(executor: root_executor).and_return(result) + expect(Future).to receive(:new).with(executor: root_executor).and_return(result) Concurrent::dataflow_with(root_executor, input){0} end @@ -74,8 +74,8 @@ module Concurrent end it 'returns a Future' do - Concurrent::dataflow{0}.should be_a(Future) - Concurrent::dataflow{0}.should be_a(Future) + expect(Concurrent::dataflow{0}).to be_a(Future) + expect(Concurrent::dataflow{0}).to be_a(Future) end context 'does not schedule the Future' do @@ -83,12 +83,12 @@ module Concurrent specify 'if no dependencies are completed' do d = Future.new(executor: executor){0} f = Concurrent::dataflow(d){0} - f.should be_unscheduled + expect(f).to be_unscheduled d.execute d = Future.new(executor: executor){0} f = Concurrent::dataflow_with(root_executor, d){0} - f.should be_unscheduled + expect(f).to be_unscheduled d.execute end @@ -97,14 +97,14 @@ module Concurrent d2 = Future.new(executor: executor){0} f = Concurrent::dataflow(d1, d2){0} d1.execute - f.should be_unscheduled + expect(f).to be_unscheduled d2.execute d1 = Future.new(executor: executor){0} d2 = Future.new(executor: executor){0} f = Concurrent::dataflow_with(root_executor, d1, d2){0} d1.execute - f.should be_unscheduled + expect(f).to be_unscheduled d2.execute end end @@ -115,12 +115,12 @@ module Concurrent d = Future.new(executor: executor){0} f = Concurrent::dataflow(d){0} d.execute - f.value.should eq 0 + expect(f.value).to eq 0 d = Future.new(executor: executor){0} f = Concurrent::dataflow_with(root_executor, d){0} d.execute - f.value.should eq 0 + expect(f.value).to eq 0 end specify 'if there is more than one' do @@ -129,14 +129,14 @@ module Concurrent f = Concurrent::dataflow(d1, d2){0} d1.execute d2.execute - f.value.should eq 0 + expect(f.value).to eq 0 d1 = Future.new(executor: executor){0} d2 = Future.new(executor: executor){0} f = Concurrent::dataflow_with(root_executor, d1, d2){0} d1.execute d2.execute - f.value.should eq 0 + expect(f.value).to eq 0 end end @@ -146,12 +146,12 @@ module Concurrent d = Future.new(executor: executor){0} d.execute f = Concurrent::dataflow(d){0} - f.value.should eq 0 + expect(f.value).to eq 0 d = Future.new(executor: executor){0} d.execute f = Concurrent::dataflow_with(root_executor, d){0} - f.value.should eq 0 + expect(f.value).to eq 0 end specify 'if there is more than one' do @@ -160,14 +160,14 @@ module Concurrent d1.execute d2.execute f = Concurrent::dataflow(d1, d2){0} - f.value.should eq 0 + expect(f.value).to eq 0 d1 = Future.new(executor: executor){0} d2 = Future.new(executor: executor){0} d1.execute d2.execute f = Concurrent::dataflow_with(root_executor, d1, d2){0} - f.value.should eq 0 + expect(f.value).to eq 0 end end @@ -177,12 +177,12 @@ module Concurrent d = Future.new(executor: executor){14} f = Concurrent::dataflow(d){|v| v } d.execute - f.value.should eq 14 + expect(f.value).to eq 14 d = Future.new(executor: executor){14} f = Concurrent::dataflow_with(root_executor, d){|v| v } d.execute - f.value.should eq 14 + expect(f.value).to eq 14 end specify 'if there is more than one' do @@ -191,14 +191,14 @@ module Concurrent f = Concurrent::dataflow(d1, d2) {|v1, v2| v1 + v2} d1.execute d2.execute - f.value.should eq 16 + expect(f.value).to eq 16 d1 = Future.new(executor: executor){14} d2 = Future.new(executor: executor){2} f = Concurrent::dataflow_with(root_executor, d1, d2) {|v1, v2| v1 + v2} d1.execute d2.execute - f.value.should eq 16 + expect(f.value).to eq 16 end end @@ -218,7 +218,7 @@ def fib_with_dot(n) expected = fib_with_dot(14) sleep(0.1) - expected.value.should eq 377 + expect(expected.value).to eq 377 end it 'can be called as Concurrent::dataflow and Concurrent::dataflow_with' do @@ -235,7 +235,7 @@ def fib_with_colons(n) expected = fib_with_colons(14) sleep(0.1) - expected.value.should eq 377 + expect(expected.value).to eq 377 end end end diff --git a/spec/concurrent/delay_spec.rb b/spec/concurrent/delay_spec.rb index b54222467..6eea422da 100644 --- a/spec/concurrent/delay_spec.rb +++ b/spec/concurrent/delay_spec.rb @@ -42,8 +42,8 @@ def dereferenceable_subject(value, opts = {}) context '#initialize' do it 'sets the state to :pending' do - Delay.new{ nil }.state.should eq :pending - Delay.new{ nil }.should be_pending + expect(Delay.new{ nil }.state).to eq :pending + expect(Delay.new{ nil }).to be_pending end it 'raises an exception when no block given' do @@ -56,14 +56,14 @@ def dereferenceable_subject(value, opts = {}) context '#reconfigure' do it 'returns value of block used in reconfiguration' do - Delay.new { nil }.tap { |d| d.reconfigure { true } }.value.should be_true + expect(Delay.new { nil }.tap { |d| d.reconfigure { true } }.value).to be_truthy end it 'returns false when process completed?' do d = Delay.new { 1 } - d.reconfigure { 2 }.should be_true - d.value.should be 2 - d.reconfigure { 3 }.should be_false + expect(d.reconfigure { 2 }).to be_truthy + expect(d.value).to be 2 + expect(d.reconfigure { 3 }).to be_falsey end end @@ -72,17 +72,17 @@ def dereferenceable_subject(value, opts = {}) let(:task){ proc{ nil } } it 'does not call the block before #value is called' do - task.should_not_receive(:call).with(any_args) + expect(task).not_to receive(:call).with(any_args) Delay.new(&task) end it 'calls the block when #value is called' do - task.should_receive(:call).once.with(any_args).and_return(nil) + expect(task).to receive(:call).once.with(any_args).and_return(nil) Delay.new(&task).value end it 'only calls the block once no matter how often #value is called' do - task.should_receive(:call).once.with(any_args).and_return(nil) + expect(task).to receive(:call).once.with(any_args).and_return(nil) delay = Delay.new(&task) 5.times{ delay.value } end diff --git a/spec/concurrent/dereferenceable_shared.rb b/spec/concurrent/dereferenceable_shared.rb index 55114f018..650966856 100644 --- a/spec/concurrent/dereferenceable_shared.rb +++ b/spec/concurrent/dereferenceable_shared.rb @@ -1,73 +1,73 @@ require 'spec_helper' -share_examples_for :dereferenceable do +shared_examples :dereferenceable do it 'defaults :dup_on_deref to false' do value = 'value' - value.should_not_receive(:dup).with(any_args) + expect(value).not_to receive(:dup).with(any_args) subject = dereferenceable_subject(value) - subject.value.should eq 'value' + expect(subject.value).to eq 'value' subject = dereferenceable_subject(value, dup_on_deref: false) - subject.value.should eq 'value' + expect(subject.value).to eq 'value' subject = dereferenceable_subject(value, dup: false) - subject.value.should eq 'value' + expect(subject.value).to eq 'value' end it 'calls #dup when the :dup_on_deref option is true' do value = 'value' subject = dereferenceable_subject(value, dup_on_deref: true) - subject.value.object_id.should_not eq value.object_id - subject.value.should eq 'value' + expect(subject.value.object_id).not_to eq value.object_id + expect(subject.value).to eq 'value' subject = dereferenceable_subject(value, dup: true) - subject.value.object_id.should_not eq value.object_id - subject.value.should eq 'value' + expect(subject.value.object_id).not_to eq value.object_id + expect(subject.value).to eq 'value' end it 'defaults :freeze_on_deref to false' do value = 'value' - value.should_not_receive(:freeze).with(any_args) + expect(value).not_to receive(:freeze).with(any_args) subject = dereferenceable_subject(value) - subject.value.should eq 'value' + expect(subject.value).to eq 'value' subject = dereferenceable_subject(value, freeze_on_deref: false) - subject.value.should eq 'value' + expect(subject.value).to eq 'value' subject = dereferenceable_subject(value, freeze: false) - subject.value.should eq 'value' + expect(subject.value).to eq 'value' end it 'calls #freeze when the :freeze_on_deref option is true' do value = 'value' subject = dereferenceable_subject(value, freeze_on_deref: true) - subject.value.should be_frozen - subject.value.should eq 'value' + expect(subject.value).to be_frozen + expect(subject.value).to eq 'value' subject = dereferenceable_subject(value, freeze: true) - subject.value.should be_frozen - subject.value.should eq 'value' + expect(subject.value).to be_frozen + expect(subject.value).to eq 'value' end it 'defaults :copy_on_deref to nil' do value = 'value' subject = dereferenceable_subject(value) - subject.value.object_id.should == value.object_id - subject.value.should eq 'value' + expect(subject.value.object_id).to eq(value.object_id) + expect(subject.value).to eq 'value' subject = dereferenceable_subject(value, copy_on_deref: nil) - subject.value.object_id.should == value.object_id - subject.value.should eq 'value' + expect(subject.value.object_id).to eq(value.object_id) + expect(subject.value).to eq 'value' subject = dereferenceable_subject(value, copy: nil) - subject.value.object_id.should == value.object_id - subject.value.should eq 'value' + expect(subject.value.object_id).to eq(value.object_id) + expect(subject.value).to eq 'value' end it 'calls the block when the :copy_on_deref option is passed a proc' do @@ -75,10 +75,10 @@ copy = proc{|val| 'copy' } subject = dereferenceable_subject(value, copy_on_deref: copy) - subject.value.object_id.should_not == value.object_id + expect(subject.value.object_id).not_to eq(value.object_id) subject = dereferenceable_subject(value, copy: copy) - subject.value.object_id.should_not == value.object_id + expect(subject.value.object_id).not_to eq(value.object_id) end it 'calls the :copy block first followed by #dup followed by #freeze' do @@ -88,17 +88,17 @@ frozen = 'frozen' copy = proc{|val| copied } - copied.should_receive(:dup).at_least(:once).with(no_args).and_return(dup) - dup.should_receive(:freeze).at_least(:once).with(no_args).and_return(frozen) + expect(copied).to receive(:dup).at_least(:once).with(no_args).and_return(dup) + expect(dup).to receive(:freeze).at_least(:once).with(no_args).and_return(frozen) subject = dereferenceable_subject(value, dup_on_deref: true, freeze_on_deref: true, copy_on_deref: copy) - subject.value.should eq frozen + expect(subject.value).to eq frozen end it 'does not call #dup when #dup_on_deref is set and the value is nil' do allow_message_expectations_on_nil result = nil - result.should_not_receive(:dup).with(any_args) + expect(result).not_to receive(:dup).with(any_args) subject = dereferenceable_subject(result, dup_on_deref: true) subject.value end @@ -106,7 +106,7 @@ it 'does not call #freeze when #freeze_on_deref is set and the value is nil' do allow_message_expectations_on_nil result = nil - result.should_not_receive(:freeze).with(any_args) + expect(result).not_to receive(:freeze).with(any_args) subject = dereferenceable_subject(result, freeze_on_deref: true) subject.value end @@ -114,7 +114,7 @@ it 'does not call the #copy_on_deref block when the value is nil' do copier = proc { 42 } subject = dereferenceable_subject(nil, copy_on_deref: copier) - subject.value.should be_nil + expect(subject.value).to be_nil end it 'supports dereference flags with observers' do @@ -122,12 +122,12 @@ if dereferenceable_subject(0).respond_to?(:add_observer) result = 'result' - result.should_receive(:dup).at_least(:once).and_return(result) - result.should_receive(:freeze).at_least(:once).and_return(result) + expect(result).to receive(:dup).at_least(:once).and_return(result) + expect(result).to receive(:freeze).at_least(:once).and_return(result) copier = proc { result } observer = double('observer') - observer.should_receive(:update).at_least(:once).with(any_args) + expect(observer).to receive(:update).at_least(:once).with(any_args) subject = dereferenceable_observable(dup_on_deref: true, freeze_on_deref: true, copy_on_deref: copier) diff --git a/spec/concurrent/exchanger_spec.rb b/spec/concurrent/exchanger_spec.rb index e895deaa9..2ca1acb46 100644 --- a/spec/concurrent/exchanger_spec.rb +++ b/spec/concurrent/exchanger_spec.rb @@ -12,7 +12,7 @@ module Concurrent it 'should block' do t = Thread.new { exchanger.exchange(1) } sleep(0.1) - t.status.should eq 'sleep' + expect(t.status).to eq 'sleep' end it 'should receive the other value' do @@ -24,8 +24,8 @@ module Concurrent sleep(0.1) - first_value.should eq 4 - second_value.should eq 2 + expect(first_value).to eq 4 + expect(second_value).to eq 2 end it 'can be reused' do @@ -42,8 +42,8 @@ module Concurrent sleep(0.1) - first_value.should eq 12 - second_value.should eq 10 + expect(first_value).to eq 12 + expect(second_value).to eq 10 end end @@ -51,8 +51,8 @@ module Concurrent it 'should block until timeout' do start = Time.now.to_f - exchanger.exchange(2, 0.1).should be_nil - (Time.now.to_f - start).should be_within(0.05).of(0.1) + expect(exchanger.exchange(2, 0.1)).to be_nil + expect(Time.now.to_f - start).to be_within(0.05).of(0.1) end end end diff --git a/spec/concurrent/executor/cached_thread_pool_shared.rb b/spec/concurrent/executor/cached_thread_pool_shared.rb index 2cd761396..f16202b6a 100644 --- a/spec/concurrent/executor/cached_thread_pool_shared.rb +++ b/spec/concurrent/executor/cached_thread_pool_shared.rb @@ -1,7 +1,7 @@ require 'spec_helper' require_relative 'thread_pool_shared' -share_examples_for :cached_thread_pool do +shared_examples :cached_thread_pool do subject do described_class.new(overflow_policy: :discard) @@ -17,32 +17,32 @@ context '#initialize' do it 'sets :max_length to DEFAULT_MAX_POOL_SIZE' do - described_class.new.max_length.should eq described_class::DEFAULT_MAX_POOL_SIZE + expect(described_class.new.max_length).to eq described_class::DEFAULT_MAX_POOL_SIZE end it 'sets :min_length to DEFAULT_MIN_POOL_SIZE' do - subject = described_class.new.min_length.should eq described_class::DEFAULT_MIN_POOL_SIZE + subject = expect(described_class.new.min_length).to eq described_class::DEFAULT_MIN_POOL_SIZE end it 'sets :idletime to DEFAULT_THREAD_IDLETIMEOUT' do - subject = described_class.new.idletime.should eq described_class::DEFAULT_THREAD_IDLETIMEOUT + subject = expect(described_class.new.idletime).to eq described_class::DEFAULT_THREAD_IDLETIMEOUT end it 'sets :max_queue to DEFAULT_MAX_QUEUE_SIZE' do - subject = described_class.new.max_queue.should eq described_class::DEFAULT_MAX_QUEUE_SIZE + subject = expect(described_class.new.max_queue).to eq described_class::DEFAULT_MAX_QUEUE_SIZE end end context '#min_length' do it 'returns zero on creation' do - subject.min_length.should eq 0 + expect(subject.min_length).to eq 0 end it 'returns zero while running' do 10.times{ subject.post{ nil } } sleep(0.1) - subject.min_length.should eq 0 + expect(subject.min_length).to eq 0 end it 'returns zero once shutdown' do @@ -50,20 +50,20 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.min_length.should eq 0 + expect(subject.min_length).to eq 0 end end context '#max_length' do it 'returns :max_length on creation' do - subject.max_length.should eq described_class::DEFAULT_MAX_POOL_SIZE + expect(subject.max_length).to eq described_class::DEFAULT_MAX_POOL_SIZE end it 'returns :max_length while running' do 10.times{ subject.post{ nil } } sleep(0.1) - subject.max_length.should eq described_class::DEFAULT_MAX_POOL_SIZE + expect(subject.max_length).to eq described_class::DEFAULT_MAX_POOL_SIZE end it 'returns :max_length once shutdown' do @@ -71,20 +71,20 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.max_length.should eq described_class::DEFAULT_MAX_POOL_SIZE + expect(subject.max_length).to eq described_class::DEFAULT_MAX_POOL_SIZE end end context '#largest_length' do it 'returns zero on creation' do - subject.largest_length.should eq 0 + expect(subject.largest_length).to eq 0 end it 'returns a non-zero number once tasks have been received' do 10.times{ subject.post{ sleep(0.1) } } sleep(0.1) - subject.largest_length.should > 0 + expect(subject.largest_length).to be > 0 end it 'returns a non-zero number after shutdown if tasks have been received' do @@ -92,15 +92,15 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.largest_length.should > 0 + expect(subject.largest_length).to be > 0 end end context '#status' do it 'returns an array' do - subject.stub(:warn) - subject.status.should be_kind_of(Array) + allow(subject).to receive(:warn) + expect(subject.status).to be_kind_of(Array) end end @@ -109,7 +109,7 @@ subject{ described_class.new(idletime: 42) } it 'returns the thread idletime' do - subject.idletime.should eq described_class::DEFAULT_THREAD_IDLETIMEOUT + expect(subject.idletime).to eq described_class::DEFAULT_THREAD_IDLETIMEOUT end end end diff --git a/spec/concurrent/executor/executor_service_shared.rb b/spec/concurrent/executor/executor_service_shared.rb index 5185ecd5b..05fe2c180 100644 --- a/spec/concurrent/executor/executor_service_shared.rb +++ b/spec/concurrent/executor/executor_service_shared.rb @@ -1,7 +1,7 @@ require 'spec_helper' require_relative 'global_thread_pool_shared' -share_examples_for :executor_service do +shared_examples :executor_service do after(:each) do subject.kill @@ -17,13 +17,13 @@ subject.post{ sleep(1) } subject.shutdown subject.post{ latch.count_down } - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey end it 'returns false while shutting down' do subject.post{ sleep(1) } subject.shutdown - subject.post{ nil }.should be_false + expect(subject.post{ nil }).to be_falsey end it 'rejects the block once shutdown' do @@ -31,40 +31,40 @@ latch = Concurrent::CountDownLatch.new(1) subject.post{ sleep(1) } subject.post{ latch.count_down } - latch.wait(0.1).should be_false + expect(latch.wait(0.1)).to be_falsey end it 'returns false once shutdown' do subject.post{ nil } subject.shutdown sleep(0.1) - subject.post{ nil }.should be_false + expect(subject.post{ nil }).to be_falsey end end context '#running?' do it 'returns true when the thread pool is running' do - subject.should be_running + expect(subject).to be_running end it 'returns false when the thread pool is shutting down' do subject.post{ sleep(1) } subject.shutdown subject.wait_for_termination(1) - subject.should_not be_running + expect(subject).not_to be_running end it 'returns false when the thread pool is shutdown' do subject.shutdown subject.wait_for_termination(1) - subject.should_not be_running + expect(subject).not_to be_running end it 'returns false when the thread pool is killed' do subject.kill subject.wait_for_termination(1) - subject.should_not be_running + expect(subject).not_to be_running end end @@ -75,16 +75,16 @@ latch2 = Concurrent::CountDownLatch.new(1) subject.post{ sleep(0.2); latch1.count_down } subject.shutdown - subject.post{ latch2.count_down }.should be_false - latch1.wait(1).should be_true - latch2.wait(0.2).should be_false + expect(subject.post{ latch2.count_down }).to be_falsey + expect(latch1.wait(1)).to be_truthy + expect(latch2.wait(0.2)).to be_falsey end it 'allows in-progress tasks to complete' do latch = Concurrent::CountDownLatch.new(1) subject.post{ sleep(0.1); latch.count_down } subject.shutdown - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'allows pending tasks to complete' do @@ -92,7 +92,7 @@ subject.post{ sleep(0.2); latch.count_down } subject.post{ sleep(0.2); latch.count_down } subject.shutdown - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end end @@ -103,7 +103,7 @@ subject.post{ sleep(0.1); latch.count_down } subject.shutdown subject.wait_for_termination(1) - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'allows pending tasks to complete' do @@ -113,7 +113,7 @@ end subject.shutdown subject.wait_for_termination(1) - q.length.should eq 5 + expect(q.length).to eq 5 end it 'stops accepting/running new tasks' do @@ -123,7 +123,7 @@ subject.shutdown subject.post{ expected.increment } subject.wait_for_termination(1) - expected.value.should == 2 + expect(expected.value).to eq(2) end end @@ -135,9 +135,9 @@ subject.post{ sleep(0.1); latch.count_down } latch.wait(1) subject.kill - subject.post{ expected.make_true }.should be_false + expect(subject.post{ expected.make_true }).to be_falsey sleep(0.1) - expected.value.should be_false + expect(expected.value).to be_falsey end it 'rejects all pending tasks' do @@ -145,7 +145,7 @@ sleep(0.1) subject.kill sleep(0.1) - subject.post{ nil }.should be_false + expect(subject.post{ nil }).to be_falsey end end @@ -153,21 +153,21 @@ it 'immediately returns true when no operations are pending' do subject.shutdown - subject.wait_for_termination(0).should be_true + expect(subject.wait_for_termination(0)).to be_truthy end it 'returns true after shutdown has complete' do 10.times { subject << proc{ nil } } sleep(0.1) subject.shutdown - subject.wait_for_termination(1).should be_true + expect(subject.wait_for_termination(1)).to be_truthy end it 'returns true when shutdown sucessfully completes before timeout' do subject.post{ sleep(0.5) } sleep(0.1) subject.shutdown - subject.wait_for_termination(1).should be_true + expect(subject.wait_for_termination(1)).to be_truthy end it 'returns false when shutdown fails to complete before timeout' do @@ -175,7 +175,7 @@ 100.times{ subject.post{ sleep(1) } } sleep(0.1) subject.shutdown - subject.wait_for_termination(0).should be_false + expect(subject.wait_for_termination(0)).to be_falsey end end end diff --git a/spec/concurrent/executor/fixed_thread_pool_shared.rb b/spec/concurrent/executor/fixed_thread_pool_shared.rb index a7fdb12c3..4dfa792db 100644 --- a/spec/concurrent/executor/fixed_thread_pool_shared.rb +++ b/spec/concurrent/executor/fixed_thread_pool_shared.rb @@ -2,7 +2,7 @@ require_relative 'thread_pool_shared' require 'thread' -share_examples_for :fixed_thread_pool do +shared_examples :fixed_thread_pool do let!(:num_threads){ 5 } subject { described_class.new(num_threads) } @@ -19,24 +19,24 @@ subject { described_class.new(5) } it 'defaults :min_length correctly' do - subject.min_length.should eq 5 + expect(subject.min_length).to eq 5 end it 'defaults :max_length correctly' do - subject.max_length.should eq 5 + expect(subject.max_length).to eq 5 end it 'defaults :overflow_policy to :abort' do - subject.overflow_policy.should eq :abort + expect(subject.overflow_policy).to eq :abort end it 'defaults :idletime correctly' do - subject.idletime.should eq subject.class.const_get(:DEFAULT_THREAD_IDLETIMEOUT) + expect(subject.idletime).to eq subject.class.const_get(:DEFAULT_THREAD_IDLETIMEOUT) end it 'defaults default :max_queue to zero' do - subject.max_queue.should eq 0 + expect(subject.max_queue).to eq 0 end end @@ -44,25 +44,25 @@ context '#initialize explicit values' do it 'raises an exception when the pool length is less than one' do - lambda { + expect { described_class.new(0) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it 'sets explicit :max_queue correctly' do subject = described_class.new(5, :max_queue => 10) - subject.max_queue.should eq 10 + expect(subject.max_queue).to eq 10 end it 'correctly sets valid :overflow_policy' do subject = described_class.new(5, :overflow_policy => :caller_runs) - subject.overflow_policy.should eq :caller_runs + expect(subject.overflow_policy).to eq :caller_runs end it "correctly sets valid :idletime" do subject = described_class.new(5, :idletime => 10) - subject.idletime.should eq 10 + expect(subject.idletime).to eq 10 end it 'raises an exception if given an invalid :overflow_policy' do @@ -77,13 +77,13 @@ context '#min_length' do it 'returns :num_threads on creation' do - subject.min_length.should eq num_threads + expect(subject.min_length).to eq num_threads end it 'returns :num_threads while running' do 10.times{ subject.post{ nil } } sleep(0.1) - subject.min_length.should eq num_threads + expect(subject.min_length).to eq num_threads end it 'returns :num_threads once shutdown' do @@ -91,20 +91,20 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.min_length.should eq num_threads + expect(subject.min_length).to eq num_threads end end context '#max_length' do it 'returns :num_threads on creation' do - subject.max_length.should eq num_threads + expect(subject.max_length).to eq num_threads end it 'returns :num_threads while running' do 10.times{ subject.post{ nil } } sleep(0.1) - subject.max_length.should eq num_threads + expect(subject.max_length).to eq num_threads end it 'returns :num_threads once shutdown' do @@ -112,7 +112,7 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.max_length.should eq num_threads + expect(subject.max_length).to eq num_threads end end @@ -121,20 +121,20 @@ it 'returns :num_threads while running' do 10.times{ subject.post{ nil } } sleep(0.1) - subject.length.should eq num_threads + expect(subject.length).to eq num_threads end end context '#largest_length' do it 'returns zero on creation' do - subject.largest_length.should eq 0 + expect(subject.largest_length).to eq 0 end it 'returns :num_threads while running' do 10.times{ subject.post{ nil } } sleep(0.1) - subject.largest_length.should eq num_threads + expect(subject.largest_length).to eq num_threads end it 'returns :num_threads once shutdown' do @@ -142,15 +142,15 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.largest_length.should eq num_threads + expect(subject.largest_length).to eq num_threads end end context '#status' do it 'returns an array' do - subject.stub(:warn) - subject.status.should be_kind_of(Array) + allow(subject).to receive(:warn) + expect(subject.status).to be_kind_of(Array) end end @@ -165,7 +165,7 @@ sleep(0.1) subject.kill sleep(0.1) - @expected.should be_false + expect(@expected).to be_falsey end end @@ -175,7 +175,7 @@ pool = described_class.new(5) 100.times{ pool << proc{ sleep(1) } } sleep(0.1) - pool.current_length.should eq 5 + expect(pool.current_length).to eq 5 pool.kill end end @@ -223,7 +223,7 @@ end latch.wait(1) - @queue.length.should be < 5 + expect(@queue.length).to be < 5 end # To check for caller_runs, we'll check how many unique threads @@ -248,8 +248,8 @@ a = [] a << @queue.shift until @queue.empty? - a.size.should eq 5 # one for each run of the block - a.uniq.size.should eq 3 # one for each of teh two threads, plus the caller + expect(a.size).to eq 5 # one for each run of the block + expect(a.uniq.size).to eq 3 # one for each of teh two threads, plus the caller end end end diff --git a/spec/concurrent/executor/global_thread_pool_shared.rb b/spec/concurrent/executor/global_thread_pool_shared.rb index 6b5831037..cfbf16d88 100644 --- a/spec/concurrent/executor/global_thread_pool_shared.rb +++ b/spec/concurrent/executor/global_thread_pool_shared.rb @@ -1,17 +1,17 @@ require 'spec_helper' -share_examples_for :global_thread_pool do +shared_examples :global_thread_pool do context '#post' do it 'raises an exception if no block is given' do - lambda { + expect { subject.post - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it 'returns true when the block is added to the queue' do - subject.post{ nil }.should be_true + expect(subject.post{ nil }).to be_truthy end it 'calls the block with the given arguments' do @@ -22,14 +22,14 @@ latch.count_down end latch.wait(0.2) - expected.should eq [1, 2, 3] + expect(expected).to eq [1, 2, 3] end it 'aliases #<<' do latch = Concurrent::CountDownLatch.new(1) subject << proc { latch.count_down } latch.wait(0.2) - latch.count.should eq 0 + expect(latch.count).to eq 0 end end end diff --git a/spec/concurrent/executor/java_cached_thread_pool_spec.rb b/spec/concurrent/executor/java_cached_thread_pool_spec.rb index 2e0b5febd..00c842c9b 100644 --- a/spec/concurrent/executor/java_cached_thread_pool_spec.rb +++ b/spec/concurrent/executor/java_cached_thread_pool_spec.rb @@ -22,15 +22,15 @@ module Concurrent it 'sets :overflow_policy correctly' do clazz = java.util.concurrent.ThreadPoolExecutor::DiscardPolicy policy = clazz.new - clazz.should_receive(:new).at_least(:once).with(any_args).and_return(policy) + expect(clazz).to receive(:new).at_least(:once).with(any_args).and_return(policy) subject = JavaCachedThreadPool.new(overflow_policy: :discard) - subject.overflow_policy.should eq :discard + expect(subject.overflow_policy).to eq :discard end it 'defaults :overflow_policy to :abort' do subject = JavaCachedThreadPool.new - subject.overflow_policy.should eq :abort + expect(subject.overflow_policy).to eq :abort end it 'raises an exception if given an invalid :overflow_policy' do diff --git a/spec/concurrent/executor/java_fixed_thread_pool_spec.rb b/spec/concurrent/executor/java_fixed_thread_pool_spec.rb index 36e724857..4ddb86cc0 100644 --- a/spec/concurrent/executor/java_fixed_thread_pool_spec.rb +++ b/spec/concurrent/executor/java_fixed_thread_pool_spec.rb @@ -23,10 +23,10 @@ module Concurrent it 'sets :overflow_policy correctly' do clazz = java.util.concurrent.ThreadPoolExecutor::DiscardPolicy policy = clazz.new - clazz.should_receive(:new).at_least(:once).with(any_args).and_return(policy) + expect(clazz).to receive(:new).at_least(:once).with(any_args).and_return(policy) subject = JavaFixedThreadPool.new(5, overflow_policy: :discard) - subject.overflow_policy.should eq :discard + expect(subject.overflow_policy).to eq :discard end end diff --git a/spec/concurrent/executor/java_thread_pool_executor_spec.rb b/spec/concurrent/executor/java_thread_pool_executor_spec.rb index 8663a78ad..ad86f4c3e 100644 --- a/spec/concurrent/executor/java_thread_pool_executor_spec.rb +++ b/spec/concurrent/executor/java_thread_pool_executor_spec.rb @@ -30,7 +30,7 @@ module Concurrent specify ':abort maps to AbortPolicy' do clazz = java.util.concurrent.ThreadPoolExecutor::AbortPolicy policy = clazz.new - clazz.should_receive(:new).at_least(:once).with(any_args).and_return(policy) + expect(clazz).to receive(:new).at_least(:once).with(any_args).and_return(policy) JavaThreadPoolExecutor.new( min_threads: 2, max_threads: 5, @@ -43,7 +43,7 @@ module Concurrent specify ':discard maps to DiscardPolicy' do clazz = java.util.concurrent.ThreadPoolExecutor::DiscardPolicy policy = clazz.new - clazz.should_receive(:new).at_least(:once).with(any_args).and_return(policy) + expect(clazz).to receive(:new).at_least(:once).with(any_args).and_return(policy) JavaThreadPoolExecutor.new( min_threads: 2, max_threads: 5, @@ -56,7 +56,7 @@ module Concurrent specify ':caller_runs maps to CallerRunsPolicy' do clazz = java.util.concurrent.ThreadPoolExecutor::CallerRunsPolicy policy = clazz.new - clazz.should_receive(:new).at_least(:once).with(any_args).and_return(policy) + expect(clazz).to receive(:new).at_least(:once).with(any_args).and_return(policy) JavaThreadPoolExecutor.new( min_threads: 2, max_threads: 5, diff --git a/spec/concurrent/executor/per_thread_executor_spec.rb b/spec/concurrent/executor/per_thread_executor_spec.rb index 5c133d59f..d5ac1ae2a 100644 --- a/spec/concurrent/executor/per_thread_executor_spec.rb +++ b/spec/concurrent/executor/per_thread_executor_spec.rb @@ -15,40 +15,40 @@ module Concurrent it 'creates a new thread for a call without arguments' do thread = Thread.new{ nil } - Thread.should_receive(:new).with(no_args()).and_return(thread) - Concurrent.configuration.global_task_pool.should_not_receive(:post).with(any_args()) + expect(Thread).to receive(:new).with(no_args()).and_return(thread) + expect(Concurrent.configuration.global_task_pool).not_to receive(:post).with(any_args()) subject.post{ nil } end it 'executes a call without arguments' do latch = CountDownLatch.new(1) subject.post{ latch.count_down } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'creates a new thread for a call with arguments' do thread = Thread.new{ nil } - Thread.should_receive(:new).with(1,2,3).and_return(thread) - Concurrent.configuration.global_task_pool.should_not_receive(:post).with(any_args()) + expect(Thread).to receive(:new).with(1,2,3).and_return(thread) + expect(Concurrent.configuration.global_task_pool).not_to receive(:post).with(any_args()) subject.post(1,2,3){ nil } end it 'executes a call with one argument' do latch = CountDownLatch.new(3) subject.post(3){|count| count.times{ latch.count_down } } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'executes a call with multiple arguments' do latch = CountDownLatch.new(10) subject.post(1,2,3,4){|*count| count.reduce(:+).times{ latch.count_down } } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'aliases #<<' do thread = Thread.new{ nil } - Thread.should_receive(:new).with(no_args()).and_return(thread) - Concurrent.configuration.global_task_pool.should_not_receive(:post).with(any_args()) + expect(Thread).to receive(:new).with(no_args()).and_return(thread) + expect(Concurrent.configuration.global_task_pool).not_to receive(:post).with(any_args()) subject << proc{ nil } end end @@ -59,40 +59,40 @@ module Concurrent it 'creates a new thread for a call without arguments' do thread = Thread.new{ nil } - Thread.should_receive(:new).with(no_args()).and_return(thread) - Concurrent.configuration.global_task_pool.should_not_receive(:post).with(any_args()) + expect(Thread).to receive(:new).with(no_args()).and_return(thread) + expect(Concurrent.configuration.global_task_pool).not_to receive(:post).with(any_args()) subject.post{ nil } end it 'executes a call without arguments' do latch = CountDownLatch.new(1) subject.post{ latch.count_down } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'creates a new thread for a call with arguments' do thread = Thread.new{ nil } - Thread.should_receive(:new).with(1,2,3).and_return(thread) - Concurrent.configuration.global_task_pool.should_not_receive(:post).with(any_args()) + expect(Thread).to receive(:new).with(1,2,3).and_return(thread) + expect(Concurrent.configuration.global_task_pool).not_to receive(:post).with(any_args()) subject.post(1,2,3){ nil } end it 'executes a call with one argument' do latch = CountDownLatch.new(3) subject.post(3){|count| count.times{ latch.count_down } } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'executes a call with multiple arguments' do latch = CountDownLatch.new(10) subject.post(1,2,3,4){|*count| count.reduce(:+).times{ latch.count_down } } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy end it 'aliases #<<' do thread = Thread.new{ nil } - Thread.should_receive(:new).with(no_args()).and_return(thread) - Concurrent.configuration.global_task_pool.should_not_receive(:post).with(any_args()) + expect(Thread).to receive(:new).with(no_args()).and_return(thread) + expect(Concurrent.configuration.global_task_pool).not_to receive(:post).with(any_args()) subject << proc{ nil } end end diff --git a/spec/concurrent/executor/ruby_cached_thread_pool_spec.rb b/spec/concurrent/executor/ruby_cached_thread_pool_spec.rb index c009c27f7..08cc7dfc4 100644 --- a/spec/concurrent/executor/ruby_cached_thread_pool_spec.rb +++ b/spec/concurrent/executor/ruby_cached_thread_pool_spec.rb @@ -27,21 +27,21 @@ module Concurrent subject.instance_variable_set(:@idletime, 1) 3.times { subject << proc{ sleep(0.1) } } sleep(0.1) - subject.length.should eq 3 + expect(subject.length).to eq 3 sleep(2) subject << proc{ nil } sleep(0.1) - subject.length.should < 3 + expect(subject.length).to be < 3 end it 'removes from pool any dead thread' do 3.times { subject << proc{ sleep(0.1); raise Exception } } sleep(0.1) - subject.length.should eq 3 + expect(subject.length).to eq 3 sleep(2) subject << proc{ nil } sleep(0.1) - subject.length.should < 3 + expect(subject.length).to be < 3 end end @@ -50,19 +50,19 @@ module Concurrent subject{ described_class.new(idletime: 1, max_threads: 5) } it 'creates new workers when there are none available' do - subject.length.should eq 0 + expect(subject.length).to eq 0 5.times{ sleep(0.1); subject << proc{ sleep(1) } } sleep(1) - subject.length.should eq 5 + expect(subject.length).to eq 5 end it 'uses existing idle threads' do 5.times{ subject << proc{ sleep(0.1) } } sleep(1) - subject.length.should >= 5 + expect(subject.length).to be >= 5 3.times{ subject << proc{ sleep(1) } } sleep(0.1) - subject.length.should >= 5 + expect(subject.length).to be >= 5 end end end diff --git a/spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb b/spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb index ba725c22f..a3c147498 100644 --- a/spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb +++ b/spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb @@ -20,7 +20,7 @@ module Concurrent count = subject.length count.times{ subject << proc{ raise StandardError } } sleep(1) - subject.length.should eq count + expect(subject.length).to eq count end end @@ -28,10 +28,10 @@ module Concurrent it 'creates new workers when there are none available' do pool = described_class.new(5) - pool.current_length.should eq 0 + expect(pool.current_length).to eq 0 5.times{ pool << proc{ sleep(1) } } sleep(0.1) - pool.current_length.should eq 5 + expect(pool.current_length).to eq 5 pool.kill end end diff --git a/spec/concurrent/executor/ruby_thread_pool_executor_spec.rb b/spec/concurrent/executor/ruby_thread_pool_executor_spec.rb index 6cff0df49..22aac73d1 100644 --- a/spec/concurrent/executor/ruby_thread_pool_executor_spec.rb +++ b/spec/concurrent/executor/ruby_thread_pool_executor_spec.rb @@ -39,13 +39,13 @@ module Concurrent it 'returns :max_length when no tasks are enqueued' do 5.times{ subject.post{ nil } } sleep(0.1) - subject.remaining_capacity.should eq expected_max + expect(subject.remaining_capacity).to eq expected_max end it 'returns the remaining capacity when tasks are enqueued' do 100.times{ subject.post{ sleep(0.5) } } sleep(0.1) - subject.remaining_capacity.should < expected_max + expect(subject.remaining_capacity).to be < expected_max end end @@ -89,7 +89,7 @@ module Concurrent end end sleep(0.2) - executed.value.should < 10 + expect(executed.value).to be < 10 end specify 'a #<< task is never executed when the queue is at capacity' do @@ -101,7 +101,7 @@ module Concurrent end end sleep(0.2) - executed.value.should < 10 + expect(executed.value).to be < 10 end end @@ -123,7 +123,7 @@ module Concurrent subject.post{ executed.increment } end sleep(0.1) - executed.value.should < 1000 + expect(executed.value).to be < 1000 end specify 'a #<< task is never executed when the queue is at capacity' do @@ -132,7 +132,7 @@ module Concurrent subject << proc { executed.increment } end sleep(0.1) - executed.value.should < 1000 + expect(executed.value).to be < 1000 end end @@ -151,11 +151,11 @@ module Concurrent specify '#post does not create any new threads when the queue is at capacity' do initial = Thread.list.length 5.times{ subject.post{ sleep(0.1) } } - Thread.list.length.should < initial + 5 + expect(Thread.list.length).to be < initial + 5 end specify '#<< executes the task on the current thread when the queue is at capacity' do - subject.should_receive(:handle_overflow).with(any_args).at_least(:once) + expect(subject).to receive(:handle_overflow).with(any_args).at_least(:once) 5.times{ subject << proc { sleep(0.1) } } end diff --git a/spec/concurrent/executor/safe_task_executor_spec.rb b/spec/concurrent/executor/safe_task_executor_spec.rb index 2adb397fa..cae393901 100644 --- a/spec/concurrent/executor/safe_task_executor_spec.rb +++ b/spec/concurrent/executor/safe_task_executor_spec.rb @@ -13,30 +13,30 @@ module Concurrent it 'should return success' do success, value, reason = subject.execute - success.should be_true + expect(success).to be_truthy end it 'should return task value' do success, value, reason = subject.execute - value.should eq 42 + expect(value).to eq 42 end it 'should return a nil reason' do success, value, reason = subject.execute - reason.should be_nil + expect(reason).to be_nil end it 'passes all arguments to #execute to the task' do expected = nil task = proc {|*args| expected = args } SafeTaskExecutor.new(task).execute(1, 2, 3) - expected.should eq [1, 2, 3] + expect(expected).to eq [1, 2, 3] end it 'protectes #execute with a mutex' do mutex = double(:mutex) - Mutex.should_receive(:new).with(no_args).and_return(mutex) - mutex.should_receive(:synchronize).with(no_args) + expect(Mutex).to receive(:new).with(no_args).and_return(mutex) + expect(mutex).to receive(:synchronize).with(no_args) subject.execute end end @@ -48,18 +48,18 @@ module Concurrent it 'should return false success' do success, value, reason = subject.execute - success.should be_false + expect(success).to be_falsey end it 'should return a nil value' do success, value, reason = subject.execute - value.should be_nil + expect(value).to be_nil end it 'should return the reason' do success, value, reason = subject.execute - reason.should be_a(StandardError) - reason.message.should eq 'an error' + expect(reason).to be_a(StandardError) + expect(reason.message).to eq 'an error' end it 'rescues Exception when :rescue_exception is true' do diff --git a/spec/concurrent/executor/thread_pool_class_cast_spec.rb b/spec/concurrent/executor/thread_pool_class_cast_spec.rb index e62b9320a..86486733b 100644 --- a/spec/concurrent/executor/thread_pool_class_cast_spec.rb +++ b/spec/concurrent/executor/thread_pool_class_cast_spec.rb @@ -5,11 +5,11 @@ module Concurrent describe SingleThreadExecutor do if jruby? it 'inherits from JavaSingleThreadExecutor' do - SingleThreadExecutor.ancestors.should include(JavaSingleThreadExecutor) + expect(SingleThreadExecutor.ancestors).to include(JavaSingleThreadExecutor) end else it 'inherits from RubySingleThreadExecutor' do - SingleThreadExecutor.ancestors.should include(RubySingleThreadExecutor) + expect(SingleThreadExecutor.ancestors).to include(RubySingleThreadExecutor) end end end @@ -17,11 +17,11 @@ module Concurrent describe ThreadPoolExecutor do if jruby? it 'inherits from JavaThreadPoolExecutor' do - ThreadPoolExecutor.ancestors.should include(JavaThreadPoolExecutor) + expect(ThreadPoolExecutor.ancestors).to include(JavaThreadPoolExecutor) end else it 'inherits from RubyThreadPoolExecutor' do - ThreadPoolExecutor.ancestors.should include(RubyThreadPoolExecutor) + expect(ThreadPoolExecutor.ancestors).to include(RubyThreadPoolExecutor) end end end @@ -29,11 +29,11 @@ module Concurrent describe CachedThreadPool do if jruby? it 'inherits from JavaCachedThreadPool' do - CachedThreadPool.ancestors.should include(JavaCachedThreadPool) + expect(CachedThreadPool.ancestors).to include(JavaCachedThreadPool) end else it 'inherits from RubyCachedThreadPool' do - CachedThreadPool.ancestors.should include(RubyCachedThreadPool) + expect(CachedThreadPool.ancestors).to include(RubyCachedThreadPool) end end end @@ -41,11 +41,11 @@ module Concurrent describe FixedThreadPool do if jruby? it 'inherits from JavaFixedThreadPool' do - FixedThreadPool.ancestors.should include(JavaFixedThreadPool) + expect(FixedThreadPool.ancestors).to include(JavaFixedThreadPool) end else it 'inherits from RubyFixedThreadPool' do - FixedThreadPool.ancestors.should include(RubyFixedThreadPool) + expect(FixedThreadPool.ancestors).to include(RubyFixedThreadPool) end end end diff --git a/spec/concurrent/executor/thread_pool_executor_shared.rb b/spec/concurrent/executor/thread_pool_executor_shared.rb index b1ae6f2ff..e3738d248 100644 --- a/spec/concurrent/executor/thread_pool_executor_shared.rb +++ b/spec/concurrent/executor/thread_pool_executor_shared.rb @@ -1,7 +1,7 @@ require 'spec_helper' require_relative 'thread_pool_shared' -share_examples_for :thread_pool_executor do +shared_examples :thread_pool_executor do after(:each) do @@ -14,39 +14,39 @@ subject { described_class.new } it 'defaults :min_length to DEFAULT_MIN_POOL_SIZE' do - subject.min_length.should eq described_class::DEFAULT_MIN_POOL_SIZE + expect(subject.min_length).to eq described_class::DEFAULT_MIN_POOL_SIZE end it 'defaults :max_length to DEFAULT_MAX_POOL_SIZE' do - subject.max_length.should eq described_class::DEFAULT_MAX_POOL_SIZE + expect(subject.max_length).to eq described_class::DEFAULT_MAX_POOL_SIZE end it 'defaults :idletime to DEFAULT_THREAD_IDLETIMEOUT' do - subject.idletime.should eq described_class::DEFAULT_THREAD_IDLETIMEOUT + expect(subject.idletime).to eq described_class::DEFAULT_THREAD_IDLETIMEOUT end it 'defaults :max_queue to DEFAULT_MAX_QUEUE_SIZE' do - subject.max_queue.should eq described_class::DEFAULT_MAX_QUEUE_SIZE + expect(subject.max_queue).to eq described_class::DEFAULT_MAX_QUEUE_SIZE end it 'defaults :overflow_policy to :abort' do - subject.overflow_policy.should eq :abort + expect(subject.overflow_policy).to eq :abort end end context "#initialize explicit values" do it "sets :min_threads" do - described_class.new(min_threads: 2).min_length.should eq 2 + expect(described_class.new(min_threads: 2).min_length).to eq 2 end it "sets :max_threads" do - described_class.new(max_threads: 2).max_length.should eq 2 + expect(described_class.new(max_threads: 2).max_length).to eq 2 end it "sets :idletime" do - described_class.new(idletime: 2).idletime.should eq 2 + expect(described_class.new(idletime: 2).idletime).to eq 2 end it "doesn't allow max_threads < min_threads" do @@ -58,7 +58,7 @@ it 'accepts all valid overflow policies' do Concurrent::RubyThreadPoolExecutor::OVERFLOW_POLICIES.each do |policy| subject = described_class.new(overflow_policy: policy) - subject.overflow_policy.should eq policy + expect(subject.overflow_policy).to eq policy end end @@ -88,13 +88,13 @@ subject{ described_class.new(max_queue: expected_max) } it 'returns the set value on creation' do - subject.max_queue.should eq expected_max + expect(subject.max_queue).to eq expected_max end it 'returns the set value when running' do 5.times{ subject.post{ sleep(0.1) } } sleep(0.1) - subject.max_queue.should eq expected_max + expect(subject.max_queue).to eq expected_max end it 'returns the set value after stopping' do @@ -102,7 +102,7 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.max_queue.should eq expected_max + expect(subject.max_queue).to eq expected_max end end @@ -119,19 +119,19 @@ end it 'returns zero on creation' do - subject.queue_length.should eq 0 + expect(subject.queue_length).to eq 0 end it 'returns zero when there are no enqueued tasks' do 5.times{ subject.post{ nil } } sleep(0.1) - subject.queue_length.should eq 0 + expect(subject.queue_length).to eq 0 end it 'returns the size of the queue when tasks are enqueued' do 100.times{ subject.post{ sleep(0.5) } } sleep(0.1) - subject.queue_length.should > 0 + expect(subject.queue_length).to be > 0 end it 'returns zero when stopped' do @@ -139,13 +139,13 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.queue_length.should eq 0 + expect(subject.queue_length).to eq 0 end it 'can never be greater than :max_queue' do 100.times{ subject.post{ sleep(0.5) } } sleep(0.1) - subject.queue_length.should <= expected_max + expect(subject.queue_length).to be <= expected_max end end @@ -156,11 +156,11 @@ it 'returns -1 when :max_queue is set to zero' do executor = described_class.new(max_queue: 0) - executor.remaining_capacity.should eq -1 + expect(executor.remaining_capacity).to eq -1 end it 'returns :max_length on creation' do - subject.remaining_capacity.should eq expected_max + expect(subject.remaining_capacity).to eq expected_max end it 'returns :max_length when stopped' do @@ -168,7 +168,7 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.remaining_capacity.should eq expected_max + expect(subject.remaining_capacity).to eq expected_max end end end diff --git a/spec/concurrent/executor/thread_pool_shared.rb b/spec/concurrent/executor/thread_pool_shared.rb index 25774d4a4..e7eb9f420 100644 --- a/spec/concurrent/executor/thread_pool_shared.rb +++ b/spec/concurrent/executor/thread_pool_shared.rb @@ -1,7 +1,7 @@ require 'spec_helper' require_relative 'executor_service_shared' -share_examples_for :thread_pool do +shared_examples :thread_pool do after(:each) do subject.kill @@ -13,7 +13,7 @@ context '#length' do it 'returns zero on creation' do - subject.length.should eq 0 + expect(subject.length).to eq 0 end it 'returns zero once shut down' do @@ -21,26 +21,26 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.length.should eq 0 + expect(subject.length).to eq 0 end it 'aliased as #current_length' do 5.times{ subject.post{ sleep(0.1) } } sleep(0.1) - subject.current_length.should eq subject.length + expect(subject.current_length).to eq subject.length end end context '#scheduled_task_count' do it 'returns zero on creation' do - subject.scheduled_task_count.should eq 0 + expect(subject.scheduled_task_count).to eq 0 end it 'returns the approximate number of tasks that have been post thus far' do 10.times{ subject.post{ nil } } sleep(0.1) - subject.scheduled_task_count.should > 0 + expect(subject.scheduled_task_count).to be > 0 end it 'returns the approximate number of tasks that were post' do @@ -48,21 +48,21 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.scheduled_task_count.should > 0 + expect(subject.scheduled_task_count).to be > 0 end end context '#completed_task_count' do it 'returns zero on creation' do - subject.completed_task_count.should eq 0 + expect(subject.completed_task_count).to eq 0 end it 'returns the approximate number of tasks that have been completed thus far' do 5.times{ subject.post{ raise StandardError } } 5.times{ subject.post{ nil } } sleep(0.1) - subject.completed_task_count.should > 0 + expect(subject.completed_task_count).to be > 0 end it 'returns the approximate number of tasks that were completed' do @@ -71,7 +71,7 @@ sleep(0.1) subject.shutdown subject.wait_for_termination(1) - subject.completed_task_count.should > 0 + expect(subject.completed_task_count).to be > 0 end end @@ -79,11 +79,11 @@ it 'allows threads to exit normally' do 10.times{ subject << proc{ nil } } - subject.length.should > 0 + expect(subject.length).to be > 0 sleep(0.1) subject.shutdown sleep(1) - subject.length.should == 0 + expect(subject.length).to eq(0) end end end diff --git a/spec/concurrent/executor/timer_set_spec.rb b/spec/concurrent/executor/timer_set_spec.rb index 1c65fadb6..7dfbfd8e2 100644 --- a/spec/concurrent/executor/timer_set_spec.rb +++ b/spec/concurrent/executor/timer_set_spec.rb @@ -10,14 +10,14 @@ module Concurrent it 'uses the executor given at construction' do executor = double(:executor) - executor.should_receive(:post).with(no_args) + expect(executor).to receive(:post).with(no_args) subject = TimerSet.new(executor: executor) subject.post(0){ nil } sleep(0.1) end it 'uses the global task pool be default' do - Concurrent.configuration.global_task_pool.should_receive(:post).with(no_args) + expect(Concurrent.configuration.global_task_pool).to receive(:post).with(no_args) subject = TimerSet.new subject.post(0){ nil } sleep(0.1) @@ -26,13 +26,13 @@ module Concurrent it 'executes a given task when given a Time' do latch = CountDownLatch.new(1) subject.post(Time.now + 0.1){ latch.count_down } - latch.wait(0.2).should be_true + expect(latch.wait(0.2)).to be_truthy end it 'executes a given task when given an interval in seconds' do latch = CountDownLatch.new(1) subject.post(0.1){ latch.count_down } - latch.wait(0.2).should be_true + expect(latch.wait(0.2)).to be_truthy end it 'passes all arguments to the task on execution' do @@ -42,12 +42,12 @@ module Concurrent expected = args latch.count_down end - latch.wait(0.2).should be_true - expected.should eq [1, 2, 3] + expect(latch.wait(0.2)).to be_truthy + expect(expected).to eq [1, 2, 3] end it 'immediately posts a task when the delay is zero' do - Thread.should_not_receive(:new).with(any_args) + expect(Thread).not_to receive(:new).with(any_args) subject.post(0){ true } end @@ -55,9 +55,9 @@ module Concurrent expected = AtomicFixnum.new(0) subject.post(0.2){ expected.increment } sleep(0.15) - expected.value.should eq 0 + expect(expected.value).to eq 0 sleep(0.10) - expected.value.should eq 1 + expect(expected.value).to eq 1 end it 'raises an exception when given a task with a past Time value' do @@ -81,14 +81,14 @@ module Concurrent it 'executes all tasks scheduled for the same time' do latch = CountDownLatch.new(5) 5.times{ subject.post(0.1){ latch.count_down } } - latch.wait(0.2).should be_true + expect(latch.wait(0.2)).to be_truthy end it 'executes tasks with different times in schedule order' do expected = [] 3.times{|i| subject.post(i/10){ expected << i } } sleep(0.3) - expected.should eq [0, 1, 2] + expect(expected).to eq [0, 1, 2] end it 'cancels all pending tasks on #shutdown' do @@ -97,7 +97,7 @@ module Concurrent sleep(0.1) subject.shutdown sleep(0.2) - expected.value.should eq 0 + expect(expected.value).to eq 0 end it 'cancels all pending tasks on #kill' do @@ -106,78 +106,78 @@ module Concurrent sleep(0.1) subject.kill sleep(0.2) - expected.value.should eq 0 + expect(expected.value).to eq 0 end it 'stops the monitor thread on #shutdown' do timer_executor = subject.instance_variable_get(:@timer_executor) subject.shutdown sleep(0.1) - timer_executor.should_not be_running + expect(timer_executor).not_to be_running end it 'kills the monitor thread on #kill' do timer_executor = subject.instance_variable_get(:@timer_executor) subject.kill sleep(0.1) - timer_executor.should_not be_running + expect(timer_executor).not_to be_running end it 'rejects tasks once shutdown' do expected = AtomicFixnum.new(0) subject.shutdown sleep(0.1) - subject.post(0){ expected.increment }.should be_false + expect(subject.post(0){ expected.increment }).to be_falsey sleep(0.1) - expected.value.should eq 0 + expect(expected.value).to eq 0 end it 'rejects tasks once killed' do expected = AtomicFixnum.new(0) subject.kill sleep(0.1) - subject.post(0){ expected.increment }.should be_false + expect(subject.post(0){ expected.increment }).to be_falsey sleep(0.1) - expected.value.should eq 0 + expect(expected.value).to eq 0 end it 'is running? when first created' do - subject.should be_running - subject.should_not be_shutdown + expect(subject).to be_running + expect(subject).not_to be_shutdown end it 'is running? after tasks have been post' do subject.post(0.1){ nil } - subject.should be_running - subject.should_not be_shutdown + expect(subject).to be_running + expect(subject).not_to be_shutdown end it 'is shutdown? after shutdown completes' do subject.shutdown sleep(0.1) - subject.should_not be_running - subject.should be_shutdown + expect(subject).not_to be_running + expect(subject).to be_shutdown end it 'is shutdown? after being killed' do subject.kill sleep(0.1) - subject.should_not be_running - subject.should be_shutdown + expect(subject).not_to be_running + expect(subject).to be_shutdown end specify '#wait_for_termination returns true if shutdown completes before timeout' do subject.post(0.1){ nil } sleep(0.1) subject.shutdown - subject.wait_for_termination(0.1).should be_true + expect(subject.wait_for_termination(0.1)).to be_truthy end specify '#wait_for_termination returns false on timeout' do subject.post(0.1){ nil } sleep(0.1) # do not call shutdown -- force timeout - subject.wait_for_termination(0.1).should be_false + expect(subject.wait_for_termination(0.1)).to be_falsey end end end diff --git a/spec/concurrent/future_spec.rb b/spec/concurrent/future_spec.rb index 326224632..497b5ad80 100644 --- a/spec/concurrent/future_spec.rb +++ b/spec/concurrent/future_spec.rb @@ -90,7 +90,7 @@ def trigger_observable(observable) let(:executor) { ImmediateExecutor.new } it 'sets the state to :unscheduled' do - Future.new(executor: executor){ nil }.should be_unscheduled + expect(Future.new(executor: executor){ nil }).to be_unscheduled end it 'raises an exception when no block given' do @@ -100,22 +100,22 @@ def trigger_observable(observable) end it 'uses the executor given with the :executor option' do - executor.should_receive(:post) + expect(executor).to receive(:post) Future.execute(executor: executor){ nil } end it 'uses the global operation pool when :operation is true' do - Concurrent.configuration.should_receive(:global_operation_pool).and_return(executor) + expect(Concurrent.configuration).to receive(:global_operation_pool).and_return(executor) Future.execute(operation: true){ nil } end it 'uses the global task pool when :task is true' do - Concurrent.configuration.should_receive(:global_task_pool).and_return(executor) + expect(Concurrent.configuration).to receive(:global_task_pool).and_return(executor) Future.execute(task: true){ nil } end it 'uses the global task pool by default' do - Concurrent.configuration.should_receive(:global_task_pool).and_return(executor) + expect(Concurrent.configuration).to receive(:global_task_pool).and_return(executor) Future.execute{ nil } end end @@ -124,7 +124,7 @@ def trigger_observable(observable) it 'does nothing unless the state is :unscheduled' do executor = ImmediateExecutor.new - executor.should_not_receive(:post).with(any_args) + expect(executor).not_to receive(:post).with(any_args) future = Future.new(executor: executor){ nil } future.instance_variable_set(:@state, :pending) future.execute @@ -135,7 +135,7 @@ def trigger_observable(observable) end it 'posts the block given on construction' do - executor.should_receive(:post).with(any_args) + expect(executor).to receive(:post).with(any_args) future = Future.new(executor: executor){ nil } future.execute end @@ -144,13 +144,13 @@ def trigger_observable(observable) latch = Concurrent::CountDownLatch.new(1) future = Future.new(executor: executor){ latch.wait(10) } future.execute - future.should be_pending + expect(future).to be_pending latch.count_down end it 'returns self' do future = Future.new(executor: executor){ nil } - future.execute.should be future + expect(future.execute).to be future end end @@ -160,19 +160,19 @@ def trigger_observable(observable) it 'creates a new Future' do future = Future.execute(executor: executor){ nil } - future.should be_a(Future) + expect(future).to be_a(Future) end it 'passes the block to the new Future' do @expected = false Future.execute(executor: executor){ @expected = true } - @expected.should be_true + expect(@expected).to be_truthy end it 'calls #execute on the new Future' do future = double('future') - Future.stub(:new).with(any_args).and_return(future) - future.should_receive(:execute).with(no_args) + allow(Future).to receive(:new).with(any_args).and_return(future) + expect(future).to receive(:execute).with(no_args) Future.execute{ nil } end end @@ -184,37 +184,37 @@ def trigger_observable(observable) it 'passes all arguments to handler' do @expected = false Future.new(executor: executor){ @expected = true }.execute - @expected.should be_true + expect(@expected).to be_truthy end it 'sets the value to the result of the handler' do future = Future.new(executor: executor){ 42 }.execute - future.value.should eq 42 + expect(future.value).to eq 42 end it 'sets the state to :fulfilled when the block completes' do future = Future.new(executor: executor){ 42 }.execute - future.should be_fulfilled + expect(future).to be_fulfilled end it 'sets the value to nil when the handler raises an exception' do future = Future.new(executor: executor){ raise StandardError }.execute - future.value.should be_nil + expect(future.value).to be_nil end it 'sets the state to :rejected when the handler raises an exception' do future = Future.new(executor: executor){ raise StandardError }.execute - future.should be_rejected + expect(future).to be_rejected end context 'aliases' do it 'aliases #realized? for #fulfilled?' do - subject.should be_realized + expect(subject).to be_realized end it 'aliases #deref for #value' do - subject.deref.should eq value + expect(subject.deref).to eq value end end end @@ -244,8 +244,8 @@ def trigger_observable(observable) future.execute - observer.value.should == 42 - observer.reason.should be_nil + expect(observer.value).to eq(42) + expect(observer.reason).to be_nil end it 'notifies all observers on rejection' do @@ -254,46 +254,46 @@ def trigger_observable(observable) future.execute - observer.value.should be_nil - observer.reason.should be_a(StandardError) + expect(observer.value).to be_nil + expect(observer.reason).to be_a(StandardError) end it 'notifies an observer added after fulfillment' do future = Future.new(executor: executor){ 42 }.execute future.add_observer(observer) - observer.value.should == 42 + expect(observer.value).to eq(42) end it 'notifies an observer added after rejection' do future = Future.new(executor: executor){ raise StandardError }.execute future.add_observer(observer) - observer.reason.should be_a(StandardError) + expect(observer.reason).to be_a(StandardError) end it 'does not notify existing observers when a new observer added after fulfillment' do future = Future.new(executor: executor){ 42 }.execute future.add_observer(observer) - observer.count.should == 1 + expect(observer.count).to eq(1) o2 = clazz.new future.add_observer(o2) - observer.count.should == 1 - o2.value.should == 42 + expect(observer.count).to eq(1) + expect(o2.value).to eq(42) end it 'does not notify existing observers when a new observer added after rejection' do future = Future.new(executor: executor){ raise StandardError }.execute future.add_observer(observer) - observer.count.should == 1 + expect(observer.count).to eq(1) o2 = clazz.new future.add_observer(o2) - observer.count.should == 1 - o2.reason.should be_a(StandardError) + expect(observer.count).to eq(1) + expect(o2.reason).to be_a(StandardError) end context 'deadlock avoidance' do @@ -314,7 +314,7 @@ def reentrant_observer(future) future.add_observer(obs) future.execute - obs.value.should eq 42 + expect(obs.value).to eq 42 end it 'should notify a new observer added after fulfillment outside lock' do @@ -323,7 +323,7 @@ def reentrant_observer(future) future.add_observer(obs) - obs.value.should eq 42 + expect(obs.value).to eq 42 end end end diff --git a/spec/concurrent/ivar_spec.rb b/spec/concurrent/ivar_spec.rb index 968b77db4..b2f24983e 100644 --- a/spec/concurrent/ivar_spec.rb +++ b/spec/concurrent/ivar_spec.rb @@ -76,17 +76,17 @@ def trigger_observable(observable) it 'does not have to set an initial value' do i = IVar.new - i.should be_incomplete + expect(i).to be_incomplete end it 'does not set an initial value if you pass NO_VALUE' do i = IVar.new(IVar::NO_VALUE) - i.should be_incomplete + expect(i).to be_incomplete end it 'can set an initial value' do i = IVar.new(14) - i.should be_completed + expect(i).to be_completed end end @@ -96,25 +96,25 @@ def trigger_observable(observable) it 'sets the state to be fulfilled' do i = IVar.new i.set(14) - i.should be_fulfilled + expect(i).to be_fulfilled end it 'sets the value' do i = IVar.new i.set(14) - i.value.should eq 14 + expect(i.value).to eq 14 end it 'raises an exception if set more than once' do i = IVar.new i.set(14) expect {i.set(2)}.to raise_error(Concurrent::MultipleAssignmentError) - i.value.should eq 14 + expect(i.value).to eq 14 end it 'returns self' do i = IVar.new - i.set(42).should eq i + expect(i.set(42)).to eq i end end @@ -123,31 +123,31 @@ def trigger_observable(observable) it 'sets the state to be rejected' do i = IVar.new i.fail - i.should be_rejected + expect(i).to be_rejected end it 'sets the value to be nil' do i = IVar.new i.fail - i.value.should be_nil + expect(i.value).to be_nil end it 'raises an exception if set more than once' do i = IVar.new i.fail expect {i.fail}.to raise_error(Concurrent::MultipleAssignmentError) - i.value.should be_nil + expect(i.value).to be_nil end it 'defaults the reason to a StandardError' do i = IVar.new i.fail - i.reason.should be_a StandardError + expect(i.reason).to be_a StandardError end it 'returns self' do i = IVar.new - i.fail.should eq i + expect(i.fail).to eq i end end @@ -174,8 +174,8 @@ def trigger_observable(observable) i.set(42) - observer.value.should == 42 - observer.reason.should be_nil + expect(observer.value).to eq(42) + expect(observer.reason).to be_nil end context 'deadlock avoidance' do @@ -196,7 +196,7 @@ def reentrant_observer(i) i.add_observer(obs) i.set(42) - obs.value.should eq 42 + expect(obs.value).to eq 42 end it 'should notify a new observer added after fulfillment outside lock' do @@ -206,7 +206,7 @@ def reentrant_observer(i) i.add_observer(obs) - obs.value.should eq 42 + expect(obs.value).to eq 42 end end diff --git a/spec/concurrent/mvar_spec.rb b/spec/concurrent/mvar_spec.rb index ab3089a7c..e9a1095d5 100644 --- a/spec/concurrent/mvar_spec.rb +++ b/spec/concurrent/mvar_spec.rb @@ -20,22 +20,22 @@ def dereferenceable_subject(value, opts = {}) it 'accepts no initial value' do m = MVar.new - m.should be_empty + expect(m).to be_empty end it 'accepts an empty initial value' do m = MVar.new(MVar::EMPTY) - m.should be_empty + expect(m).to be_empty end it 'accepts an initial value' do m = MVar.new(14) - m.should_not be_empty + expect(m).not_to be_empty end it 'accepts a nil initial value' do m = MVar.new(nil) - m.should_not be_empty + expect(m).not_to be_empty end end @@ -45,12 +45,12 @@ def dereferenceable_subject(value, opts = {}) it 'sets the MVar to empty' do m = MVar.new(14) m.take - m.should be_empty + expect(m).to be_empty end it 'returns the value on a full MVar' do m = MVar.new(14) - m.take.should eq 14 + expect(m.take).to eq 14 end it 'waits for another thread to #put' do @@ -61,12 +61,12 @@ def dereferenceable_subject(value, opts = {}) m.put 14 } - m.take.should eq 14 + expect(m.take).to eq 14 end it 'returns TIMEOUT on timeout on an empty MVar' do m = MVar.new - m.take(0.1).should eq MVar::TIMEOUT + expect(m.take(0.1)).to eq MVar::TIMEOUT end end @@ -76,13 +76,13 @@ def dereferenceable_subject(value, opts = {}) it 'sets the MVar to be empty' do m = MVar.new(14) m.take - m.should be_empty + expect(m).to be_empty end it 'sets a new value on an empty MVar' do m = MVar.new m.put 14 - m.take.should eq 14 + expect(m.take).to eq 14 end it 'waits for another thread to #take' do @@ -93,17 +93,17 @@ def dereferenceable_subject(value, opts = {}) m.take } - m.put(14).should eq 14 + expect(m.put(14)).to eq 14 end it 'returns TIMEOUT on timeout on a full MVar' do m = MVar.new(14) - m.put(14, 0.1).should eq MVar::TIMEOUT + expect(m.put(14, 0.1)).to eq MVar::TIMEOUT end it 'returns the value' do m = MVar.new - m.put(14).should eq 14 + expect(m.put(14)).to eq 14 end end @@ -112,12 +112,12 @@ def dereferenceable_subject(value, opts = {}) it 'returns true on an empty MVar' do m = MVar.new - m.should be_empty + expect(m).to be_empty end it 'returns false on a full MVar' do m = MVar.new(14) - m.should_not be_empty + expect(m).not_to be_empty end end @@ -126,12 +126,12 @@ def dereferenceable_subject(value, opts = {}) it 'returns false on an empty MVar' do m = MVar.new - m.should_not be_full + expect(m).not_to be_full end it 'returns true on a full MVar' do m = MVar.new(14) - m.should be_full + expect(m).to be_full end end @@ -146,12 +146,12 @@ def dereferenceable_subject(value, opts = {}) it 'modifies a full MVar' do m = MVar.new(14) m.modify{ |v| v + 2 } - m.take.should eq 16 + expect(m.take).to eq 16 end it 'returns the unmodified value' do m = MVar.new(14) - m.modify{ |v| v + 2 }.should eq 14 + expect(m.modify{ |v| v + 2 }).to eq 14 end it 'waits for another thread to #put' do @@ -162,7 +162,7 @@ def dereferenceable_subject(value, opts = {}) m.put 14 } - m.modify{ |v| v + 2 }.should eq 14 + expect(m.modify{ |v| v + 2 }).to eq 14 end it 'is atomic' do @@ -179,13 +179,13 @@ def dereferenceable_subject(value, opts = {}) } sleep(0.1) - m.put(2, 0.5).should eq MVar::TIMEOUT - m.take.should eq 1 + expect(m.put(2, 0.5)).to eq MVar::TIMEOUT + expect(m.take).to eq 1 end it 'returns TIMEOUT on timeout on an empty MVar' do m = MVar.new - m.modify(0.1){ |v| v + 2 }.should eq MVar::TIMEOUT + expect(m.modify(0.1){ |v| v + 2 }).to eq MVar::TIMEOUT end end @@ -194,18 +194,18 @@ def dereferenceable_subject(value, opts = {}) it 'returns true an empty MVar' do m = MVar.new - m.try_put!(14).should eq true + expect(m.try_put!(14)).to eq true end it 'returns false on a full MVar' do m = MVar.new(14) - m.try_put!(14).should eq false + expect(m.try_put!(14)).to eq false end it 'sets an empty MVar to be full' do m = MVar.new m.try_put! 14 - m.should be_full + expect(m).to be_full end end @@ -214,18 +214,18 @@ def dereferenceable_subject(value, opts = {}) it 'returns EMPTY an empty MVar' do m = MVar.new - m.try_take!.should eq MVar::EMPTY + expect(m.try_take!).to eq MVar::EMPTY end it 'returns the value on a full MVar' do m = MVar.new(14) - m.try_take!.should eq 14 + expect(m.try_take!).to eq 14 end it 'sets a full MVar to be empty' do m = MVar.new(14) m.try_take! - m.should be_empty + expect(m).to be_empty end end @@ -235,24 +235,24 @@ def dereferenceable_subject(value, opts = {}) it 'sets an empty MVar to be full' do m = MVar.new m.set! 14 - m.should be_full + expect(m).to be_full end it 'sets a full MVar to be full' do m = MVar.new(2) m.set! 14 - m.should be_full - m.take.should eq 14 + expect(m).to be_full + expect(m.take).to eq 14 end it 'returns EMPTY on an empty MVar' do m = MVar.new - m.set!(2).should eq MVar::EMPTY + expect(m.set!(2)).to eq MVar::EMPTY end it 'returns the original value on a full MVar' do m = MVar.new(14) - m.set!(2).should eq 14 + expect(m.set!(2)).to eq 14 end end @@ -267,30 +267,30 @@ def dereferenceable_subject(value, opts = {}) it 'modifies a full MVar' do m = MVar.new(14) m.modify!{ |v| v + 2 } - m.take.should eq 16 + expect(m.take).to eq 16 end it 'modifies an empty MVar' do m = MVar.new m.modify!{ |v| 14 } - m.take.should eq 14 + expect(m.take).to eq 14 end it 'can be used to set a full MVar to empty' do m = MVar.new(14) m.modify!{ |v| MVar::EMPTY } - m.should be_empty + expect(m).to be_empty end it 'can be used to set an empty MVar to empty' do m = MVar.new m.modify!{ |v| MVar::EMPTY } - m.should be_empty + expect(m).to be_empty end it 'returns the unmodified value' do m = MVar.new(14) - m.modify!{ |v| v + 2 }.should eq 14 + expect(m.modify!{ |v| v + 2 }).to eq 14 end end @@ -313,7 +313,7 @@ def m.simulate_spurious_wake_up Thread.new { sleep(0.5); m.put 14 } Thread.new { sleep(0.1); m.simulate_spurious_wake_up } - m.take.should eq 14 + expect(m.take).to eq 14 end it 'returns TIMEOUT on timeout on an empty MVar' do @@ -322,9 +322,9 @@ def m.simulate_spurious_wake_up sleep(0.1) Thread.new { m.simulate_spurious_wake_up } sleep(0.1) - result.should be_nil + expect(result).to be_nil sleep(0.2) - result.should eq MVar::TIMEOUT + expect(result).to eq MVar::TIMEOUT end end @@ -334,7 +334,7 @@ def m.simulate_spurious_wake_up Thread.new { sleep(0.5); m.put 14 } Thread.new { sleep(0.1); m.simulate_spurious_wake_up } - m.modify{ |v| v + 2 }.should eq 14 + expect(m.modify{ |v| v + 2 }).to eq 14 end it 'returns TIMEOUT on timeout on an empty MVar' do @@ -343,9 +343,9 @@ def m.simulate_spurious_wake_up sleep(0.1) Thread.new { m.simulate_spurious_wake_up } sleep(0.1) - result.should be_nil + expect(result).to be_nil sleep(0.2) - result.should eq MVar::TIMEOUT + expect(result).to eq MVar::TIMEOUT end end @@ -357,7 +357,7 @@ def m.simulate_spurious_wake_up Thread.new { sleep(0.5); m.take } Thread.new { sleep(0.1); m.simulate_spurious_wake_up } - m.put(14).should eq 14 + expect(m.put(14)).to eq 14 end it 'returns TIMEOUT on timeout on a full MVar' do @@ -366,9 +366,9 @@ def m.simulate_spurious_wake_up sleep(0.1) Thread.new { m.simulate_spurious_wake_up } sleep(0.1) - result.should be_nil + expect(result).to be_nil sleep(0.2) - result.should eq MVar::TIMEOUT + expect(result).to eq MVar::TIMEOUT end end diff --git a/spec/concurrent/obligation_shared.rb b/spec/concurrent/obligation_shared.rb index 7d5d817c2..ea7d07408 100644 --- a/spec/concurrent/obligation_shared.rb +++ b/spec/concurrent/obligation_shared.rb @@ -1,25 +1,25 @@ require 'spec_helper' -share_examples_for :obligation do +shared_examples :obligation do context '#state' do it 'is :pending when first created' do f = pending_subject - f.state.should == :pending - f.should be_pending + expect(f.state).to eq(:pending) + expect(f).to be_pending end it 'is :fulfilled when the handler completes' do f = fulfilled_subject - f.state.should == :fulfilled - f.should be_fulfilled + expect(f.state).to eq(:fulfilled) + expect(f).to be_fulfilled end it 'is :rejected when the handler raises an exception' do f = rejected_subject - f.state.should == :rejected - f.should be_rejected + expect(f.state).to eq(:rejected) + expect(f).to be_rejected end end @@ -30,73 +30,73 @@ it 'returns nil when reaching the optional timeout value' do if supports_timeout f = pending_subject - f.value(0).should be_nil - f.should be_pending + expect(f.value(0)).to be_nil + expect(f).to be_pending end end it 'returns immediately when timeout is zero' do if supports_timeout - Concurrent.should_not_receive(:timeout).with(any_args()) + expect(Concurrent).not_to receive(:timeout).with(any_args()) f = pending_subject - f.value(0).should be_nil - f.should be_pending + expect(f.value(0)).to be_nil + expect(f).to be_pending end end it 'returns the value when fulfilled before timeout' do if supports_timeout f = pending_subject - f.value(10).should be_true - f.should be_fulfilled + expect(f.value(10)).to be_truthy + expect(f).to be_fulfilled end end it 'returns nil when timeout reached' do if supports_timeout f = pending_subject - f.value(0.1).should be_nil - f.should be_pending + expect(f.value(0.1)).to be_nil + expect(f).to be_pending end end it 'is nil when :pending' do if supports_timeout expected = pending_subject.value(0) - expected.should be_nil + expect(expected).to be_nil end end it 'blocks the caller when :pending and timeout is nil' do f = pending_subject - f.value.should be_true - f.should be_fulfilled + expect(f.value).to be_truthy + expect(f).to be_fulfilled end it 'is nil when :rejected' do expected = rejected_subject.value - expected.should be_nil + expect(expected).to be_nil end it 'is set to the return value of the block when :fulfilled' do expected = fulfilled_subject.value - expected.should eq fulfilled_value + expect(expected).to eq fulfilled_value end end context '#reason' do it 'is nil when :pending' do - pending_subject.reason.should be_nil + expect(pending_subject.reason).to be_nil end it 'is nil when :fulfilled' do - fulfilled_subject.reason.should be_nil + expect(fulfilled_subject.reason).to be_nil end it 'is set to error object of the exception when :rejected' do - rejected_subject.reason.should be_a(Exception) - rejected_subject.reason.to_s.should =~ /#{rejected_reason}/ + expect(rejected_subject.reason).to be_a(Exception) + expect(rejected_subject.reason.to_s).to match(/#{rejected_reason}/) end end end diff --git a/spec/concurrent/obligation_spec.rb b/spec/concurrent/obligation_spec.rb index abfb3fcc5..b855d324a 100644 --- a/spec/concurrent/obligation_spec.rb +++ b/spec/concurrent/obligation_spec.rb @@ -21,13 +21,14 @@ def initialize let (:obligation) { obligation_class.new } let (:event) { double 'event' } - share_examples_for :incomplete do + shared_examples :incomplete do + it 'should be not completed' do - obligation.should_not be_completed + expect(obligation).not_to be_completed end it 'should be incomplete' do - obligation.should be_incomplete + expect(obligation).to be_incomplete end methods = [:value, :value!, :no_error!] @@ -35,19 +36,24 @@ def initialize describe "##{method}" do it 'should return immediately if timeout is zero' do - obligation.send(method, 0).should(method == :no_error! ? eq(obligation) : be_nil) + result = obligation.send(method, 0) + if method == :no_error! + expect(result).to eq obligation + else + expect(result).to be_nil + end end it 'should block on the event if timeout is not set' do - obligation.stub(:event).and_return(event) - event.should_receive(:wait).with(nil) + allow(obligation).to receive(:event).and_return(event) + expect(event).to receive(:wait).with(nil) obligation.send method end it 'should block on the event if timeout is not zero' do - obligation.stub(:event).and_return(event) - event.should_receive(:wait).with(5) + allow(obligation).to receive(:event).and_return(event) + expect(event).to receive(:wait).with(5) obligation.send(method, 5) end @@ -71,33 +77,33 @@ def initialize before(:each) do obligation.state = :fulfilled obligation.send(:value=, 42) - obligation.stub(:event).and_return(event) + allow(obligation).to receive(:event).and_return(event) end it 'should be completed' do - obligation.should be_completed + expect(obligation).to be_completed end it 'should be not incomplete' do - obligation.should_not be_incomplete + expect(obligation).not_to be_incomplete end describe '#value' do it 'should return immediately if timeout is zero' do - obligation.value(0).should eq 42 + expect(obligation.value(0)).to eq 42 end it 'should return immediately if timeout is not set' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.value.should eq 42 + expect(obligation.value).to eq 42 end it 'should return immediately if timeout is not zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.value(5).should eq 42 + expect(obligation.value(5)).to eq 42 end end @@ -105,19 +111,19 @@ def initialize describe '#value!' do it 'should return immediately if timeout is zero' do - obligation.value!(0).should eq 42 + expect(obligation.value!(0)).to eq 42 end it 'should return immediately if timeout is not set' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.value!.should eq 42 + expect(obligation.value!).to eq 42 end it 'should return immediately if timeout is not zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.value!(5).should eq 42 + expect(obligation.value!(5)).to eq 42 end end @@ -125,19 +131,19 @@ def initialize describe '#no_error!' do it 'should return immediately if timeout is zero' do - obligation.no_error!(0).should eq obligation + expect(obligation.no_error!(0)).to eq obligation end it 'should return immediately if timeout is not set' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.no_error!.should eq obligation + expect(obligation.no_error!).to eq obligation end it 'should return immediately if timeout is not zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.no_error!(5).should eq obligation + expect(obligation.no_error!(5)).to eq obligation end end @@ -148,36 +154,36 @@ def initialize before(:each) do obligation.state = :rejected - obligation.stub(:event).and_return(event) + allow(obligation).to receive(:event).and_return(event) end it 'should be completed' do - obligation.should be_completed + expect(obligation).to be_completed end it 'should be not incomplete' do - obligation.should_not be_incomplete + expect(obligation).not_to be_incomplete end describe '#value' do it 'should return immediately if timeout is zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.value(0).should be_nil + expect(obligation.value(0)).to be_nil end it 'should return immediately if timeout is not set' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.value.should be_nil + expect(obligation.value).to be_nil end it 'should return immediately if timeout is not zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - obligation.value(5).should be_nil + expect(obligation.value(5)).to be_nil end end @@ -185,21 +191,21 @@ def initialize describe '#value!' do it 'should return immediately if timeout is zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - -> { obligation.value!(0) }.should raise_error + expect { obligation.value!(0) }.to raise_error end it 'should return immediately if timeout is not set' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - -> { obligation.value! }.should raise_error + expect { obligation.value! }.to raise_error end it 'should return immediately if timeout is not zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - -> { obligation.value!(5) }.should raise_error + expect { obligation.value!(5) }.to raise_error end end @@ -207,21 +213,21 @@ def initialize describe '#no_error!' do it 'should return immediately if timeout is zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - -> { obligation.no_error!(0) }.should raise_error + expect { obligation.no_error!(0) }.to raise_error end it 'should return immediately if timeout is not set' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - -> { obligation.no_error! }.should raise_error + expect { obligation.no_error! }.to raise_error end it 'should return immediately if timeout is not zero' do - event.should_not_receive(:wait) + expect(event).not_to receive(:wait) - -> { obligation.no_error!(5) }.should raise_error + expect { obligation.no_error!(5) }.to raise_error end end @@ -234,23 +240,23 @@ def initialize context 'unexpected state' do it 'should return false if state is not the expected one' do - obligation.compare_and_set_state(:pending, :rejected).should be_false + expect(obligation.compare_and_set_state(:pending, :rejected)).to be_falsey end it 'should not change the state if current is not the expected one' do obligation.compare_and_set_state(:pending, :rejected) - obligation.state.should eq :unscheduled + expect(obligation.state).to eq :unscheduled end end context 'expected state' do it 'should return true if state is the expected one' do - obligation.compare_and_set_state(:pending, :unscheduled).should be_true + expect(obligation.compare_and_set_state(:pending, :unscheduled)).to be_truthy end it 'should not change the state if current is not the expected one' do obligation.compare_and_set_state(:pending, :unscheduled) - obligation.state.should eq :pending + expect(obligation.state).to eq :pending end end @@ -265,15 +271,15 @@ def initialize end it 'should return false if state is not expected' do - obligation.if_state(:pending, :rejected) { 42 }.should be_false + expect(obligation.if_state(:pending, :rejected) { 42 }).to be_falsey end it 'should the block value if state is expected' do - obligation.if_state(:rejected, :unscheduled) { 42 }.should eq 42 + expect(obligation.if_state(:rejected, :unscheduled) { 42 }).to eq 42 end it 'should execute the block within the mutex' do - obligation.if_state(:unscheduled) { obligation.mutex.should be_locked } + obligation.if_state(:unscheduled) { expect(obligation.mutex).to be_locked } end end diff --git a/spec/concurrent/observable_shared.rb b/spec/concurrent/observable_shared.rb index 3e3482801..65e6d0141 100644 --- a/spec/concurrent/observable_shared.rb +++ b/spec/concurrent/observable_shared.rb @@ -1,6 +1,6 @@ require 'spec_helper' -share_examples_for :observable do +shared_examples :observable do let(:observer_set) do subject.instance_variable_get(:@observers) @@ -37,18 +37,18 @@ def notify(*args) context '#add_observer' do it 'adds an observer if called before first notification' do - observer_set.should_receive(:add_observer).with(any_args) + expect(observer_set).to receive(:add_observer).with(any_args) subject.add_observer(observer) end it 'adds an observer with :func if called before first notification' do - observer_set.should_receive(:add_observer).with(observer_with_func, :notify) + expect(observer_set).to receive(:add_observer).with(observer_with_func, :notify) subject.add_observer(observer_with_func, observer_func) end it 'creates an observer from a block if called before first notification' do block = proc{ nil } - observer_set.should_receive(:add_observer).with(any_args) + expect(observer_set).to receive(:add_observer).with(any_args) subject.add_observer(&block) end @@ -68,20 +68,20 @@ def notify(*args) context '#delete_observer' do it 'deletes the given observer if called before first notification' do - subject.count_observers.should eq 0 + expect(subject.count_observers).to eq 0 subject.add_observer(observer) - subject.count_observers.should eq 1 + expect(subject.count_observers).to eq 1 subject.delete_observer(observer) - subject.count_observers.should eq 0 + expect(subject.count_observers).to eq 0 end it 'returns the removed observer if found in the observer set' do subject.add_observer(observer) - subject.delete_observer(observer).should eq observer + expect(subject.delete_observer(observer)).to eq observer end it 'returns the given observer even when not found in the observer set' do - subject.delete_observer(observer).should eq observer + expect(subject.delete_observer(observer)).to eq observer end end @@ -89,31 +89,31 @@ def notify(*args) it 'deletes all observers when called before first notification' do 5.times{ subject.add_observer(observer_class.new) } - subject.count_observers.should eq 5 + expect(subject.count_observers).to eq 5 subject.delete_observers - subject.count_observers.should eq 0 + expect(subject.count_observers).to eq 0 end it 'returns self' do - subject.delete_observers.should eq subject + expect(subject.delete_observers).to eq subject end end context '#count_observers' do it 'returns zero for a new observable object' do - subject.count_observers.should eq 0 + expect(subject.count_observers).to eq 0 end it 'returns a count of registered observers if called before first notification' do 5.times{ subject.add_observer(observer_class.new) } - subject.count_observers.should eq 5 + expect(subject.count_observers).to eq 5 end it 'returns zero after #delete_observers has been called' do 5.times{ subject.add_observer(observer_class.new) } subject.delete_observers - subject.count_observers.should eq 0 + expect(subject.count_observers).to eq 0 end end @@ -125,7 +125,7 @@ def notify(*args) subject.add_observer(observer_class.new{ latch.count_down }) end trigger_observable(subject) - latch.count.should eq 0 + expect(latch.count).to eq 0 end it 'calls the appropriate function on all observers which specified a :func' do @@ -136,7 +136,7 @@ def notify(*args) end trigger_observable(subject) latch.wait(1) - latch.count.should eq 0 + expect(latch.count).to eq 0 end it 'calls the proc for all observers added as a block' do @@ -146,7 +146,7 @@ def notify(*args) end trigger_observable(subject) latch.wait(1) - latch.count.should eq 0 + expect(latch.count).to eq 0 end it 'does not notify any observers removed with #delete_observer' do @@ -158,7 +158,7 @@ def notify(*args) trigger_observable(subject) latch.wait(1) - latch.count.should eq 5 + expect(latch.count).to eq 5 end it 'does not notify any observers after #delete_observers called' do @@ -171,7 +171,7 @@ def notify(*args) trigger_observable(subject) latch.wait(1) - latch.count.should eq 5 + expect(latch.count).to eq 5 end end end diff --git a/spec/concurrent/observable_spec.rb b/spec/concurrent/observable_spec.rb index 2010760b1..b76e35636 100644 --- a/spec/concurrent/observable_spec.rb +++ b/spec/concurrent/observable_spec.rb @@ -19,37 +19,37 @@ module Concurrent end it 'does not initialize set by by default' do - described_class.new.observers.should be_nil + expect(described_class.new.observers).to be_nil end it 'uses the given observer set' do expected = CopyOnWriteObserverSet.new subject.observers = expected - subject.observers.should eql expected + expect(subject.observers).to eql expected end it 'delegates #add_observer' do - observer_set.should_receive(:add_observer).with(:observer).and_return { |v| v } - subject.add_observer(:observer).should eq :observer + expect(observer_set).to receive(:add_observer).with(:observer) { |v| v } + expect(subject.add_observer(:observer)).to eq :observer end it 'delegates #with_observer' do - observer_set.should_receive(:add_observer).with(:observer).and_return { |v| v } - subject.with_observer(:observer).should eq subject + expect(observer_set).to receive(:add_observer).with(:observer) { |v| v } + expect(subject.with_observer(:observer)).to eq subject end it 'delegates #delete_observer' do - observer_set.should_receive(:delete_observer).with(:observer) + expect(observer_set).to receive(:delete_observer).with(:observer) subject.delete_observer(:observer) end it 'delegates #delete_observers' do - observer_set.should_receive(:delete_observers).with(no_args) + expect(observer_set).to receive(:delete_observers).with(no_args) subject.delete_observers end it 'delegates #count_observers' do - observer_set.should_receive(:count_observers).with(no_args) + expect(observer_set).to receive(:count_observers).with(no_args) subject.count_observers end end diff --git a/spec/concurrent/options_parser_spec.rb b/spec/concurrent/options_parser_spec.rb index 72dba25d0..cd889b0d4 100644 --- a/spec/concurrent/options_parser_spec.rb +++ b/spec/concurrent/options_parser_spec.rb @@ -12,57 +12,57 @@ module Concurrent context '#get_executor_from' do it 'returns the given :executor' do - OptionsParser::get_executor_from(executor: executor).should eq executor + expect(OptionsParser::get_executor_from(executor: executor)).to eq executor end it 'returns the global operation pool when :operation is true' do - Concurrent.configuration.should_receive(:global_operation_pool). + expect(Concurrent.configuration).to receive(:global_operation_pool). and_return(:operation_pool) OptionsParser::get_executor_from(operation: true) end it 'returns the global task pool when :operation is false' do - Concurrent.configuration.should_receive(:global_task_pool). + expect(Concurrent.configuration).to receive(:global_task_pool). and_return(:task_pool) OptionsParser::get_executor_from(operation: false) end it 'returns the global operation pool when :task is false' do - Concurrent.configuration.should_receive(:global_operation_pool). + expect(Concurrent.configuration).to receive(:global_operation_pool). and_return(:operation_pool) OptionsParser::get_executor_from(task: false) end it 'returns the global task pool when :task is true' do - Concurrent.configuration.should_receive(:global_task_pool). + expect(Concurrent.configuration).to receive(:global_task_pool). and_return(:task_pool) OptionsParser::get_executor_from(task: true) end it 'returns the global task pool when :executor is nil' do - Concurrent.configuration.should_receive(:global_task_pool). + expect(Concurrent.configuration).to receive(:global_task_pool). and_return(:task_pool) OptionsParser::get_executor_from(executor: nil) end it 'returns the global task pool when no option is given' do - Concurrent.configuration.should_receive(:global_task_pool). + expect(Concurrent.configuration).to receive(:global_task_pool). and_return(:task_pool) OptionsParser::get_executor_from end specify ':executor overrides :operation' do - OptionsParser::get_executor_from(executor: executor, operation: true). - should eq executor + expect(OptionsParser::get_executor_from(executor: executor, operation: true)). + to eq executor end specify ':executor overrides :task' do - OptionsParser::get_executor_from(executor: executor, task: true). - should eq executor + expect(OptionsParser::get_executor_from(executor: executor, task: true)). + to eq executor end specify ':operation overrides :task' do - Concurrent.configuration.should_receive(:global_operation_pool). + expect(Concurrent.configuration).to receive(:global_operation_pool). and_return(:operation_pool) OptionsParser::get_executor_from(operation: true, task: true) end diff --git a/spec/concurrent/promise_spec.rb b/spec/concurrent/promise_spec.rb index ed952edc6..86072e548 100644 --- a/spec/concurrent/promise_spec.rb +++ b/spec/concurrent/promise_spec.rb @@ -27,7 +27,7 @@ module Concurrent it 'includes Dereferenceable' do promise = Promise.new{ nil } - promise.should be_a(Dereferenceable) + expect(promise).to be_a(Dereferenceable) end context 'initializers' do @@ -36,15 +36,15 @@ module Concurrent subject { Promise.fulfill(10) } it 'should return a Promise' do - subject.should be_a Promise + expect(subject).to be_a Promise end it 'should return a fulfilled Promise' do - subject.should be_fulfilled + expect(subject).to be_fulfilled end it 'should return a Promise with set value' do - subject.value.should eq 10 + expect(subject.value).to eq 10 end end @@ -54,41 +54,41 @@ module Concurrent subject { Promise.reject(reason) } it 'should return a Promise' do - subject.should be_a Promise + expect(subject).to be_a Promise end it 'should return a rejected Promise' do - subject.should be_rejected + expect(subject).to be_rejected end it 'should return a Promise with set reason' do - subject.reason.should be reason + expect(subject.reason).to be reason end end describe '.new' do it 'should return an unscheduled Promise' do p = Promise.new(executor: executor){ nil } - p.should be_unscheduled + expect(p).to be_unscheduled end end describe '.execute' do it 'creates a new Promise' do p = Promise.execute(executor: executor){ nil } - p.should be_a(Promise) + expect(p).to be_a(Promise) end it 'passes the block to the new Promise' do p = Promise.execute(executor: executor){ 20 } sleep(0.1) - p.value.should eq 20 + expect(p.value).to eq 20 end it 'calls #execute on the new Promise' do p = double('promise') - Promise.stub(:new).with({executor: executor}).and_return(p) - p.should_receive(:execute).with(no_args) + allow(Promise).to receive(:new).with({executor: executor}).and_return(p) + expect(p).to receive(:execute).with(no_args) Promise.execute(executor: executor){ nil } end end @@ -100,11 +100,11 @@ module Concurrent it 'sets the promise to :pending' do p = Promise.new(executor: executor){ sleep(0.1) }.execute - p.should be_pending + expect(p).to be_pending end it 'posts the block given in construction' do - executor.should_receive(:post).with(any_args) + expect(executor).to receive(:post).with(any_args) Promise.new(executor: executor){ nil }.execute end end @@ -113,11 +113,11 @@ module Concurrent it 'sets the promise to :pending' do p = pending_subject.execute - p.should be_pending + expect(p).to be_pending end it 'does not posts again' do - executor.should_receive(:post).with(any_args).once + expect(executor).to receive(:post).with(any_args).once pending_subject.execute end end @@ -133,10 +133,10 @@ module Concurrent it 'should set all promises to :pending' do root.execute - c1.should be_pending - c2.should be_pending - c2_1.should be_pending - [root, c1, c2, c2_1].each { |p| p.should be_pending } + expect(c1).to be_pending + expect(c2).to be_pending + expect(c2_1).to be_pending + [root, c1, c2, c2_1].each { |p| expect(p).to be_pending } end end @@ -144,7 +144,7 @@ module Concurrent it 'should set all promises to :pending' do c2_1.execute - [root, c1, c2, c2_1].each { |p| p.should be_pending } + [root, c1, c2, c2_1].each { |p| expect(p).to be_pending } end end end @@ -154,20 +154,20 @@ module Concurrent it 'returns a new promise when a block is passed' do child = empty_root.then { nil } - child.should be_a Promise - child.should_not be empty_root + expect(child).to be_a Promise + expect(child).not_to be empty_root end it 'returns a new promise when a rescuer is passed' do child = empty_root.then(Proc.new{}) - child.should be_a Promise - child.should_not be empty_root + expect(child).to be_a Promise + expect(child).not_to be empty_root end it 'returns a new promise when a block and rescuer are passed' do child = empty_root.then(Proc.new{}) { nil } - child.should be_a Promise - child.should_not be empty_root + expect(child).to be_a Promise + expect(child).not_to be empty_root end it 'should have block or rescuers' do @@ -180,12 +180,12 @@ module Concurrent let(:child) { p1.then{} } it 'returns a new promise' do - child.should be_a Promise - p1.should_not be child + expect(child).to be_a Promise + expect(p1).not_to be child end it 'returns an unscheduled promise' do - child.should be_unscheduled + expect(child).to be_unscheduled end end @@ -194,12 +194,12 @@ module Concurrent let(:child) { pending_subject.then{} } it 'returns a new promise' do - child.should be_a Promise - pending_subject.should_not be child + expect(child).to be_a Promise + expect(pending_subject).not_to be child end it 'returns a pending promise' do - child.should be_pending + expect(child).to be_pending end end @@ -207,13 +207,13 @@ module Concurrent it 'returns a new Promise' do p1 = fulfilled_subject p2 = p1.then{} - p2.should be_a(Promise) - p1.should_not eq p2 + expect(p2).to be_a(Promise) + expect(p1).not_to eq p2 end it 'notifies fulfillment to new child' do child = fulfilled_subject.then(Proc.new{ 7 }) { |v| v + 5 } - child.value.should eq fulfilled_value + 5 + expect(child.value).to eq fulfilled_value + 5 end end @@ -221,13 +221,13 @@ module Concurrent it 'returns a new Promise when :rejected' do p1 = rejected_subject p2 = p1.then{} - p2.should be_a(Promise) - p1.should_not eq p2 + expect(p2).to be_a(Promise) + expect(p1).not_to eq p2 end it 'notifies rejection to new child' do child = rejected_subject.then(Proc.new{ 7 }) { |v| v + 5 } - child.value.should eq 7 + expect(child.value).to eq 7 end end @@ -235,7 +235,7 @@ module Concurrent p = pending_subject p1 = p.then{} p2 = p.then{} - p1.should_not be p2 + expect(p1).not_to be p2 end end @@ -246,8 +246,8 @@ module Concurrent it 'returns a new promise' do child = empty_root.on_success { nil } - child.should be_a Promise - child.should_not be empty_root + expect(child).to be_a Promise + expect(child).not_to be empty_root end end @@ -255,8 +255,8 @@ module Concurrent it 'returns a new promise' do child = empty_root.rescue { nil } - child.should be_a Promise - child.should_not be empty_root + expect(child).to be_a Promise + expect(child).not_to be empty_root end end @@ -266,34 +266,34 @@ module Concurrent expected = nil Promise.new(executor: executor){ 20 }.then{ |result| expected = result }.execute sleep(0.1) - expected.should eq 20 + expect(expected).to eq 20 end it 'sets the promise value to the result if its block' do root = Promise.new(executor: executor){ 20 } p = root.then{ |result| result * 2}.execute sleep(0.1) - root.value.should eq 20 - p.value.should eq 40 + expect(root.value).to eq 20 + expect(p.value).to eq 40 end it 'sets the promise state to :fulfilled if the block completes' do p = Promise.new(executor: executor){ 10 * 2 }.then{|result| result * 2}.execute sleep(0.1) - p.should be_fulfilled + expect(p).to be_fulfilled end it 'passes the last result through when a promise has no block' do expected = nil Promise.new(executor: executor){ 20 }.then(Proc.new{}).then{|result| expected = result}.execute sleep(0.1) - expected.should eq 20 + expect(expected).to eq 20 end it 'uses result as fulfillment value when a promise has no block' do p = Promise.new(executor: executor){ 20 }.then(Proc.new{}).execute sleep(0.1) - p.value.should eq 20 + expect(p.value).to eq 20 end it 'can manage long chain' do @@ -305,10 +305,10 @@ module Concurrent root.execute sleep(0.1) - root.value.should eq 20 - p1.value.should eq 60 - p2.value.should eq 22 - p3.value.should eq 67 + expect(root.value).to eq 20 + expect(p1.value).to eq 60 + expect(p2.value).to eq 22 + expect(p3.value).to eq 67 end end @@ -318,27 +318,27 @@ module Concurrent expected = nil Promise.new(executor: executor){ raise ArgumentError }.then(Proc.new{ |reason| expected = reason }).execute sleep(0.1) - expected.should be_a ArgumentError + expect(expected).to be_a ArgumentError end it 'sets the promise value to the result if its block' do root = Promise.new(executor: executor){ raise ArgumentError } p = root.then(Proc.new{ |reason| 42 }).execute sleep(0.1) - p.value.should eq 42 + expect(p.value).to eq 42 end it 'sets the promise state to :rejected if the block completes' do p = Promise.new(executor: executor){ raise ArgumentError }.execute sleep(0.1) - p.should be_rejected + expect(p).to be_rejected end it 'uses reason as rejection reason when a promise has no rescue callable' do p = Promise.new(executor: ImmediateExecutor.new){ raise ArgumentError }.then{ |val| val }.execute sleep(0.1) - p.should be_rejected - p.reason.should be_a ArgumentError + expect(p).to be_rejected + expect(p.reason).to be_a ArgumentError end end @@ -346,21 +346,21 @@ module Concurrent context 'aliases' do it 'aliases #realized? for #fulfilled?' do - fulfilled_subject.should be_realized + expect(fulfilled_subject).to be_realized end it 'aliases #deref for #value' do - fulfilled_subject.deref.should eq fulfilled_value + expect(fulfilled_subject.deref).to eq fulfilled_value end it 'aliases #catch for #rescue' do child = rejected_subject.catch { 7 } - child.value.should eq 7 + expect(child.value).to eq 7 end it 'aliases #on_error for #rescue' do child = rejected_subject.on_error { 7 } - child.value.should eq 7 + expect(child.value).to eq 7 end end end diff --git a/spec/concurrent/scheduled_task_spec.rb b/spec/concurrent/scheduled_task_spec.rb index ad7920def..caf14b2c5 100644 --- a/spec/concurrent/scheduled_task_spec.rb +++ b/spec/concurrent/scheduled_task_spec.rb @@ -37,7 +37,7 @@ module Concurrent # dereferenceable - specify{ ScheduledTask.ancestors.should include(Dereferenceable) } + specify{ expect(ScheduledTask.ancestors).to include(Dereferenceable) } # observable @@ -57,14 +57,14 @@ def trigger_observable(observable) Timecop.freeze do now = Time.now task = ScheduledTask.new(60){ nil }.execute - task.schedule_time.to_i.should eq now.to_i + 60 + expect(task.schedule_time.to_i).to eq now.to_i + 60 end end it 'accepts a time object as the schedule time' do schedule = Time.now + (60*10) task = ScheduledTask.new(schedule){ nil }.execute - task.schedule_time.should eq schedule + expect(task.schedule_time).to eq schedule end it 'raises an exception when seconds is less than zero' do @@ -87,19 +87,19 @@ def trigger_observable(observable) it 'sets the initial state to :unscheduled' do task = ScheduledTask.new(1){ nil } - task.should be_unscheduled + expect(task).to be_unscheduled end it 'sets the #schedule_time to nil prior to execution' do task = ScheduledTask.new(1){ nil } - task.schedule_time.should be_nil + expect(task.schedule_time).to be_nil end end context 'instance #execute' do it 'does nothing unless the state is :unscheduled' do - Thread.should_not_receive(:new).with(any_args) + expect(Thread).not_to receive(:new).with(any_args) task = ScheduledTask.new(1){ nil } task.instance_variable_set(:@state, :pending) task.execute @@ -115,7 +115,7 @@ def trigger_observable(observable) task = ScheduledTask.new(5){ nil } Timecop.travel(10) task.execute - task.schedule_time.to_i.should eq now.to_i + 15 + expect(task.schedule_time.to_i).to eq now.to_i + 15 end end @@ -133,12 +133,12 @@ def trigger_observable(observable) it 'sets the sate to :pending' do task = ScheduledTask.new(1){ nil } task.execute - task.should be_pending + expect(task).to be_pending end it 'returns self' do task = ScheduledTask.new(1){ nil } - task.execute.should eq task + expect(task.execute).to eq task end end @@ -146,20 +146,20 @@ def trigger_observable(observable) it 'creates a new ScheduledTask' do task = ScheduledTask.execute(1){ nil } - task.should be_a(ScheduledTask) + expect(task).to be_a(ScheduledTask) end it 'passes the block to the new ScheduledTask' do @expected = false task = ScheduledTask.execute(0.1){ @expected = true } task.value(1) - @expected.should be_true + expect(@expected).to be_truthy end it 'calls #execute on the new ScheduledTask' do task = ScheduledTask.new(0.1){ nil } - ScheduledTask.stub(:new).with(any_args).and_return(task) - task.should_receive(:execute).with(no_args) + allow(ScheduledTask).to receive(:new).with(any_args).and_return(task) + expect(task).to receive(:execute).with(no_args) ScheduledTask.execute(0.1){ nil } end end @@ -169,7 +169,7 @@ def trigger_observable(observable) it 'returns false if the task has already been performed' do task = ScheduledTask.new(0.1){ 42 }.execute task.value(1) - task.cancel.should be_false + expect(task.cancel).to be_falsey end it 'returns false if the task is already in progress' do @@ -179,7 +179,7 @@ def trigger_observable(observable) sleep(1) }.execute latch.wait(1) - task.cancel.should be_false + expect(task.cancel).to be_falsey end it 'cancels the task if it has not yet scheduled' do @@ -187,7 +187,7 @@ def trigger_observable(observable) task = ScheduledTask.new(0.1){ latch.count_down } task.cancel task.execute - latch.wait(0.3).should be_false + expect(latch.wait(0.3)).to be_falsey end @@ -196,20 +196,20 @@ def trigger_observable(observable) task = ScheduledTask.new(0.3){ latch.count_down }.execute sleep(0.1) task.cancel - latch.wait(0.5).should be_false + expect(latch.wait(0.5)).to be_falsey end it 'returns true on success' do task = ScheduledTask.new(10){ nil }.execute sleep(0.1) - task.cancel.should be_true + expect(task.cancel).to be_truthy end it 'sets the state to :cancelled when cancelled' do task = ScheduledTask.new(10){ 42 }.execute sleep(0.1) task.cancel - task.should be_cancelled + expect(task).to be_cancelled end end @@ -222,7 +222,7 @@ def trigger_observable(observable) sleep(1) }.execute latch.wait(1) - task.should be_in_progress + expect(task).to be_in_progress end end @@ -250,56 +250,56 @@ def update(time, value, reason) it 'returns true for an observer added while :unscheduled' do task = ScheduledTask.new(0.1){ 42 } - task.add_observer(observer).should be_true + expect(task.add_observer(observer)).to be_truthy end it 'returns true for an observer added while :pending' do task = ScheduledTask.new(0.1){ 42 }.execute - task.add_observer(observer).should be_true + expect(task.add_observer(observer)).to be_truthy end it 'returns true for an observer added while :in_progress' do task = ScheduledTask.new(0.1){ sleep(1); 42 }.execute sleep(0.2) - task.add_observer(observer).should be_true + expect(task.add_observer(observer)).to be_truthy end it 'returns false for an observer added once :cancelled' do task = ScheduledTask.new(1){ 42 } task.cancel - task.add_observer(observer).should be_false + expect(task.add_observer(observer)).to be_falsey end it 'returns false for an observer added once :fulfilled' do task = ScheduledTask.new(0.1){ 42 }.execute task.value(1) - task.add_observer(observer).should be_false + expect(task.add_observer(observer)).to be_falsey end it 'returns false for an observer added once :rejected' do task = ScheduledTask.new(0.1){ raise StandardError }.execute task.value(0.2) - task.add_observer(observer).should be_false + expect(task.add_observer(observer)).to be_falsey end it 'notifies all observers on fulfillment' do task = ScheduledTask.new(0.1){ 42 }.execute task.add_observer(observer) observer.latch.wait(1) - observer.value.should == 42 - observer.reason.should be_nil + expect(observer.value).to eq(42) + expect(observer.reason).to be_nil end it 'notifies all observers on rejection' do task = ScheduledTask.new(0.1){ raise StandardError }.execute task.add_observer(observer) observer.latch.wait(1) - observer.value.should be_nil - observer.reason.should be_a(StandardError) + expect(observer.value).to be_nil + expect(observer.reason).to be_a(StandardError) end it 'does not notify an observer added after fulfillment' do - observer.should_not_receive(:update).with(any_args) + expect(observer).not_to receive(:update).with(any_args) task = ScheduledTask.new(0.1){ 42 }.execute task.value(1) task.add_observer(observer) @@ -307,7 +307,7 @@ def update(time, value, reason) end it 'does not notify an observer added after rejection' do - observer.should_not_receive(:update).with(any_args) + expect(observer).not_to receive(:update).with(any_args) task = ScheduledTask.new(0.1){ raise StandardError }.execute task.value(1) task.add_observer(observer) @@ -315,7 +315,7 @@ def update(time, value, reason) end it 'does not notify an observer added after cancellation' do - observer.should_not_receive(:update).with(any_args) + expect(observer).not_to receive(:update).with(any_args) task = ScheduledTask.new(0.1){ 42 }.execute task.cancel task.add_observer(observer) diff --git a/spec/concurrent/timer_task_spec.rb b/spec/concurrent/timer_task_spec.rb index ec7b578cd..c4016b83b 100644 --- a/spec/concurrent/timer_task_spec.rb +++ b/spec/concurrent/timer_task_spec.rb @@ -7,8 +7,8 @@ module Concurrent describe TimerTask do before(:each) do # suppress deprecation warnings. - Concurrent::TimerTask.any_instance.stub(:warn) - Concurrent::TimerTask.stub(:warn) + allow_any_instance_of(Concurrent::TimerTask).to receive(:warn) + allow(Concurrent::TimerTask).to receive(:warn) end context :dereferenceable do @@ -61,53 +61,53 @@ def trigger_observable(observable) context '#initialize' do it 'raises an exception if no block given' do - lambda { + expect { Concurrent::TimerTask.new - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it 'raises an exception if :execution_interval is not greater than zero' do - lambda { + expect { Concurrent::TimerTask.new(execution_interval: 0) { nil } - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it 'raises an exception if :execution_interval is not an integer' do - lambda { + expect { Concurrent::TimerTask.new(execution_interval: 'one') { nil } - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it 'raises an exception if :timeout_interval is not greater than zero' do - lambda { + expect { Concurrent::TimerTask.new(timeout_interval: 0) { nil } - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it 'raises an exception if :timeout_interval is not an integer' do - lambda { + expect { Concurrent::TimerTask.new(timeout_interval: 'one') { nil } - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it 'uses the default execution interval when no interval is given' do subject = TimerTask.new { nil } - subject.execution_interval.should eq TimerTask::EXECUTION_INTERVAL + expect(subject.execution_interval).to eq TimerTask::EXECUTION_INTERVAL end it 'uses the default timeout interval when no interval is given' do subject = TimerTask.new { nil } - subject.timeout_interval.should eq TimerTask::TIMEOUT_INTERVAL + expect(subject.timeout_interval).to eq TimerTask::TIMEOUT_INTERVAL end it 'uses the given execution interval' do subject = TimerTask.new(execution_interval: 5) { nil } - subject.execution_interval.should eq 5 + expect(subject.execution_interval).to eq 5 end it 'uses the given timeout interval' do subject = TimerTask.new(timeout_interval: 5) { nil } - subject.timeout_interval.should eq 5 + expect(subject.timeout_interval).to eq 5 end end @@ -116,7 +116,7 @@ def trigger_observable(observable) it 'returns true on success' do task = TimerTask.execute(run_now: false) { nil } sleep(0.1) - task.kill.should be_true + expect(task.kill).to be_truthy end end end @@ -124,9 +124,9 @@ def trigger_observable(observable) context 'arguments' do it 'raises an exception if no block given' do - lambda { + expect { Concurrent::TimerTask.execute - }.should raise_error + }.to raise_error end specify '#execution_interval is writeable' do @@ -139,14 +139,14 @@ def trigger_observable(observable) latch.count_down end - subject.execution_interval.should == 1 + expect(subject.execution_interval).to eq(1) subject.execution_interval = 0.1 - subject.execution_interval.should == 0.1 + expect(subject.execution_interval).to eq(0.1) subject.execute latch.wait(0.2) - subject.execution_interval.should == 3 + expect(subject.execution_interval).to eq(3) subject.kill end @@ -160,14 +160,14 @@ def trigger_observable(observable) latch.count_down end - subject.timeout_interval.should == 1 + expect(subject.timeout_interval).to eq(1) subject.timeout_interval = 2 - subject.timeout_interval.should == 2 + expect(subject.timeout_interval).to eq(2) subject.execute latch.wait(0.2) - subject.timeout_interval.should == 3 + expect(subject.timeout_interval).to eq(3) subject.kill end end @@ -177,23 +177,23 @@ def trigger_observable(observable) it 'runs the block immediately when the :run_now option is true' do latch = CountDownLatch.new(1) subject = TimerTask.execute(execution: 500, now: true) { latch.count_down } - latch.wait(1).should be_true + expect(latch.wait(1)).to be_truthy subject.kill end it 'waits for :execution_interval seconds when the :run_now option is false' do latch = CountDownLatch.new(1) subject = TimerTask.execute(execution: 0.1, now: false) { latch.count_down } - latch.count.should eq 1 - latch.wait(1).should be_true + expect(latch.count).to eq 1 + expect(latch.wait(1)).to be_truthy subject.kill end it 'waits for :execution_interval seconds when the :run_now option is not given' do latch = CountDownLatch.new(1) subject = TimerTask.execute(execution: 0.1, now: false) { latch.count_down } - latch.count.should eq 1 - latch.wait(1).should be_true + expect(latch.count).to eq 1 + expect(latch.wait(1)).to be_truthy subject.kill end @@ -206,7 +206,7 @@ def trigger_observable(observable) end subject.execute latch.wait(1) - expected.should eq subject + expect(expected).to eq subject subject.kill end end @@ -234,8 +234,8 @@ def trigger_observable(observable) subject.add_observer(observer) subject.execute observer.latch.wait(1) - observer.value.should == 42 - observer.ex.should be_nil + expect(observer.value).to eq(42) + expect(observer.ex).to be_nil subject.kill end @@ -244,8 +244,8 @@ def trigger_observable(observable) subject.add_observer(observer) subject.execute observer.latch.wait(1) - observer.value.should be_nil - observer.ex.should be_a(Concurrent::TimeoutError) + expect(observer.value).to be_nil + expect(observer.ex).to be_a(Concurrent::TimeoutError) subject.kill end @@ -254,8 +254,8 @@ def trigger_observable(observable) subject.add_observer(observer) subject.execute observer.latch.wait(1) - observer.value.should be_nil - observer.ex.should be_a(ArgumentError) + expect(observer.value).to be_nil + expect(observer.ex).to be_a(ArgumentError) subject.kill end end diff --git a/spec/concurrent/tvar_spec.rb b/spec/concurrent/tvar_spec.rb index 0a3360e3b..6a4556411 100644 --- a/spec/concurrent/tvar_spec.rb +++ b/spec/concurrent/tvar_spec.rb @@ -8,7 +8,7 @@ module Concurrent it 'accepts an initial value' do t = TVar.new(14) - t.value.should eq 14 + expect(t.value).to eq 14 end end @@ -17,7 +17,7 @@ module Concurrent it 'gets the value' do t = TVar.new(14) - t.value.should eq 14 + expect(t.value).to eq 14 end end @@ -27,7 +27,7 @@ module Concurrent it 'sets the value' do t = TVar.new(14) t.value = 2 - t.value.should eq 2 + expect(t.value).to eq 2 end end @@ -52,7 +52,7 @@ module Concurrent end end - count.should eq 2 + expect(count).to eq 2 end it 'commits writes if the transaction succeeds' do @@ -62,7 +62,7 @@ module Concurrent t.value = 1 end - t.value.should eq 1 + expect(t.value).to eq 1 end it 'undoes writes if the transaction is aborted' do @@ -78,7 +78,7 @@ module Concurrent end end - t.value.should eq 0 + expect(t.value).to eq 0 end it 'provides atomicity' do @@ -96,8 +96,8 @@ module Concurrent end end - t1.value.should eq 0 - t2.value.should eq 0 + expect(t1.value).to eq 0 + expect(t2.value).to eq 0 end it 'provides isolation' do @@ -112,7 +112,7 @@ module Concurrent sleep(0.5) - t.value.should eq 0 + expect(t.value).to eq 0 end it 'nests' do diff --git a/spec/concurrent/utility/processor_count_spec.rb b/spec/concurrent/utility/processor_count_spec.rb index b06f4f712..21c33e479 100644 --- a/spec/concurrent/utility/processor_count_spec.rb +++ b/spec/concurrent/utility/processor_count_spec.rb @@ -5,16 +5,16 @@ module Concurrent describe '#processor_count' do it 'retuns a positive integer' do - Concurrent::processor_count.should be_a Integer - Concurrent::processor_count.should >= 1 + expect(Concurrent::processor_count).to be_a Integer + expect(Concurrent::processor_count).to be >= 1 end end describe '#physical_processor_count' do it 'retuns a positive integer' do - Concurrent::physical_processor_count.should be_a Integer - Concurrent::physical_processor_count.should >= 1 + expect(Concurrent::physical_processor_count).to be_a Integer + expect(Concurrent::physical_processor_count).to be >= 1 end end end diff --git a/spec/concurrent/utility/timeout_spec.rb b/spec/concurrent/utility/timeout_spec.rb index 8008aa958..00a51a44e 100644 --- a/spec/concurrent/utility/timeout_spec.rb +++ b/spec/concurrent/utility/timeout_spec.rb @@ -12,7 +12,7 @@ module Concurrent it 'returns the value of the block on success' do result = Concurrent::timeout(1) { 42 } - result.should eq 42 + expect(result).to eq 42 end it 'raises an exception if the timeout value is reached' do @@ -29,19 +29,19 @@ module Concurrent it 'kills the thread on success' do result = Concurrent::timeout(1) { 42 } - Thread.should_receive(:kill).with(any_args()) + expect(Thread).to receive(:kill).with(any_args()) Concurrent::timeout(1){ 42 } end it 'kills the thread on timeout' do - Thread.should_receive(:kill).with(any_args()) + expect(Thread).to receive(:kill).with(any_args()) expect { Concurrent::timeout(1){ sleep } }.to raise_error end it 'kills the thread on exception' do - Thread.should_receive(:kill).with(any_args()) + expect(Thread).to receive(:kill).with(any_args()) expect { Concurrent::timeout(1){ raise NotImplementedError } }.to raise_error diff --git a/spec/concurrent/utility/timer_spec.rb b/spec/concurrent/utility/timer_spec.rb index f523a8ec4..0aa1a4f4a 100644 --- a/spec/concurrent/utility/timer_spec.rb +++ b/spec/concurrent/utility/timer_spec.rb @@ -22,8 +22,8 @@ module Concurrent Concurrent::timer(0.1){ latch.count_down } latch.wait(1) diff = Time.now.to_f - start - diff.should > 0.1 - diff.should < 0.5 + expect(diff).to be > 0.1 + expect(diff).to be < 0.5 end it 'suppresses exceptions thrown by the block' do @@ -40,11 +40,11 @@ module Concurrent latch.count_down end latch.wait(0.2) - expected.should eq [1, 2, 3] + expect(expected).to eq [1, 2, 3] end it 'runs the task on the global timer pool' do - Concurrent.configuration.global_timer_set.should_receive(:post).with(0.1) + expect(Concurrent.configuration.global_timer_set).to receive(:post).with(0.1) Concurrent::timer(0.1){ :foo } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d6f3e883e..ba0ca2d6e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,8 +27,8 @@ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require File.expand_path(f) } RSpec.configure do |config| + #config.raise_errors_for_deprecations! config.order = 'random' - config.treat_symbols_as_metadata_keys_with_true_values = true config.before(:each) do #TODO: Better configuration management in individual test suites