Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
updated specs to use expect().to instead of the deprecated .should sy…
Browse files Browse the repository at this point in the history
…ntax
  • Loading branch information
oheyandy committed May 21, 2014
1 parent 881b81e commit 0ed14cb
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 173 deletions.
32 changes: 16 additions & 16 deletions spec/desk_api/client_spec.rb
Expand Up @@ -43,7 +43,7 @@
it 'inherits the module configuration' do
client = DeskApi::Client.new
DeskApi::Configuration.keys.each do |key|
client.instance_variable_get(:"@#{key}").should eq(@configuration[key])
expect(client.instance_variable_get(:"@#{key}")).to eq(@configuration[key])
end
end
end
Expand All @@ -53,7 +53,7 @@
it "overrides the module configuration" do
client = DeskApi::Client.new(@configuration)
DeskApi::Configuration.keys.each do |key|
client.instance_variable_get(:"@#{key}").should eq(@configuration[key])
expect(client.instance_variable_get(:"@#{key}")).to eq(@configuration[key])
end
end
end
Expand All @@ -68,7 +68,7 @@
end

DeskApi::Configuration.keys.each do |key|
client.instance_variable_get(:"@#{key}").should eq(@configuration[key])
expect(client.instance_variable_get(:"@#{key}")).to eq(@configuration[key])
end
end
end
Expand All @@ -79,26 +79,26 @@
describe '#get', :vcr do
it 'fetches resources' do
response = subject.get('/api/v2/cases/3014')
response.body['subject'].should eq('Testing Quick Case')
expect(response.body['subject']).to eq('Testing Quick Case')
end
end

describe '#post', :vcr do
it 'creates a resource' do
response = subject.post('/api/v2/topics', @topic_create_data)
response.body['name'].should eq(@topic_create_data[:name])
expect(response.body['name']).to eq(@topic_create_data[:name])
end
end

describe '#patch', :vcr do
it 'updates a resource' do
subject.patch('/api/v2/topics/601117', @topic_update_data).body['name'].should eq(@topic_update_data[:name])
expect(subject.patch('/api/v2/topics/601117', @topic_update_data).body['name']).to eq(@topic_update_data[:name])
end
end

describe '#delete', :vcr do
it 'deletes a resource' do
subject.delete('/api/v2/topics/601117').status.should eq(204)
expect(subject.delete('/api/v2/topics/601117').status).to eq(204)
end
end
end
Expand All @@ -113,56 +113,56 @@
describe '#get', :vcr do
it 'fetches resources' do
response = @client.get('/api/v2/articles/1391017')
response.body['subject'].should eq('Testing OAuth')
expect(response.body['subject']).to eq('Testing OAuth')
end
end

describe '#post', :vcr do
it 'creates a resource' do
response = @client.post('/api/v2/articles', @article_create_data)
response.body['subject'].should eq(@article_create_data[:subject])
expect(response.body['subject']).to eq(@article_create_data[:subject])
end
end

describe '#patch', :vcr do
it 'updates a resource' do
@client.patch('/api/v2/articles/1391017', @article_update_data).body['subject'].should eq(@article_update_data[:subject])
expect(@client.patch('/api/v2/articles/1391017', @article_update_data).body['subject']).to eq(@article_update_data[:subject])
end
end

describe '#delete', :vcr do
it 'deletes a resource' do
@client.delete('/api/v2/articles/1391017').status.should eq(204)
expect(@client.delete('/api/v2/articles/1391017').status).to eq(204)
end
end
end

describe '#by_url', :vcr do
it 'finds resources by url' do
subject.by_url('/api/v2/articles/1295677').should be_an_instance_of(DeskApi::Resource)
expect(subject.by_url('/api/v2/articles/1295677')).to be_an_instance_of(DeskApi::Resource)
end
end

describe '#connection' do
it 'looks like Faraday connection' do
subject.send(:connection).should be_an_instance_of(Faraday::Connection)
expect(subject.send(:connection)).to be_an_instance_of(Faraday::Connection)
end

