Skip to content

Commit

Permalink
Update supported Ruby versions to 2.7-3.2. Update dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-viney committed Mar 27, 2023
1 parent 0ccc7b8 commit 246ba73
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 83 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Tests

on:
- push
- pull_request

jobs:
test:
name: Run tests on on Ruby ${{ matrix.ruby }}

strategy:
matrix:
ruby: ["2.7", "3.0", "3.1", "3.2"]

runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install gems
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Run test suite
run: bundle exec rspec

- name: Run linter
run: bundle exec rubocop
8 changes: 7 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ require:

AllCops:
NewCops: enable
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7

Bundler/GemFilename:
EnforcedStyle: gems.rb

Layout/LineLength:
Max: 120
Expand All @@ -27,5 +30,8 @@ RSpec/MessageSpies:
RSpec/MultipleExpectations:
Enabled: false

RSpec/StubbedMock:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false
10 changes: 5 additions & 5 deletions lib/lightstreamer/cli/commands/stream_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ def prepare_stream
def create_session
@session = Lightstreamer::Session.new session_options
@session.connect
@session.on_message_result(&method(:on_message_result))
@session.on_error(&method(:on_error))
@session.on_message_result { |sequence, numbers, error| on_message_result sequence, numbers, error }
@session.on_error { |error| on_error error }
end

def create_subscription
subscription = @session.build_subscription subscription_options

subscription.on_data(&method(:on_data))
subscription.on_overflow(&method(:on_overflow))
subscription.on_end_of_snapshot(&method(:on_end_of_snapshot))
subscription.on_data { |sub, item_name, item_data, new_data| on_data sub, item_name, item_data, new_data }
subscription.on_overflow { |sub, item_name, overflow_size| on_overflow sub, item_name, overflow_size }
subscription.on_end_of_snapshot { |sub, item_name| on_end_of_snapshot sub, item_name }

subscription.start
end
Expand Down
6 changes: 3 additions & 3 deletions lib/lightstreamer/messages/update_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def parse(line, table_id, items, fields)
message.item_index = match.captures[0].to_i - 1
return unless message.item_index < items.size

message.data = parse_field_values match.captures[1..-1], fields
message.data = parse_field_values match.captures[1..], fields

message
end
Expand All @@ -52,7 +52,7 @@ def parse_raw_field_value(value)
return '' if value == '$'
return nil if value == '#'

