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

MONGOID-5572 Switch to RSpec expect syntax #2694

Closed
Closed
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
2 changes: 1 addition & 1 deletion spec/integration/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
begin
connection.connect!
rescue Mongo::Error::SocketError => exc
exc.service_id.should_not be nil
expect(exc.service_id).not_to be nil
else
fail 'Expected the SocketError to be raised'
end
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/awaited_ismaster_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
resp = client.database.command(hello: 1)
doc = resp.replies.first.documents.first
tv = Mongo::TopologyVersion.new(doc['topologyVersion'])
tv.should be_a(BSON::Document)
expect(tv).to be_a(BSON::Document)

elapsed_time = Benchmark.realtime do
resp = client.database.command(hello: 1,
topologyVersion: tv.to_doc, maxAwaitTimeMS: 500)
end
doc = resp.replies.first.documents.first

elapsed_time.should > 0.5
expect(elapsed_time).to be > 0.5
end
end
10 changes: 5 additions & 5 deletions spec/integration/aws_auth_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
it 'is usable' do
# This assertion intentionally does not use payload so that if it fails,
# the entire response is printed for diagnostic purposes.
sts_response.body.should_not =~ /"Error"/
expect(sts_response.body).not_to match(/"Error"/)

sts_response.code.should == '200'
result['Arn'].should =~ /^arn:aws:(iam|sts)::/
result['Account'].should be_a(String)
result['UserId'].should =~ /^A/
expect(sts_response.code).to eq('200')
expect(result['Arn']).to match(/^arn:aws:(iam|sts)::/)
expect(result['Account']).to be_a(String)
expect(result['UserId']).to match(/^A/)

puts "STS request successful with ARN #{result['Arn']}"
end
Expand Down
12 changes: 6 additions & 6 deletions spec/integration/aws_credentials_retriever_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

shared_examples_for 'retrieves the credentials' do
it 'retrieves' do
credentials.should be_a(Mongo::Auth::Aws::Credentials)
expect(credentials).to be_a(Mongo::Auth::Aws::Credentials)

# When user is not given, credentials retrieved are always temporary.
retriever.credentials.access_key_id.should =~ /^ASIA/
retriever.credentials.secret_access_key.should =~ /./
retriever.credentials.session_token.should =~ /./
expect(retriever.credentials.access_key_id).to match(/^ASIA/)
expect(retriever.credentials.secret_access_key).to match(/./)
expect(retriever.credentials.session_token).to match(/./)
end

let(:request) do
Expand Down Expand Up @@ -68,9 +68,9 @@
end

it 'raises an error' do
lambda do
expect do
credentials
end.should raise_error(Mongo::Auth::Aws::CredentialsNotFound, /Could not locate AWS credentials/)
end.to raise_error(Mongo::Auth::Aws::CredentialsNotFound, /Could not locate AWS credentials/)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/integration/bson_symbol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
end

it 'encodes symbol to BSON symbol' do
serialized.should == expected
expect(serialized).to eq(expected)
end

it 'round-trips symbol values' do
buffer = BSON::ByteBuffer.new(serialized)
Hash.from_bson(buffer).should == hash
expect(Hash.from_bson(buffer)).to eq(hash)
end

it 'round-trips symbol values using the same byte buffer' do
Expand All @@ -34,6 +34,6 @@
'bson version 4.11.0. For more information, see https://jira.mongodb.org/browse/RUBY-2128'
end

Hash.from_bson(hash.to_bson).should == hash
expect(Hash.from_bson(hash.to_bson)).to eq(hash)
end
end
8 changes: 4 additions & 4 deletions spec/integration/bulk_write_error_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
], ordered: true)
fail('Should have raised')
rescue Mongo::Error::BulkWriteError => e
e.message.should =~ %r,\A\[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):,
expect(e.message).to match(%r,\A\[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):,)
end
end
end
Expand All @@ -34,7 +34,7 @@
], ordered: false)
fail('Should have raised')
rescue Mongo::Error::BulkWriteError => e
e.message.should =~ %r,\AMultiple errors: \[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):.*\[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):,
expect(e.message).to match(%r,\AMultiple errors: \[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):.*\[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):,)
end
end
end
Expand Down Expand Up @@ -63,10 +63,10 @@
], ordered: false)
fail('Should have raised')
rescue Mongo::Error::BulkWriteError => e
e.message.should =~ %r,\AMultiple errors: \[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):.*\; \[121\]: Document failed validation( -- .*)?,
expect(e.message).to match(%r,\AMultiple errors: \[11000\]: (insertDocument :: caused by :: 11000 )?E11000 duplicate key error (collection|index):.*\; \[121\]: Document failed validation( -- .*)?,)
# The duplicate key error should not print details because it's not a
# WriteError or a WriteConcernError
e.message.scan(/ -- /).length.should be <= 1
expect(e.message.scan(/ -- /).length).to be <= 1
end
end
end
Expand Down
26 changes: 13 additions & 13 deletions spec/integration/client_construction_aws_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:aws:iam:/
expect(authenticated_user_name).to match(/^arn:aws:iam:/)
end
end