it 'memoizes the connection' do
c1, c2 = subject.send(:connection), subject.send(:connection)
c1.should equal(c2)
expect(c1).to equal(c2)
end
end

describe '#request' do
it 'catches Faraday errors' do
allow(subject).to receive(:connection).and_raise(Faraday::Error::ClientError.new('Oops'))
lambda { subject.send(:request, :get, '/path') }.should raise_error(DeskApi::Error::ClientError)
expect(lambda { subject.send(:request, :get, '/path') }).to raise_error(DeskApi::Error::ClientError)
end

it 'catches JSON::ParserError errors' do
allow(subject).to receive(:connection).and_raise(JSON::ParserError.new('unexpected token'))
lambda { subject.send(:request, :get, '/path') }.should raise_error(DeskApi::Error::ParserError)
expect(lambda { subject.send(:request, :get, '/path') }).to raise_error(DeskApi::Error::ParserError)
end
end
end
90 changes: 49 additions & 41 deletions spec/desk_api/configuration_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe DeskApi::Configuration do
context '#keys' do
it 'returns an array of configuration keys' do
DeskApi::Configuration.keys.should eq([
expect(DeskApi::Configuration.keys).to eq([
:consumer_key,
:consumer_secret,
:token,
Expand All @@ -24,18 +24,18 @@

it 'returns the endpoint if set' do
DeskApi.endpoint = 'https://devel.desk.com'
DeskApi.endpoint.should eq('https://devel.desk.com')
expect(DeskApi.endpoint).to eq('https://devel.desk.com')
end

it 'returns the subdomain endpoint if subdomain is set' do
DeskApi.subdomain = 'devel'
DeskApi.endpoint.should eq('https://devel.desk.com')
expect(DeskApi.endpoint).to eq('https://devel.desk.com')
end

it 'gives presidence to the endpoint' do
DeskApi.subdomain = 'subdomain'
DeskApi.endpoint = 'https://endpoint.desk.com'
DeskApi.endpoint.should eq('https://endpoint.desk.com')
expect(DeskApi.endpoint).to eq('https://endpoint.desk.com')
end
end

Expand Down Expand Up @@ -65,59 +65,67 @@
end

DeskApi::Configuration.keys.each do |key|
client.instance_variable_get(:"@#{key}").should eq(@configuration[key])
expect(client.instance_variable_get(:"@#{key}")).to eq(@configuration[key])
end
end

it 'throws an exception if credentials are not set' do
client = DeskApi::Client.new
lambda {
client.configure do |config|
@configuration.each do |key, value|
config.send("#{key}=", value)
expect(
lambda {
client.configure do |config|
@configuration.each do |key, value|
config.send("#{key}=", value)
end
config.username = nil
config.consumer_key = nil
end
config.username = nil
config.consumer_key = nil
end
}.should raise_error(DeskApi::Error::ConfigurationError)
}
).to raise_error(DeskApi::Error::ConfigurationError)
end

it 'throws an exception if basic auth credentials are invalid' do
client = DeskApi::Client.new
lambda {
client.configure do |config|
@configuration.each do |key, value|
config.send("#{key}=", value)
expect(
lambda {
client.configure do |config|
@configuration.each do |key, value|
config.send("#{key}=", value)
end
config.username = 1
config.consumer_key = nil
end
config.username = 1
config.consumer_key = nil
end
}.should raise_error(DeskApi::Error::ConfigurationError)
}
).to raise_error(DeskApi::Error::ConfigurationError)
end

it 'throws an exception if oauth credentials are invalid' do
client = DeskApi::Client.new
lambda {
client.configure do |config|
@configuration.each do |key, value|
config.send("#{key}=", value)
expect(
lambda {
client.configure do |config|
@configuration.each do |key, value|
config.send("#{key}=", value)
end
config.username = nil
config.consumer_key = 1
end
config.username = nil
config.consumer_key = 1
end
}.should raise_error(DeskApi::Error::ConfigurationError)
}
).to raise_error(DeskApi::Error::ConfigurationError)
end

it 'throws an exception if endpoint is not a valid url' do
client = DeskApi::Client.new
lambda {
client.configure do |config|
@configuration.each do |key, value|
config.send("#{key}=", value)
expect(
lambda {
client.configure do |config|
@configuration.each do |key, value|
config.send("#{key}=", value)
end
config.endpoint = 'some_funky_endpoint'
end
config.endpoint = 'some_funky_endpoint'
end
}.should raise_error(DeskApi::Error::ConfigurationError)
}
).to raise_error(DeskApi::Error::ConfigurationError)
end
end

Expand Down Expand Up @@ -148,7 +156,7 @@
client.reset!

DeskApi::Configuration.keys.each do |key|
client.instance_variable_get(:"@#{key}").should_not eq(@configuration[key])
expect(client.instance_variable_get(:"@#{key}")).not_to eq(@configuration[key])
end
end
end
Expand All @@ -163,21 +171,21 @@
end

it 'returns false if no authentication credentials are set' do
@client.credentials?.should be_false
expect(@client.credentials?).to be_false
end

it 'returns true if basic auth credentials are set' do
@client.username = 'UN'
@client.password = 'PW'
@client.credentials?.should be_true
expect(@client.credentials?).to be_true
end

it 'returns true if oauth credentials are set' do
@client.consumer_key = 'CK'
@client.consumer_secret = 'CS'
@client.token = 'TOK'
@client.token_secret = 'TOKS'
@client.credentials?.should be_true
expect(@client.credentials?).to be_true
end
end
end
end
6 changes: 3 additions & 3 deletions spec/desk_api/default_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe DeskApi::Default do
context '#options' do
it 'returns a hash with mostly nil values' do
DeskApi::Default.options.should eq({
expect(DeskApi::Default.options).to eq({
consumer_key: nil,
consumer_secret: nil,
token: nil,
Expand Down Expand Up @@ -35,7 +35,7 @@
ENV['DESK_SUBDOMAIN'] = 'SD'
ENV['DESK_ENDPOINT'] = 'EP'

DeskApi::Default.options.should eq({
expect(DeskApi::Default.options).to eq({
consumer_key: 'CK',
consumer_secret: 'CS',
token: 'TOK',
Expand Down Expand Up @@ -66,4 +66,4 @@
ENV['DESK_ENDPOINT'] = nil
end
end
end
end
16 changes: 9 additions & 7 deletions spec/desk_api/error_spec.rb
Expand Up @@ -7,16 +7,18 @@

context '.from_response' do
it 'can be created from a faraday response', :vcr do
lambda {
subject.articles.create({ subject: 'Testing', body: 'Testing' })
}.should raise_error(DeskApi::Error::UnprocessableEntity)
expect(
lambda {
subject.articles.create({ subject: 'Testing', body: 'Testing' })
}
).to raise_error(DeskApi::Error::UnprocessableEntity)
end

it 'uses the body message if present', :vcr do
begin
subject.articles.create({ subject: 'Testing', body: 'Testing' })
rescue DeskApi::Error::UnprocessableEntity => e
e.message.should eq('Validation Failed')
expect(e.message).to eq('Validation Failed')
end
end
end
Expand All @@ -26,9 +28,9 @@
begin
subject.articles.create({ subject: 'Testing', body: 'Testing' })
rescue DeskApi::Error::UnprocessableEntity => e
e.errors.should be_an_instance_of(Hash)
e.errors.should eq({"_links" => { "topic" => ["blank"]}})
expect(e.errors).to be_an_instance_of(Hash)
expect(e.errors).to eq({"_links" => { "topic" => ["blank"]}})
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/desk_api/rate_limit_spec.rb
Expand Up @@ -39,4 +39,4 @@
expect(rate_limit.reset_in).to be_nil
end
end
end
end

0 comments on commit 0ed14cb

Please sign in to comment.