Skip to content

Commit

Permalink
Update RSpec to v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mthssdrbrg committed Jun 6, 2014
1 parent aaf169b commit 0fe726b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 53 deletions.
22 changes: 13 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GEM
simplecov (>= 0.7)
term-ansicolor
thor
diff-lcs (1.2.4)
diff-lcs (1.2.5)
docile (1.1.3)
kafka-jars (0.8.1.1.pre0-java)
scala-library-jars (~> 2.9.2)
Expand All @@ -17,14 +17,18 @@ GEM
multi_json (1.10.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.3)
rspec-expectations (2.14.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.1)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.0)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.0)
scala-library-jars (2.9.2-java)
simplecov (0.8.2)
docile (~> 1.1.0)
Expand Down
2 changes: 1 addition & 1 deletion spec/heller/consumer_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Heller
end

it 'sets #auto_commit_enable' do
expect(configuration.auto_commit_enable).to be_false
expect(configuration.auto_commit_enable).to be false
end

it 'sets #auto_commit_interval_ms' do
Expand Down
27 changes: 14 additions & 13 deletions spec/heller/consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ module Heller
end

let :consumer_spy do
double(:consumer, fetch: nil)
double(:consumer)
end

before do
consumer_impl.stub(:new) do |*args|
consumer_spy.stub(:client_id).and_return(args.last)
allow(consumer_impl).to receive(:new) do |*args|
allow(consumer_spy).to receive(:client_id).and_return(args.last)
consumer_spy
end
allow(consumer_spy).to receive(:fetch)
end

describe '#initialize' do
Expand All @@ -43,7 +44,7 @@ module Heller
context 'client_id' do
it 'makes some kind of attempt to generate a unique client id' do
consumer = described_class.new('localhost:9092', consumer_impl: consumer_impl)
consumer.client_id.should =~ /heller\-consumer\-[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12}/
expect(consumer.client_id).to match /heller\-consumer\-[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12}/
end
end
end
Expand Down Expand Up @@ -83,7 +84,7 @@ module Heller
it 'includes parameters from given Heller::FetchRequest' do
expect(consumer_spy).to receive(:fetch) do |request|
request_info = request.request_info
expect(request_info).to have(1).item
expect(request_info.size).to eq(1)

tuple = request_info.first
expect(tuple._1.topic).to eq('spec')
Expand All @@ -103,7 +104,7 @@ module Heller
it 'converts them to a Kafka::Api::FetchRequest' do
expect(consumer_spy).to receive(:fetch) do |request|
expect(request).to be_a(Kafka::Api::FetchRequest)
expect(request.request_info).to have(3).items
expect(request.request_info.size).to eq(3)
end

requests = 3.times.map { |i| Heller::FetchRequest.new(topic, partition + i, offset) }
Expand Down Expand Up @@ -166,7 +167,7 @@ module Heller

describe '#offsets_before' do
before do
consumer_spy.stub(:get_offsets_before)
allow(consumer_spy).to receive(:get_offsets_before)
end

let :topic do
Expand Down Expand Up @@ -243,8 +244,8 @@ module Heller
end

before do
consumer_spy.stub(:get_offsets_before).and_return(fake_offset_response)
fake_offset_response.stub(:offsets).with('spec', 0).and_return([0, 1, 2])
allow(consumer_spy).to receive(:get_offsets_before).and_return(fake_offset_response)
allow(fake_offset_response).to receive(:offsets).with('spec', 0).and_return([0, 1, 2])
end

it 'sends an OffsetRequest with the magic value for \'earliest\' offset' do
Expand Down Expand Up @@ -280,8 +281,8 @@ module Heller
end

before do
fake_offset_response.stub(:offsets).with('spec', 0).and_return([0, 1, 2])
consumer_spy.stub(:get_offsets_before).and_return(fake_offset_response)
allow(fake_offset_response).to receive(:offsets).with('spec', 0).and_return([0, 1, 2])
allow(consumer_spy).to receive(:get_offsets_before).and_return(fake_offset_response)
end

it 'sends an OffsetRequest with the magic value for \'latest\' offset' do
Expand Down Expand Up @@ -314,7 +315,7 @@ module Heller
describe '#metadata' do
context 'given a list of topics' do
before do
consumer_spy.stub(:send)
allow(consumer_spy).to receive(:send)
end

it 'sends a TopicMetadataRequest' do
Expand Down Expand Up @@ -345,7 +346,7 @@ module Heller

context '#disconnect' do
before do
consumer_spy.stub(:close)
allow(consumer_spy).to receive(:close)
end

it 'calls #close on the underlying consumer' do
Expand Down
8 changes: 4 additions & 4 deletions spec/heller/fetch_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ module Heller
end

before do
underlying.stub(:has_error?)
underlying.stub(:error)
underlying.stub(:high_watermark)
allow(underlying).to receive(:has_error?)
allow(underlying).to receive(:error)
allow(underlying).to receive(:high_watermark)
end

describe '#error?' do
it 'asks proxies the underlying FetchResponse#has_error?' do
it 'proxies underlying FetchResponse#has_error?' do
fetch_response.error?

expect(underlying).to have_received(:has_error?)
Expand Down
4 changes: 2 additions & 2 deletions spec/heller/offset_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ module Heller
end

before do
underlying.stub(:has_error?)
allow(underlying).to receive(:has_error?)
end

describe '#error?' do
it 'asks proxies the underlying FetchResponse#has_error?' do
it 'proxies the underlying FetchResponse#has_error?' do
response.error?

expect(underlying).to have_received(:has_error?)
Expand Down
2 changes: 1 addition & 1 deletion spec/heller/producer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Heller
message = Heller::Message.new('topic', 'actual message')