value = value[1..-1] if /^(\$|#)/.match?(value)
value = value[1..] if /^(\$|#)/.match?(value)

decode_escape_sequences value
end
Expand All @@ -63,7 +63,7 @@ def decode_escape_sequences(string)
string = decode_surrogate_pair_escape_sequences string

string.gsub(/\\u[A-F\d]{4}/i) do |escape_sequence|
codepoint = escape_sequence[2..-1].hex
codepoint = escape_sequence[2..].hex

# Codepoints greater than 0xD7FF are invalid and so are removed
codepoint < 0xD800 ? [codepoint].pack('U') : ''
Expand Down
4 changes: 2 additions & 2 deletions lib/lightstreamer/stream_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def execute_stream_post_request(url, options)
@header = StreamConnectionHeader.new

buffer = StreamBuffer.new
options[:response_block] = ->(data, _, _) { buffer.process data, &method(:process_stream_line) }
options[:response_block] = ->(data, _, _) { buffer.process(data) { |line| process_stream_line line } }
options[:expects] = 200

Excon.post url, options
Expand Down Expand Up @@ -175,7 +175,7 @@ def process_body_line(line)
if /^LOOP( \d+|)$/.match?(line)
@loop = true
elsif /^END( \d+|)$/.match?(line)
@error = Errors::SessionEndError.new line[4..-1]
@error = Errors::SessionEndError.new line[4..]
elsif !line.empty?
@queue.push line
end
Expand Down
23 changes: 12 additions & 11 deletions lightstreamer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ Gem::Specification.new do |s|
s.files = Dir['bin/lightstreamer', 'lib/**/*.rb', 'CHANGELOG.md', 'LICENSE.md', 'README.md']
s.executables = ['lightstreamer']

s.required_ruby_version = '>= 2.5.0'
s.required_ruby_version = '>= 2.7'

s.add_runtime_dependency 'excon', '~> 0.73'
s.add_runtime_dependency 'excon', '~> 0.99'
s.add_runtime_dependency 'thor', '~> 1.0'

s.add_development_dependency 'factory_bot', '~> 5.0'
s.add_development_dependency 'github-markup', '~> 3.0'
s.add_development_dependency 'redcarpet', '~> 3.3'
s.add_development_dependency 'rspec', '~> 3.8'
s.add_development_dependency 'rspec-mocks', '~> 3.8'
s.add_development_dependency 'rubocop', '~> 0.82'
s.add_development_dependency 'rubocop-performance', '~> 1.4'
s.add_development_dependency 'rubocop-rspec', '~> 1.35'
s.add_development_dependency 'simplecov', '~> 0.18'
s.add_development_dependency 'factory_bot', '~> 6.2'
s.add_development_dependency 'github-markup', '~> 4.0'
s.add_development_dependency 'redcarpet', '~> 3.6'
s.add_development_dependency 'rspec', '~> 3.12'
s.add_development_dependency 'rspec-mocks', '~> 3.12'
s.add_development_dependency 'rubocop', '~> 1.48'
s.add_development_dependency 'rubocop-performance', '~> 1.16'
s.add_development_dependency 'rubocop-rspec', '~> 2.19'
s.add_development_dependency 'simplecov', '~> 0.21'
s.add_development_dependency 'yard', '~> 0.9'
s.metadata['rubygems_mfa_required'] = 'true'
end
12 changes: 6 additions & 6 deletions spec/lightstreamer/cli/commands/stream_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
polling_enabled: false
end

let(:session) { instance_double 'Lightstreamer::Session' }
let(:subscription) { instance_double 'Lightstreamer::Subscription' }
let(:session) { instance_double Lightstreamer::Session }
let(:subscription) { instance_double Lightstreamer::Subscription }
let(:queue) { Queue.new }

it 'prints stream data' do
expect(Lightstreamer::Session).to receive(:new)
.with(server_url: 'http://a.com', username: 'username', password: 'password', adapter_set: 'adapter-set',
requested_maximum_bandwidth: nil, polling_enabled: false)
.with({ server_url: 'http://a.com', username: 'username', password: 'password', adapter_set: 'adapter-set',
requested_maximum_bandwidth: nil, polling_enabled: false })
.and_return(session)

expect(session).to receive(:on_message_result)
expect(session).to receive(:on_error)
expect(session).to receive(:connect)
expect(session).to receive(:session_id).and_return('A')
expect(session).to receive(:build_subscription)
.with(items: ['item'], fields: ['field'], mode: :merge, data_adapter: 'adapter', maximum_update_frequency: nil,
selector: nil, snapshot: nil)
.with({ items: ['item'], fields: ['field'], mode: :merge, data_adapter: 'adapter', maximum_update_frequency: nil,
selector: nil, snapshot: nil })
.and_return(subscription)

expect(subscription).to receive(:on_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

it 'rejects invalid end-of-snapshot messages' do
['', '1,1,EO', '18,20,EOS', '18,10,EOS '].each do |line|
expect(described_class.parse(line, 18, items)).to be nil
expect(described_class.parse(line, 18, items)).to be_nil
end
end
end
2 changes: 1 addition & 1 deletion spec/lightstreamer/messages/overflow_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'18,20,OV5',
'18,10,OV999 ABC'
].each do |line|
expect(described_class.parse(line, 18, items)).to be nil
expect(described_class.parse(line, 18, items)).to be_nil
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

expect(message.sequence).to eq('Name_123')
expect(message.numbers).to eq([99])
expect(message.error).to be nil
expect(message.error).to be_nil
end

it 'parses a failure message' do
Expand All @@ -24,7 +24,7 @@

it 'rejects invalid messages' do
['', 'DONE', 'MSG,,99,DONE', 'MSG,-,99,DONE', 'MSG,Name,99,ERR,A,A'].each do |line|
expect(described_class.parse(line)).to be nil
expect(described_class.parse(line)).to be_nil
end
end
end
4 changes: 2 additions & 2 deletions spec/lightstreamer/messages/update_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}.each do |line, result|
message = described_class.parse line, 18, items, fields

expect(message).not_to be nil
expect(message).not_to be_nil
expect(message.item_index).to eq(result[:item_index])
expect(message.data).to eq(result[:data])
end
Expand All @@ -33,7 +33,7 @@
'1,1||',
'18,2|'
].each do |line|
expect(described_class.parse(line, 18, items, fields)).to be nil
expect(described_class.parse(line, 18, items, fields)).to be_nil
end
end
end
4 changes: 2 additions & 2 deletions spec/lightstreamer/post_request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe Lightstreamer::PostRequest do
def build_response(body)
instance_double 'Excon::Response', body: body
instance_double Excon::Response, body: body
end

it 'sends a single request' do
Expand Down Expand Up @@ -48,7 +48,7 @@ def build_response(body)
errors = described_class.execute_multiple 'http://a.com', %w[A B C]