Expand All @@ -66,7 +66,7 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:aws:iam:/
expect(authenticated_user_name).to match(/^arn:aws:iam:/)
end
end
end
Expand All @@ -92,7 +92,7 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:aws:sts:/
expect(authenticated_user_name).to match(/^arn:aws:sts:/)
end
end

Expand All @@ -105,7 +105,7 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:aws:sts:/
expect(authenticated_user_name).to match(/^arn:aws:sts:/)
end
end
end
Expand All @@ -123,9 +123,9 @@
)

it 'does not connect' do
lambda do
expect do
client['foo'].insert_one(test: true)
end.should raise_error(Mongo::Auth::Aws::CredentialsNotFound, /Could not locate AWS credentials/)
end.to raise_error(Mongo::Auth::Aws::CredentialsNotFound, /Could not locate AWS credentials/)
end
end

Expand All @@ -145,8 +145,8 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:/
authenticated_user_name.should_not =~ /^arn:.*assumed-role/
expect(authenticated_user_name).to match(/^arn:/)
expect(authenticated_user_name).not_to match(/^arn:.*assumed-role/)
end
end

Expand All @@ -155,7 +155,7 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:.*assumed-role/
expect(authenticated_user_name).to match(/^arn:.*assumed-role/)
end
end
end
Expand All @@ -167,7 +167,7 @@

before(:all) do
# No explicit credentials are expected in the tested configurations
ENV['AWS_ACCESS_KEY_ID'].should be_nil
expect(ENV['AWS_ACCESS_KEY_ID']).to be_nil
end

it_behaves_like 'connects successfully'
Expand All @@ -177,7 +177,7 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:aws:sts:.*assumed-role.*instance_profile_role/
expect(authenticated_user_name).to match(/^arn:aws:sts:.*assumed-role.*instance_profile_role/)
end
end

Expand All @@ -186,7 +186,7 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:aws:sts:.*assumed-role.*ecstaskexecutionrole/i
expect(authenticated_user_name).to match(/^arn:aws:sts:.*assumed-role.*ecstaskexecutionrole/i)
end
end

Expand All @@ -195,7 +195,7 @@

it 'uses the expected user' do
puts "Authenticated as #{authenticated_user_name}"
authenticated_user_name.should =~ /^arn:aws:sts:.*assumed-role.*webIdentityTestRole/i
expect(authenticated_user_name).to match(/^arn:aws:sts:.*assumed-role.*webIdentityTestRole/i)
end
end
end
Expand Down
24 changes: 12 additions & 12 deletions spec/integration/client_construction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
let(:response) { client.command(ismaster: 1).documents.first }

it 'connects' do
response.fetch('arbiterOnly').should be true
expect(response.fetch('arbiterOnly')).to be true
end
end
end
Expand Down Expand Up @@ -237,20 +237,20 @@
# the minimum was requested by application for its own needs.
it 'uses min pool size 0 for key vault client' do
key_vault_client = client.encrypter.key_vault_client
key_vault_client.options[:min_pool_size].should be 0
expect(key_vault_client.options[:min_pool_size]).to be 0
end
end

context 'when top-level max pool size is not specified' do
before do
client.options[:max_pool_size].should be nil
expect(client.options[:max_pool_size]).to be nil
end

include_examples 'limited connection pool'

it 'uses unspecified max pool size for key vault client' do
key_vault_client = client.encrypter.key_vault_client
key_vault_client.options[:max_pool_size].should be nil
expect(key_vault_client.options[:max_pool_size]).to be nil
end
end

Expand All @@ -266,7 +266,7 @@

it 'uses the same max pool size for key vault client' do
key_vault_client = client.encrypter.key_vault_client
key_vault_client.options[:max_pool_size].should be 42
expect(key_vault_client.options[:max_pool_size]).to be 42
end
end
end
Expand All @@ -280,7 +280,7 @@
end

before do
client.options[:max_pool_size].should be 0
expect(client.options[:max_pool_size]).to be 0
end

include_examples 'creates a working key vault client'
Expand Down Expand Up @@ -341,13 +341,13 @@
end

it 'creates the client successfully' do
client.should be_a(Mongo::Client)
expect(client).to be_a(Mongo::Client)
end

it 'fails all operations' do
lambda do
expect do
client.command(ping: true)
end.should raise_error(Mongo::Error::BadLoadBalancerTarget)
end.to raise_error(Mongo::Error::BadLoadBalancerTarget)
end
end
end
Expand All @@ -368,13 +368,13 @@
end

it 'creates the client successfully' do
client.should be_a(Mongo::Client)
expect(client).to be_a(Mongo::Client)
end

it 'fails all operations' do
lambda do
expect do
client.command(ping: true)
end.should raise_error(Mongo::Error::MissingServiceId)
end.to raise_error(Mongo::Error::MissingServiceId)
end
end
end
Expand Down
Loading