expect(producer_spy).to receive(:send) do |msgs|
expect(msgs).to have(1).item
expect(msgs.size).to eq(1)
expect(msgs.first).to eq(message)
end

Expand Down
26 changes: 13 additions & 13 deletions spec/heller/topic_metadata_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module Heller
end

before do
fake_topics_metadata.stub(:topic).and_return('spec')
fake_topics_metadata.stub(:partitions_metadata).and_return([fake_partition_metadata])
allow(fake_topics_metadata).to receive(:topic).and_return('spec')
allow(fake_topics_metadata).to receive(:partitions_metadata).and_return([fake_partition_metadata])
end

it 'yields topic and partition_metadata' do
Expand All @@ -35,7 +35,7 @@ module Heller

describe '#metadata' do
before do
underlying.stub(:topics_metadata)
allow(underlying).to receive(:topics_metadata)
end

it 'returns #topics_metadata' do
Expand All @@ -52,10 +52,10 @@ module Heller
end

before do
fake_topics_metadata.stub(:topic).and_return('spec')
fake_topics_metadata.stub(:partitions_metadata).and_return([fake_partition_metadata])
fake_partition_metadata.stub(:partition_id).and_return(0)
fake_partition_metadata.stub(:leader).and_return('a non-nil value')
allow(fake_topics_metadata).to receive(:topic).and_return('spec')
allow(fake_topics_metadata).to receive(:partitions_metadata).and_return([fake_partition_metadata])
allow(fake_partition_metadata).to receive(:partition_id).and_return(0)
allow(fake_partition_metadata).to receive(:leader).and_return('a non-nil value')
end

it 'returns the leader' do
Expand All @@ -73,7 +73,7 @@ module Heller

context 'given a topic-partition combination that does not exist' do
before do
fake_topics_metadata.stub(:topic).and_return('not-spec')
allow(fake_topics_metadata).to receive(:topic).and_return('not-spec')
end

it 'raises NoSuchTopicPartitionCombinationError' do
Expand All @@ -89,10 +89,10 @@ module Heller
end

before do
fake_topics_metadata.stub(:topic).and_return('spec')
fake_topics_metadata.stub(:partitions_metadata).and_return([fake_partition_metadata])
fake_partition_metadata.stub(:partition_id).and_return(0)
fake_partition_metadata.stub(:isr).and_return(['a non-nil value'])
allow(fake_topics_metadata).to receive(:topic).and_return('spec')
allow(fake_topics_metadata).to receive(:partitions_metadata).and_return([fake_partition_metadata])
allow(fake_partition_metadata).to receive(:partition_id).and_return(0)
allow(fake_partition_metadata).to receive(:isr).and_return(['a non-nil value'])
end

it 'returns in sync replicas' do
Expand All @@ -110,7 +110,7 @@ module Heller

context 'given a topic-partition combination that does not exist' do
before do
fake_topics_metadata.stub(:topic).and_return('not-spec')
allow(fake_topics_metadata).to receive(:topic).and_return('not-spec')
end

it 'raises NoSuchTopicPartitionCombinationError' do
Expand Down
22 changes: 12 additions & 10 deletions spec/integration/heller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ module Heller
consumer.fetch(FetchRequest.new(topic, 0, 0))
end

let :enumerator do
fetch_response.messages(topic, 0)
end

context 'simple string messages' do
let :topic do
"spec-simple-string-#{Time.now.to_i.to_s(36)}"
Expand All @@ -51,11 +55,10 @@ module Heller
end

it 'is no big deal' do
enumerator = fetch_response.messages(topic, 0)
enumerator.should be_a(MessageSetEnumerator)
expect(enumerator).to be_a(MessageSetEnumerator)

messages = enumerator.to_a
expect(messages).to have(1).item
expect(messages.size).to eq(1)

offset, message = messages.last
expect(offset).to be_zero
Expand All @@ -73,11 +76,10 @@ module Heller
end

it 'is no big deal' do
enumerator = fetch_response.messages(topic, 0)
enumerator.should be_a(MessageSetEnumerator)
expect(enumerator).to be_a(MessageSetEnumerator)

messages = enumerator.to_a
expect(messages).to have(1).item
expect(messages.size).to eq(1)

offset, message = messages.last
expect(offset).to be_zero
Expand All @@ -100,7 +102,7 @@ module Heller
response = consumer.metadata(topics)
metadata = response.metadata

expect(metadata).to have(1).item
expect(metadata.size).to eq(1)

topic_metadata = metadata.first
expect(topic_metadata.topic).to eq(topics.first)
Expand All @@ -116,7 +118,7 @@ module Heller
response = consumer.metadata(topics)
metadata = response.metadata

expect(metadata).to have(3).item
expect(metadata.size).to eq(3)

topics.zip(metadata).each do |topic, metadata|
expect(metadata.topic).to eq(topic)
Expand Down Expand Up @@ -164,7 +166,7 @@ module Heller
topics.each do |topic|
isr = response.isr_for(topic, 0)

expect(isr).to have(1).item
expect(isr.size).to eq(1)

replica = isr.first

Expand Down Expand Up @@ -202,7 +204,7 @@ module Heller
it 'returns the expected offsets' do
offsets = response.offsets(topic, 0)

expect(offsets).to have(2).items
expect(offsets.size).to eq(2)
expect(offsets.first).to be > offsets.last
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
RSpec.configure do |config|
config.include(Fakers)
config.order = 'random'
config.raise_errors_for_deprecations!
end

require 'coveralls'
Expand Down

0 comments on commit 0fe726b

Please sign in to comment.