Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix test failures when running with --order random #291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/protobuf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ module Protobuf
# Default is Socket as it has no external dependencies.
DEFAULT_CONNECTOR = :socket

module_function

class << self
# Client Host
#
# Default: `hostname` of the system
#
# The name or address of the host to use during client RPC calls.
attr_accessor :client_host
attr_writer :client_host
end

self.client_host = Socket.gethostname
def self.client_host
@client_host ||= Socket.gethostname
end

# Connector Type
#
Expand Down
3 changes: 3 additions & 0 deletions lib/protobuf/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def self.define(name, tag)
enum = new(self, name, tag)
@enums ||= []
@enums << enum
# defining a new field for the enum will cause cached @values and @mapped_enums
# to be incorrect; reset them
@mapped_enums = @values = nil
const_set(name, enum)
end

Expand Down
3 changes: 3 additions & 0 deletions lib/protobuf/message/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def define_field(rule, type_class, field_name, tag, options)
field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options)
field_store[field_name] = field
field_store[tag] = field
# defining a new field for the message will cause cached @all_fields, @extension_fields,
# and @fields to be incorrect; reset them
@all_fields = @extension_fields = @fields = nil

str_field_store[field_name.to_s] = field

Expand Down
1 change: 0 additions & 1 deletion spec/lib/protobuf/code_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@
end
end
end

end
1 change: 1 addition & 0 deletions spec/lib/protobuf/enum_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require PROTOS_PATH.join('enum.pb')

RSpec.describe Protobuf::Enum do

Expand Down
15 changes: 12 additions & 3 deletions spec/lib/protobuf/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@
end

context 'ignoring unknown fields' do
before { ::Protobuf.ignore_unknown_fields = true }
around do |example|
orig = ::Protobuf.ignore_unknown_fields?
::Protobuf.ignore_unknown_fields = true
example.call
::Protobuf.ignore_unknown_fields = orig
end

context 'with valid fields' do
let(:values) { { :name => "Jim" } }
Expand All @@ -203,8 +208,12 @@
end

context 'not ignoring unknown fields' do
before { ::Protobuf.ignore_unknown_fields = false }
after { ::Protobuf.ignore_unknown_fields = true }
around do |example|
orig = ::Protobuf.ignore_unknown_fields?
::Protobuf.ignore_unknown_fields = false
example.call
::Protobuf.ignore_unknown_fields = orig
end

context 'with valid fields' do
let(:values) { { :name => "Jim" } }
Expand Down
22 changes: 16 additions & 6 deletions spec/lib/protobuf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@
end

describe '.print_deprecation_warnings?' do
before { described_class.instance_variable_set(:@print_deprecation_warnings, nil) }
around do |example|
orig = described_class.print_deprecation_warnings?
example.call
described_class.print_deprecation_warnings = orig
end

it 'defaults to a true value' do
allow(ENV).to receive(:key?).with('PB_IGNORE_DEPRECATIONS').and_return(false)
described_class.instance_variable_set('@field_deprecator', nil)
expect(described_class.print_deprecation_warnings?).to be true
end

Expand All @@ -69,20 +75,24 @@

context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do
it 'defaults to a false value' do
ENV['PB_IGNORE_DEPRECATIONS'] = '1'
allow(ENV).to receive(:key?).with('PB_IGNORE_DEPRECATIONS').and_return(true)
described_class.instance_variable_set('@field_deprecator', nil)
expect(described_class.print_deprecation_warnings?).to be false
end
end
end

describe '.ignore_unknown_fields?' do
before do
if described_class.instance_variable_defined?(:@_ignore_unknown_fields)
described_class.send(:remove_instance_variable, :@_ignore_unknown_fields)
end
around do |example|
orig = described_class.ignore_unknown_fields?
example.call
described_class.ignore_unknown_fields = orig
end

it 'defaults to a true value' do
if described_class.instance_variable_defined?('@ignore_unknown_fields')
described_class.send(:remove_instance_variable, '@ignore_unknown_fields')
end
expect(described_class.ignore_unknown_fields?).to be true
end

Expand Down