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

tests: don't reopen Ruby modules in spec #74

Merged
merged 1 commit into from
Oct 17, 2024
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
232 changes: 114 additions & 118 deletions spec/netbox_client_ruby/api/circuits/circuit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,153 +1,149 @@
require 'spec_helper'

module NetboxClientRuby
module Circuits
RSpec.describe Circuit, faraday_stub: true do
let(:id) { 1 }
let(:base_url) { '/api/circuits/circuits/' }
let(:request_url) { "#{base_url}#{id}.json" }
let(:response) { File.read("spec/fixtures/circuits/circuit_#{id}.json") }

subject { described_class.new id }

describe '#id' do
it 'shall be the expected id' do
expect(subject.id).to eq(id)
end
end
RSpec.describe NetboxClientRuby::Circuits::Circuit, faraday_stub: true do
let(:id) { 1 }
let(:base_url) { '/api/circuits/circuits/' }
let(:request_url) { "#{base_url}#{id}.json" }
let(:response) { File.read("spec/fixtures/circuits/circuit_#{id}.json") }

describe '#description' do
it 'should fetch the data' do
expect(faraday).to receive(:get).and_call_original
subject { described_class.new id }

subject.description
end
describe '#id' do
it 'shall be the expected id' do
expect(subject.id).to eq(id)
end
end

it 'shall be the expected description' do
expect(subject.description).to eq('Desc of Circuit 0')
end
end
describe '#description' do
it 'should fetch the data' do
expect(faraday).to receive(:get).and_call_original

describe '.tenant' do
it 'should be a Tenant object' do
tenant = subject.tenant
expect(tenant).to be_a Tenancy::Tenant
expect(tenant.id).to eq(1)
end
end
subject.description
end

describe '.provider' do
it 'should be a Provider object' do
provider = subject.provider
expect(provider).to be_a Provider
expect(provider.id).to eq(1)
end
end
it 'shall be the expected description' do
expect(subject.description).to eq('Desc of Circuit 0')
end
end

describe '.type' do
it 'should be a Type object' do
provider = subject.type
expect(provider).to be_a CircuitType
expect(provider.id).to eq(1)
end
end
describe '.tenant' do
it 'should be a Tenant object' do
tenant = subject.tenant
expect(tenant).to be_a NetboxClientRuby::Tenancy::Tenant
expect(tenant.id).to eq(1)
end
end

describe '.delete' do
let(:request_method) { :delete }
let(:response_status) { 204 }
let(:response) { nil }
describe '.provider' do
it 'should be a Provider object' do
provider = subject.provider
expect(provider).to be_a NetboxClientRuby::Circuits::Provider
expect(provider.id).to eq(1)
end
end

it 'should delete the object' do
expect(faraday).to receive(request_method).and_call_original
subject.delete
end
end
describe '.type' do
it 'should be a Type object' do
provider = subject.type
expect(provider).to be_a NetboxClientRuby::Circuits::CircuitType
expect(provider.id).to eq(1)
end
end

describe '.update' do
let(:request_method) { :patch }
let(:request_params) { { 'description' => 'noob' } }
describe '.delete' do
let(:request_method) { :delete }
let(:response_status) { 204 }
let(:response) { nil }

it 'should update the object' do
expect(faraday).to receive(request_method).and_call_original
expect(subject.update(description: 'noob').description).to eq('Desc of Circuit 0')
end
end
it 'should delete the object' do
expect(faraday).to receive(request_method).and_call_original
subject.delete
end
end

describe '.reload' do
it 'should reload the object' do
expect(faraday).to receive(request_method).twice.and_call_original
describe '.update' do
let(:request_method) { :patch }
let(:request_params) { { 'description' => 'noob' } }

subject.reload
subject.reload
end
end
it 'should update the object' do
expect(faraday).to receive(request_method).and_call_original
expect(subject.update(description: 'noob').description).to eq('Desc of Circuit 0')
end
end

describe '.save' do
let(:description) { 'foobar' }
let(:request_params) { { 'description' => description } }
describe '.reload' do
it 'should reload the object' do
expect(faraday).to receive(request_method).twice.and_call_original

context 'update' do
let(:request_method) { :patch }
subject.reload
subject.reload
end
end

subject do
entity = described_class.new id
entity.description = description
entity
end
describe '.save' do
let(:description) { 'foobar' }
let(:request_params) { { 'description' => description } }

it 'does not call PATCH until save is called' do
expect(faraday).to_not receive(request_method)
expect(faraday).to_not receive(:get)
context 'update' do
let(:request_method) { :patch }

expect(subject.description).to eq(description)
end
subject do
entity = described_class.new id
entity.description = description
entity
end

it 'calls PATCH when save is called' do
expect(faraday).to receive(request_method).and_call_original
it 'does not call PATCH until save is called' do
expect(faraday).to_not receive(request_method)
expect(faraday).to_not receive(:get)

expect(subject.save).to be(subject)
end
expect(subject.description).to eq(description)
end

it 'Reads the answer from the PATCH answer' do
expect(faraday).to receive(request_method).and_call_original
it 'calls PATCH when save is called' do
expect(faraday).to receive(request_method).and_call_original

subject.save
expect(subject.description).to eq('Desc of Circuit 0')
end
end
expect(subject.save).to be(subject)
end

it 'Reads the answer from the PATCH answer' do
expect(faraday).to receive(request_method).and_call_original

subject.save
expect(subject.description).to eq('Desc of Circuit 0')
end
end

context 'create' do
let(:request_method) { :post }
let(:request_url) { base_url }
context 'create' do
let(:request_method) { :post }
let(:request_url) { base_url }

subject do
entity = described_class.new
entity.description = description
entity
end
subject do
entity = described_class.new
entity.description = description
entity
end

it 'does not POST until save is called' do
expect(faraday).to_not receive(request_method)
expect(faraday).to_not receive(:get)
it 'does not POST until save is called' do
expect(faraday).to_not receive(request_method)
expect(faraday).to_not receive(:get)

expect(subject.description).to eq(description)
end
expect(subject.description).to eq(description)
end

it 'POSTs the data upon a call of save' do
expect(faraday).to receive(request_method).and_call_original
it 'POSTs the data upon a call of save' do
expect(faraday).to receive(request_method).and_call_original

expect(subject.save).to be(subject)
end
expect(subject.save).to be(subject)
end

it 'Reads the answer from the POST' do
expect(faraday).to receive(request_method).and_call_original
it 'Reads the answer from the POST' do
expect(faraday).to receive(request_method).and_call_original

subject.save
subject.save

expect(subject.id).to be(1)
expect(subject.description).to eq('Desc of Circuit 0')
end
end
expect(subject.id).to be(1)
expect(subject.description).to eq('Desc of Circuit 0')
end
end
end
Expand Down
Loading
Loading