expect(errors.size).to eq(3)
expect(errors[0]).to be nil
expect(errors[0]).to be_nil
expect(errors[1]).to be_a(Lightstreamer::Errors::UnknownAdapterSetError)
expect(errors[2]).to be_a(Lightstreamer::LightstreamerError)
expect(errors[2].message).to eq('INVALID RESPONSE')
Expand Down
32 changes: 18 additions & 14 deletions spec/lightstreamer/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
end

let(:stream_connection) do
instance_double 'Lightstreamer::StreamConnection', session_id: 'session', control_address: 'http://a.com'
instance_double Lightstreamer::StreamConnection, session_id: 'session', control_address: 'http://a.com'
end

let(:subscription) { build :subscription, session: session, items: ['item'], fields: ['field'], selector: 'selector' }
let(:subscription) do
build(:subscription, session: session, items: ['item'], fields: ['field'], selector: 'selector')
end

it 'connects to a stream, processes some data, then disconnects' do
expect(Lightstreamer::StreamConnection).to receive(:new).with(session).and_return(stream_connection)
expect(stream_connection).to receive(:connect)

on_message_result_callback = instance_double 'Proc'
on_message_result_callback = instance_double Proc
expect(on_message_result_callback).to receive(:call).with('sequence', [5], nil)
session.on_message_result { |*args| on_message_result_callback.call(*args) }

Expand Down Expand Up @@ -106,22 +108,24 @@

it 'sends a synchronous message' do
expect(Lightstreamer::PostRequest).to receive(:execute)
.with('http://a.com/lightstreamer/send_message.txt', LS_session: 'session', LS_message: 'message')
.with('http://a.com/lightstreamer/send_message.txt', { LS_session: 'session', LS_message: 'message' })

session.send_message 'message'
end

it 'sends an synchronous message' do
expect(Lightstreamer::PostRequest).to receive(:execute)
.with('http://a.com/lightstreamer/send_message.txt', LS_session: 'session', LS_message: 'message',
LS_sequence: 'sequence', LS_msg_prog: 1, LS_max_wait: 500)
.with(
'http://a.com/lightstreamer/send_message.txt',
{ LS_session: 'session', LS_message: 'message', LS_sequence: 'sequence', LS_msg_prog: 1, LS_max_wait: 500 }
)

session.send_message 'message', async: true, sequence: 'sequence', number: 1, max_wait: 500
end

it 'sends control requests' do
expect(Lightstreamer::PostRequest).to receive(:execute)
.with('http://a.com/lightstreamer/control.txt', LS_session: 'session', LS_op: :operation, test: 1)
.with('http://a.com/lightstreamer/control.txt', { LS_session: 'session', LS_op: :operation, test: 1 })

session.control_request LS_op: :operation, test: 1
end
Expand All @@ -146,17 +150,17 @@
subscriptions = [subscription, build(:subscription, session: session), build(:subscription, session: session)]

expect(Lightstreamer::PostRequest).to receive(:request_body)
.with(LS_session: 'session', LS_op: :add, LS_table: subscriptions[0].id, LS_mode: 'MERGE', LS_id: %w[item],
LS_schema: %w[field], LS_selector: 'selector', LS_data_adapter: nil, LS_requested_max_frequency: 0.0,
LS_snapshot: false)
.with({ LS_session: 'session', LS_op: :add, LS_table: subscriptions[0].id, LS_mode: 'MERGE', LS_id: %w[item],
LS_schema: %w[field], LS_selector: 'selector', LS_data_adapter: nil, LS_requested_max_frequency: 0.0,
LS_snapshot: false })
.and_return('body1')

expect(Lightstreamer::PostRequest).to receive(:request_body)
.with(LS_session: 'session', LS_op: :start, LS_table: subscriptions[1].id)
.with({ LS_session: 'session', LS_op: :start, LS_table: subscriptions[1].id })
.and_return('body2')

expect(Lightstreamer::PostRequest).to receive(:request_body)
.with(LS_session: 'session', LS_op: :delete, LS_table: subscriptions[2].id)
.with({ LS_session: 'session', LS_op: :delete, LS_table: subscriptions[2].id })
.and_return('body3')

expect(Lightstreamer::PostRequest).to receive(:execute_multiple)
Expand All @@ -168,9 +172,9 @@
{ subscription: subscriptions[2], action: :stop }]

expect(errors.size).to eq(3)
expect(errors[0]).to be nil
expect(errors[0]).to be_nil
expect(errors[1]).to be_a(Lightstreamer::Errors::InvalidDataAdapterError)
expect(errors[2]).to be nil
expect(errors[2]).to be_nil

expect(subscriptions[0].active).to be_truthy
expect(subscriptions[2].active).to be_falsey
Expand Down
Loading

0 comments on commit 246ba73

Please sign in to comment.