Skip to content

Commit

Permalink
Pet rubocop
Browse files Browse the repository at this point in the history
They are basically in two categories:
  1. Variables with name ending with digits.  This is generaly not a
     good idea but in the test suite we want to send messages in order
     and numbering them help, so silence the related offences;
  2. Test that do not explicitly run expectations.  Some run a function
     that had the expectation, so this was refactored to remove the
     extra layer that caused rubocop confusion; other just made sure
     that to expection was raised, but did not explicitly tested for it,
     so explicitly state that we expect no exception.
  • Loading branch information
smortex committed Jun 15, 2024
1 parent 2c82d32 commit a8cc529
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ Metrics/MethodLength:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
RSpec/IndexedLet:
Enabled: false
Style/Documentation:
Enabled: false
55 changes: 29 additions & 26 deletions spec/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ def wait_for(&block)
raise 'wait_for condition never realized'
end

def roundtrip_metric(metric)
message_id = next_message_id

client_with_transport << {
service: 'metric-test',
metric: metric,
message_id: message_id
}

e = wait_for_message_with_id(message_id)
expect(e.metric).to eq(metric)
end

RSpec.shared_examples 'a riemann client' do
it 'is not connected before sending' do
expect(client).not_to be_connected
Expand Down Expand Up @@ -113,18 +100,34 @@ def roundtrip_metric(metric)
end
end

it 'send longs' do
roundtrip_metric(0)
roundtrip_metric(-3)
roundtrip_metric(5)
roundtrip_metric(-(2**63))
roundtrip_metric(2**63 - 1)
end
context 'when sending metrics' do
[
0,
-3,
5,
-(2**63),
2**63 - 1,
0.0,
12.0,
1.2300000190734863
].each do |metric|
context "with metric=#{metric}" do
before do
client_with_transport << {
service: 'metric-test',
metric: metric,
message_id: message_id
}
end

it 'send doubles' do
roundtrip_metric 0.0
roundtrip_metric 12.0
roundtrip_metric 1.2300000190734863
let(:message_id) { next_message_id }

it 'return the exact value that was sent' do
e = wait_for_message_with_id(message_id)
expect(e.metric).to eq(metric)
end
end
end
end

context 'when sending custom attributes' do
Expand Down Expand Up @@ -485,7 +488,7 @@ def roundtrip_metric(metric)
sleep INACTIVITY_TIME

client_with_transport << message2
wait_for_message_with_id(message_id2)
expect { wait_for_message_with_id(message_id2) }.not_to raise_exception
end
end

Expand Down Expand Up @@ -517,7 +520,7 @@ def roundtrip_metric(metric)
client.close

client_with_transport << message2
wait_for_message_with_id(message_id2)
expect { wait_for_message_with_id(message_id2) }.not_to raise_exception
end
end

Expand Down

0 comments on commit a8cc529

Please sign in to comment.