From afd72f8d17f54cba0d54415e9bcf883b85419ddc Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 29 Sep 2025 23:17:40 +0200 Subject: [PATCH 1/9] Add binstubs for rake, rspec, rubocop, appraisal --- Gemfile | 11 +++++++---- bin/appraisal | 27 +++++++++++++++++++++++++++ bin/rake | 27 +++++++++++++++++++++++++++ bin/rspec | 27 +++++++++++++++++++++++++++ bin/rubocop | 27 +++++++++++++++++++++++++++ gemfiles/faraday0.gemfile | 8 ++++---- gemfiles/faraday1.gemfile | 8 ++++---- gemfiles/faraday2.gemfile | 8 ++++---- 8 files changed, 127 insertions(+), 16 deletions(-) create mode 100755 bin/appraisal create mode 100755 bin/rake create mode 100755 bin/rspec create mode 100755 bin/rubocop diff --git a/Gemfile b/Gemfile index a7d98df..66803cb 100644 --- a/Gemfile +++ b/Gemfile @@ -5,15 +5,18 @@ source 'https://rubygems.org' # Specify your gem dependencies in netbox-client-ruby.gemspec gemspec +# Dev libs gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' gem 'pry' gem 'rake' gem 'rspec' -gem 'rubocop' -gem 'rubocop-performance' -gem 'rubocop-rake' -gem 'rubocop-rspec' # fallback to faraday 1.x in dev environment gem 'faraday', '~> 1.10' gem 'faraday_middleware' + +# Dev tools / linter +gem 'rubocop', require: false +gem 'rubocop-performance', require: false +gem 'rubocop-rake', require: false +gem 'rubocop-rspec', require: false diff --git a/bin/appraisal b/bin/appraisal new file mode 100755 index 0000000..5038ce5 --- /dev/null +++ b/bin/appraisal @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'appraisal' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("appraisal", "appraisal") diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..4eb7d7b --- /dev/null +++ b/bin/rake @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..cb53ebe --- /dev/null +++ b/bin/rspec @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..369a05b --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rubocop", "rubocop") diff --git a/gemfiles/faraday0.gemfile b/gemfiles/faraday0.gemfile index 4ffb0ba..57cc7b5 100644 --- a/gemfiles/faraday0.gemfile +++ b/gemfiles/faraday0.gemfile @@ -6,11 +6,11 @@ gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "pry" gem "rake" gem "rspec" -gem "rubocop" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "faraday", "< 1.0" gem "faraday_middleware", "< 1" +gem "rubocop", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gemspec path: "../" diff --git a/gemfiles/faraday1.gemfile b/gemfiles/faraday1.gemfile index cdff122..f2eb6cc 100644 --- a/gemfiles/faraday1.gemfile +++ b/gemfiles/faraday1.gemfile @@ -6,11 +6,11 @@ gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "pry" gem "rake" gem "rspec" -gem "rubocop" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "faraday", "= 1.0" gem "faraday_middleware", "< 2" +gem "rubocop", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gemspec path: "../" diff --git a/gemfiles/faraday2.gemfile b/gemfiles/faraday2.gemfile index 3f81b9b..517e1cd 100644 --- a/gemfiles/faraday2.gemfile +++ b/gemfiles/faraday2.gemfile @@ -6,11 +6,11 @@ gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "pry" gem "rake" gem "rspec" -gem "rubocop" -gem "rubocop-performance" -gem "rubocop-rake" -gem "rubocop-rspec" gem "faraday", "< 3" +gem "rubocop", require: false +gem "rubocop-performance", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false gem "faraday-net_http_persistent" gemspec path: "../" From 4f9bdae6b78e4c1c4d8a8ff8da2979d46e186e7a Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 29 Sep 2025 23:21:05 +0200 Subject: [PATCH 2/9] Add support for Ruby 3.4 --- .github/workflows/rspec.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index bd2be4b..c0fdecc 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -15,12 +15,11 @@ jobs: matrix: os: [ubuntu-latest] # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' - ruby: ['2.7', '3.0', '3.1', '3.2', '3.3'] + ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4'] gemfile: - [ - 'gemfiles/faraday1.gemfile', - 'gemfiles/faraday2.gemfile', - ] + - 'gemfiles/faraday1.gemfile' + - 'gemfiles/faraday2.gemfile' + # Faraday 0.x with Ruby 3.x not supported exclude: - ruby: '3.0' @@ -31,6 +30,8 @@ jobs: gemfile: gemfiles/faraday0.gemfile - ruby: '3.3' gemfile: gemfiles/faraday0.gemfile + - ruby: '3.4' + gemfile: gemfiles/faraday0.gemfile runs-on: ${{ matrix.os }} env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }} From b60f98980a11b77cb799d3794114cfcd328a0bfe Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 29 Sep 2025 23:21:41 +0200 Subject: [PATCH 3/9] Bump to actions/checkout@v5 --- .github/workflows/rspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index c0fdecc..0fb2df4 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -36,7 +36,7 @@ jobs: env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 - uses: ruby/setup-ruby@v1 From e56a5ebeebd6aed89d399bc6b542ed4d3e291e0d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 29 Sep 2025 23:44:42 +0200 Subject: [PATCH 4/9] Add rubocop config, fix offenses --- .github/workflows/rspec.yml | 22 ++++++- .rubocop.yml | 38 ++++++++++++ .rubocop_todo.yml | 60 +++++++++++++++++++ Appraisals | 2 +- lib/netbox_client_ruby/api/circuits.rb | 4 +- .../api/circuits/circuit.rb | 4 +- .../api/circuits/circuit_termination.rb | 2 +- lib/netbox_client_ruby/api/dcim.rb | 4 +- .../api/dcim/device_type.rb | 2 +- lib/netbox_client_ruby/api/dcim/platform.rb | 2 +- lib/netbox_client_ruby/api/dcim/site.rb | 4 +- lib/netbox_client_ruby/api/extras.rb | 4 +- .../api/extras/config_context.rb | 2 +- lib/netbox_client_ruby/api/ipam.rb | 4 +- lib/netbox_client_ruby/api/ipam/ip_address.rb | 9 +-- lib/netbox_client_ruby/api/ipam/ip_range.rb | 2 +- lib/netbox_client_ruby/api/ipam/prefix.rb | 2 +- lib/netbox_client_ruby/api/ipam/service.rb | 2 +- lib/netbox_client_ruby/api/secrets.rb | 4 +- .../api/secrets/rsa_key_pair.rb | 2 +- .../api/secrets/session_key.rb | 7 ++- lib/netbox_client_ruby/api/tenancy.rb | 4 +- lib/netbox_client_ruby/communication.rb | 24 ++++---- lib/netbox_client_ruby/connection.rb | 6 +- lib/netbox_client_ruby/entities.rb | 18 +++--- lib/netbox_client_ruby/entity.rb | 24 ++++---- netbox-client-ruby.gemspec | 16 +++-- 27 files changed, 200 insertions(+), 74 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 0fb2df4..e25e0c0 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -9,7 +9,25 @@ name: Ruby CI on: [push, pull_request] jobs: - test: + rubocop: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '2.7' + + - name: Bundler + run: bundle install + + - name: Rubocop + run: bin/rubocop + + rspec: strategy: fail-fast: false matrix: @@ -43,4 +61,4 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle exec rake spec + - run: bin/rspec diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..3bfe4a5 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,38 @@ +--- +inherit_from: .rubocop_todo.yml + +plugins: + - rubocop-performance + - rubocop-rake + - rubocop-rspec + +AllCops: + NewCops: enable + TargetRubyVersion: 2.7 + Exclude: + - bin/* + - gemfiles/* + - spec/**/* + - lib/netbox-client-ruby.rb + +Gemspec/RequireMFA: + Enabled: false + +######### +# STYLE # +######### + +Style/Documentation: + Enabled: false + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: consistent_comma + +Style/AccessModifierDeclarations: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..320916b --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,60 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2025-09-29 22:04:50 UTC using RuboCop version 1.81.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +Lint/ReturnInVoidContext: + Exclude: + - 'lib/netbox_client_ruby/entity.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: CheckForMethodsWithNoSideEffects. +Lint/Void: + Exclude: + - 'lib/netbox_client_ruby/entity.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, conditionals +Style/AndOr: + Exclude: + - 'lib/netbox_client_ruby/entity.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/CollectionQuerying: + Exclude: + - 'lib/netbox_client_ruby/entity.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/KeywordArgumentsMerging: + Exclude: + - 'lib/netbox_client_ruby/connection.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantRegexpArgument: + Exclude: + - 'lib/netbox_client_ruby/communication.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'lib/netbox_client_ruby/entities.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'netbox-client-ruby.gemspec' diff --git a/Appraisals b/Appraisals index 6cc5e59..d97b77a 100644 --- a/Appraisals +++ b/Appraisals @@ -13,5 +13,5 @@ end appraise 'faraday2' do gem 'faraday', '< 3' gem 'faraday-net_http_persistent' - remove_gem "faraday_middleware" + remove_gem 'faraday_middleware' end diff --git a/lib/netbox_client_ruby/api/circuits.rb b/lib/netbox_client_ruby/api/circuits.rb index 796f54e..652aa15 100644 --- a/lib/netbox_client_ruby/api/circuits.rb +++ b/lib/netbox_client_ruby/api/circuits.rb @@ -6,7 +6,7 @@ module Circuits providers: Providers, circuits: Circuits, circuit_types: CircuitTypes, - circuit_terminations: CircuitTerminations + circuit_terminations: CircuitTerminations, }.each_pair do |method_name, class_name| define_method(method_name) { class_name.new } module_function(method_name) @@ -16,7 +16,7 @@ module Circuits provider: Provider, circuit: Circuit, circuit_type: CircuitType, - circuit_termination: CircuitTermination + circuit_termination: CircuitTermination, }.each_pair do |method_name, class_name| define_method(method_name) { |id| class_name.new id } module_function(method_name) diff --git a/lib/netbox_client_ruby/api/circuits/circuit.rb b/lib/netbox_client_ruby/api/circuits/circuit.rb index 2e603de..5be4654 100644 --- a/lib/netbox_client_ruby/api/circuits/circuit.rb +++ b/lib/netbox_client_ruby/api/circuits/circuit.rb @@ -11,7 +11,7 @@ class Circuit planned: 2, provisioning: 3, offline: 4, - decommissioned: 5 + decommissioned: 5, }.freeze id id: :id @@ -27,7 +27,7 @@ class Circuit STATUS_VALUES.key(raw_status['value']) || raw_status['value'] end, type: proc { |raw_data| CircuitType.new raw_data['id'] }, - tenant: proc { |raw_data| Tenancy::Tenant.new raw_data['id'] } + tenant: proc { |raw_data| Tenancy::Tenant.new raw_data['id'] }, ) end end diff --git a/lib/netbox_client_ruby/api/circuits/circuit_termination.rb b/lib/netbox_client_ruby/api/circuits/circuit_termination.rb index c826b83..c994be4 100644 --- a/lib/netbox_client_ruby/api/circuits/circuit_termination.rb +++ b/lib/netbox_client_ruby/api/circuits/circuit_termination.rb @@ -13,7 +13,7 @@ class CircuitTermination object_fields( circuit: proc { |raw_data| Circuit::Circuit.new raw_data['id'] }, site: proc { |raw_data| DCIM::Site.new raw_data['id'] }, - interface: proc { |raw_data| DCIM::Interface.new raw_data['id'] } + interface: proc { |raw_data| DCIM::Interface.new raw_data['id'] }, ) end end diff --git a/lib/netbox_client_ruby/api/dcim.rb b/lib/netbox_client_ruby/api/dcim.rb index e5660a4..9eb2483 100644 --- a/lib/netbox_client_ruby/api/dcim.rb +++ b/lib/netbox_client_ruby/api/dcim.rb @@ -24,7 +24,7 @@ module DCIM rack_roles: RackRoles, regions: Regions, sites: Sites, - virtual_chassis_list: VirtualChassisList + virtual_chassis_list: VirtualChassisList, }.each_pair do |method_name, class_name| define_method(method_name) { class_name.new } module_function(method_name) @@ -52,7 +52,7 @@ module DCIM rack_role: RackRole, region: Region, site: Site, - virtual_chassis: VirtualChassis + virtual_chassis: VirtualChassis, }.each_pair do |method_name, class_name| define_method(method_name) { |id| class_name.new id } module_function(method_name) diff --git a/lib/netbox_client_ruby/api/dcim/device_type.rb b/lib/netbox_client_ruby/api/dcim/device_type.rb index d1c2c3d..c9454cd 100644 --- a/lib/netbox_client_ruby/api/dcim/device_type.rb +++ b/lib/netbox_client_ruby/api/dcim/device_type.rb @@ -20,7 +20,7 @@ class DeviceType creation_path 'dcim/device-types/' object_fields( manufacturer: proc { |raw_data| Manufacturer.new raw_data['id'] }, - interface_ordering: InterfaceOrdering + interface_ordering: InterfaceOrdering, ) end end diff --git a/lib/netbox_client_ruby/api/dcim/platform.rb b/lib/netbox_client_ruby/api/dcim/platform.rb index 91cb3d3..03eff50 100644 --- a/lib/netbox_client_ruby/api/dcim/platform.rb +++ b/lib/netbox_client_ruby/api/dcim/platform.rb @@ -12,7 +12,7 @@ class Platform object_fields( manufacturer: proc do |raw_manufacturer| DCIM::Manufacturer.new raw_manufacturer['id'] - end + end, ) end end diff --git a/lib/netbox_client_ruby/api/dcim/site.rb b/lib/netbox_client_ruby/api/dcim/site.rb index 2cfe6a0..ba2fd25 100644 --- a/lib/netbox_client_ruby/api/dcim/site.rb +++ b/lib/netbox_client_ruby/api/dcim/site.rb @@ -8,7 +8,7 @@ class Site STATUS_VALUES = { active: 1, planned: 2, - retired: 4 + retired: 4, }.freeze id id: :id @@ -23,7 +23,7 @@ class Site region: proc { |raw_region| DCIM::Region.new raw_region['id'] }, status: proc do |raw_status| STATUS_VALUES.key(raw_status['value']) || raw_status['value'] - end + end, ) end end diff --git a/lib/netbox_client_ruby/api/extras.rb b/lib/netbox_client_ruby/api/extras.rb index 11fae70..639acf6 100644 --- a/lib/netbox_client_ruby/api/extras.rb +++ b/lib/netbox_client_ruby/api/extras.rb @@ -5,7 +5,7 @@ module Extras { config_contexts: ConfigContexts, journal_entries: JournalEntries, - tags: Tags + tags: Tags, }.each_pair do |method_name, class_name| define_method(method_name) { class_name.new } module_function(method_name) @@ -14,7 +14,7 @@ module Extras { config_context: ConfigContext, journal_entry: JournalEntry, - tag: Tag + tag: Tag, }.each_pair do |method_name, class_name| define_method(method_name) { |id| class_name.new id } module_function(method_name) diff --git a/lib/netbox_client_ruby/api/extras/config_context.rb b/lib/netbox_client_ruby/api/extras/config_context.rb index ac6ba2d..84b8ff2 100644 --- a/lib/netbox_client_ruby/api/extras/config_context.rb +++ b/lib/netbox_client_ruby/api/extras/config_context.rb @@ -18,7 +18,7 @@ class ConfigContext clusters: proc { |raw_data| Virtualization::Cluster.new raw_data['id'] }, tenant_groups: proc { |raw_data| Tenancy::TenantGroup.new raw_data['id'] }, tenants: proc { |raw_data| Tenancy::Tenant.new raw_data['id'] }, - tags: proc { |raw_data| Tag.new raw_data['id'] } + tags: proc { |raw_data| Tag.new raw_data['id'] }, ) end end diff --git a/lib/netbox_client_ruby/api/ipam.rb b/lib/netbox_client_ruby/api/ipam.rb index ac7257f..f87bb9e 100644 --- a/lib/netbox_client_ruby/api/ipam.rb +++ b/lib/netbox_client_ruby/api/ipam.rb @@ -12,7 +12,7 @@ module IPAM services: Services, vlans: Vlans, vlan_groups: VlanGroups, - vrfs: Vrfs + vrfs: Vrfs, }.each_pair do |method_name, class_name| define_method(method_name) { class_name.new } module_function(method_name) @@ -28,7 +28,7 @@ module IPAM service: Service, vlan: Vlan, vlan_group: VlanGroup, - vrf: Vrf + vrf: Vrf, }.each_pair do |method_name, class_name| define_method(method_name) { |id| class_name.new id } module_function(method_name) diff --git a/lib/netbox_client_ruby/api/ipam/ip_address.rb b/lib/netbox_client_ruby/api/ipam/ip_address.rb index 1b3d759..97b602f 100644 --- a/lib/netbox_client_ruby/api/ipam/ip_address.rb +++ b/lib/netbox_client_ruby/api/ipam/ip_address.rb @@ -9,7 +9,7 @@ class IpAddress active: 1, reserved: 2, deprecated: 3, - dhcp: 5 + dhcp: 5, }.freeze id id: :id @@ -20,7 +20,7 @@ class IpAddress vrf: proc { |raw_data| Vrf.new raw_data['id'] }, tenant: proc { |raw_data| Tenancy::Tenant.new raw_data['id'] }, status: proc { |raw_data| STATUS_VALUES.key(raw_data['value']) || raw_data['value'] }, - address: proc { |raw_ip| IPAddress.parse(raw_ip) } + address: proc { |raw_ip| IPAddress.parse(raw_ip) }, ) readonly_fields :display_name @@ -33,8 +33,9 @@ def interface interface_data = data['interface'] return nil unless interface_data - return Virtualization::Interface.new interface_data['id'] unless interface_data.dig('virtual_machine').nil? - return DCIM::Interface.new interface_data['id'] + return Virtualization::Interface.new interface_data['id'] unless interface_data['virtual_machine'].nil? + + DCIM::Interface.new interface_data['id'] end end end diff --git a/lib/netbox_client_ruby/api/ipam/ip_range.rb b/lib/netbox_client_ruby/api/ipam/ip_range.rb index ba9d715..8bbd120 100644 --- a/lib/netbox_client_ruby/api/ipam/ip_range.rb +++ b/lib/netbox_client_ruby/api/ipam/ip_range.rb @@ -15,7 +15,7 @@ class IpRange role: proc { |raw_data| Role.new raw_data['id'] }, status: proc { |raw_data| IpRangeStatus.new raw_data }, start_address: proc { |raw_data| IPAddress.parse raw_data }, - end_address: proc { |raw_data| IPAddress.parse raw_data } + end_address: proc { |raw_data| IPAddress.parse raw_data }, ) end diff --git a/lib/netbox_client_ruby/api/ipam/prefix.rb b/lib/netbox_client_ruby/api/ipam/prefix.rb index f163211..2aaafe4 100644 --- a/lib/netbox_client_ruby/api/ipam/prefix.rb +++ b/lib/netbox_client_ruby/api/ipam/prefix.rb @@ -16,7 +16,7 @@ class Prefix vlan: proc { |raw_data| Vlan.new raw_data['id'] }, status: proc { |raw_data| PrefixStatus.new raw_data }, role: proc { |raw_data| Role.new raw_data['id'] }, - prefix: proc { |raw_data| IPAddress.parse raw_data } + prefix: proc { |raw_data| IPAddress.parse raw_data }, ) readonly_fields :display_name end diff --git a/lib/netbox_client_ruby/api/ipam/service.rb b/lib/netbox_client_ruby/api/ipam/service.rb index bf5124d..204752e 100644 --- a/lib/netbox_client_ruby/api/ipam/service.rb +++ b/lib/netbox_client_ruby/api/ipam/service.rb @@ -13,7 +13,7 @@ class Service device: proc { |raw_data| Device.new raw_data['id'] }, virtual_machine: proc { |raw_data| VirtualMachine.new raw_data['id'] }, protocol: proc { |raw_data| ServiceProtocol.new raw_data }, - ipaddresses: proc { |raw_data| IpAddress.new raw_data['id'] } + ipaddresses: proc { |raw_data| IpAddress.new raw_data['id'] }, ) readonly_fields :display_name end diff --git a/lib/netbox_client_ruby/api/secrets.rb b/lib/netbox_client_ruby/api/secrets.rb index 8e234d8..5941c00 100644 --- a/lib/netbox_client_ruby/api/secrets.rb +++ b/lib/netbox_client_ruby/api/secrets.rb @@ -6,7 +6,7 @@ module Secrets secret_roles: SecretRoles, secrets: Secrets, generate_rsa_key_pair: RSAKeyPair, - get_session_key: SessionKey + get_session_key: SessionKey, }.each_pair do |method_name, class_name| define_method(method_name) { class_name.new } module_function(method_name) @@ -14,7 +14,7 @@ module Secrets { secret_role: SecretRole, - secret: Secret + secret: Secret, }.each_pair do |method_name, class_name| define_method(method_name) { |id| class_name.new id } module_function(method_name) diff --git a/lib/netbox_client_ruby/api/secrets/rsa_key_pair.rb b/lib/netbox_client_ruby/api/secrets/rsa_key_pair.rb index bd2f50d..3b26742 100644 --- a/lib/netbox_client_ruby/api/secrets/rsa_key_pair.rb +++ b/lib/netbox_client_ruby/api/secrets/rsa_key_pair.rb @@ -5,7 +5,7 @@ module Secrets class RSAKeyPair include Communication - PATH = '/api/secrets/generate-rsa-key-pair/'.freeze + PATH = '/api/secrets/generate-rsa-key-pair/' def public_key get['public_key'] diff --git a/lib/netbox_client_ruby/api/secrets/session_key.rb b/lib/netbox_client_ruby/api/secrets/session_key.rb index 77d7671..08fcced 100644 --- a/lib/netbox_client_ruby/api/secrets/session_key.rb +++ b/lib/netbox_client_ruby/api/secrets/session_key.rb @@ -5,7 +5,7 @@ module Secrets class SessionKey include Communication - PATH = '/api/secrets/get-session-key/'.freeze + PATH = '/api/secrets/get-session-key/' def initialize session_key @@ -49,6 +49,7 @@ def private_key private_key.to_pem end + # rubocop:disable Layout/LineLength,Metrics/MethodLength def decode_private_key(encoded_private_key) begin private_key = OpenSSL::PKey::RSA.new encoded_private_key, rsa_private_key_password @@ -67,15 +68,18 @@ def decode_private_key(encoded_private_key) raise LocalError, "The file at '#{rsa_private_key_path}' is not a private key, but a private key is required for get-session-key. (The corresponding configuration is 'netbox.auth.rsa_private_key.path'.)" end + # rubocop:enable Layout/LineLength,Metrics/MethodLength def rsa_private_key_password pwd = rsa_private_key_config.password # If nil is not converted to '', then OpenSSL will block and ask on console for the password. # We really don't want that. return '' if pwd.nil? + pwd end + # rubocop:disable Layout/LineLength def read_private_key_file(key_file) encoded_private_key = key_file.read return encoded_private_key unless encoded_private_key.nil? || encoded_private_key.empty? @@ -90,6 +94,7 @@ def open_private_key_file raise LocalError, "No file exists at the given path '#{rsa_private_key_path}', but it's required for get-session-key. (The corresponding configuration is 'netbox.auth.rsa_private_key.path'.)" end + # rubocop:enable Layout/LineLength def rsa_private_key_path @rsa_private_key_path ||= File.expand_path(rsa_private_key_config.path) diff --git a/lib/netbox_client_ruby/api/tenancy.rb b/lib/netbox_client_ruby/api/tenancy.rb index 03e8a0d..0b885d9 100644 --- a/lib/netbox_client_ruby/api/tenancy.rb +++ b/lib/netbox_client_ruby/api/tenancy.rb @@ -6,7 +6,7 @@ module Tenancy tenants: Tenants, tenant_groups: TenantGroups, contacts: Contacts, - contact_groups: ContactGroups + contact_groups: ContactGroups, }.each_pair do |method_name, class_name| define_method(method_name) { class_name.new } module_function(method_name) @@ -16,7 +16,7 @@ module Tenancy tenant: Tenant, tenant_group: TenantGroup, contact: Contact, - contact_group: ContactGroup + contact_group: ContactGroup, }.each_pair do |method_name, class_name| define_method(method_name) { |id| class_name.new id } module_function(method_name) diff --git a/lib/netbox_client_ruby/communication.rb b/lib/netbox_client_ruby/communication.rb index 868b1f2..c173129 100644 --- a/lib/netbox_client_ruby/communication.rb +++ b/lib/netbox_client_ruby/communication.rb @@ -21,37 +21,38 @@ def read(response) response.body end - def raise_on_http_error(response) + def raise_on_http_error(response) # rubocop:disable Metrics/MethodLength status = response.status body = response.body case status - when 200..299 then - when 300..499 then + when 200..299 + # do nothing + when 300..499 raise_on_http_client_error response - when 500..599 then + when 500..599 raise NetboxClientRuby::RemoteError, "#{status} Remote Error#{formatted_body(body)}" else raise NetboxClientRuby::RemoteError, "#{status} Unknown Error Code#{formatted_body(body)}" end end - def raise_on_http_client_error(response) + def raise_on_http_client_error(response) # rubocop:disable Metrics/MethodLength status = response.status body = response.body case status - when 400 then + when 400 raise_client_error '400 Bad Request', body - when 401 then + when 401 raise_client_error '401 Unauthorized', body - when 403 then + when 403 raise_client_error '403 Forbidden', body - when 405 then + when 405 raise_client_error '405 Method Not Allowed', body - when 415 then + when 415 raise_client_error '415 Unsupported Media Type', body - when 429 then + when 429 raise_client_error '429 Too Many Requests', body else raise_client_error "#{status} Request Error", body @@ -64,6 +65,7 @@ def raise_client_error(message, body = nil) def formatted_body(body) return '' if body.nil? || body.empty? + shortened = body.to_s one_line = shortened.gsub(/\n/, '\n') " (#{one_line})" diff --git a/lib/netbox_client_ruby/connection.rb b/lib/netbox_client_ruby/connection.rb index 1d58585..a6d029c 100644 --- a/lib/netbox_client_ruby/connection.rb +++ b/lib/netbox_client_ruby/connection.rb @@ -3,7 +3,7 @@ module NetboxClientRuby class Connection DEFAULT_OPTIONS = { - request_encoding: :json + request_encoding: :json, }.freeze def self.new(options = {}) @@ -13,7 +13,7 @@ def self.new(options = {}) def self.headers headers = {} auth_token = auth_config.token - headers['Authorization'] = "Token #{auth_token}".freeze if auth_token + headers['Authorization'] = "Token #{auth_token}" if auth_token headers['X-Session-Key'] = NetboxClientRuby::Secrets.session_key if NetboxClientRuby::Secrets.session_key headers end @@ -26,7 +26,7 @@ def self.netbox_config NetboxClientRuby.config.netbox end - private_class_method def self.build_faraday(request_encoding: :json) + private_class_method def self.build_faraday(request_encoding: :json) # rubocop:disable Metrics/AbcSize config = NetboxClientRuby.config Faraday.new(url: config.netbox.api_base_url, headers: headers, ssl: config.faraday.ssl_options) do |faraday| faraday.request request_encoding diff --git a/lib/netbox_client_ruby/entities.rb b/lib/netbox_client_ruby/entities.rb index 8f430bb..35d4ab6 100644 --- a/lib/netbox_client_ruby/entities.rb +++ b/lib/netbox_client_ruby/entities.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module NetboxClientRuby - module Entities + module Entities # rubocop:disable Metrics/ModuleLength include NetboxClientRuby::Communication include Enumerable @@ -37,7 +37,7 @@ def limit(limit = nil) @limit end - def check_limit(limit) + def check_limit(limit) # rubocop:disable Metrics/MethodLength max_limit = NetboxClientRuby.config.netbox.pagination.max_limit if limit.nil? raise ArgumentError, @@ -74,8 +74,8 @@ def path(path = nil) end end - def find_by(attributes) - fail ArgumentError, '"attributes" expects a hash' unless attributes.is_a? Hash + def find_by(attributes) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength + raise ArgumentError, '"attributes" expects a hash' unless attributes.is_a? Hash filter(attributes).find do |netbox_object| attributes.all? do |filter_key, filter_value| @@ -83,19 +83,17 @@ def find_by(attributes) custom_field = filter_key.to_s.sub('cf_', '') netbox_object.custom_fields[custom_field].to_s == filter_value.to_s + elsif netbox_object.respond_to?(filter_key) + netbox_object.public_send(filter_key).to_s == filter_value.to_s else - if netbox_object.respond_to?(filter_key) - netbox_object.public_send(filter_key).to_s == filter_value.to_s - else - false - end + false end end end end def filter(filter) - fail ArgumentError, '"filter" expects a hash' unless filter.is_a? Hash + raise ArgumentError, '"filter" expects a hash' unless filter.is_a? Hash @filter = filter reset diff --git a/lib/netbox_client_ruby/entity.rb b/lib/netbox_client_ruby/entity.rb index fdf3730..fc97369 100644 --- a/lib/netbox_client_ruby/entity.rb +++ b/lib/netbox_client_ruby/entity.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module NetboxClientRuby - module Entity + module Entity # rubocop:disable Metrics/ModuleLength include NetboxClientRuby::Communication def self.included(other_klass) @@ -21,7 +21,7 @@ module ClassMethods # id 'an_id_field' => 'id_field_in_data' # id an_id_field: 'id_field_in_data', :another_id_field: 'id_field2_in_data' # - def id(*fields) + def id(*fields) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity return @id_fields if @id_fields raise ArgumentError, "No 'id' was defined, but one is expected." if fields.empty? @@ -36,7 +36,7 @@ def id(*fields) end end - @id_fields.keys.each do |field| + @id_fields.each_key do |field| define_method(field) { instance_variable_get :"@#{field}" } end @@ -49,7 +49,7 @@ def readonly_fields(*fields) @readonly_fields = fields.map(&:to_s) end - def deletable(deletable = false) + def deletable(deletable = false) # rubocop:disable Style/OptionalBooleanParameter @deletable ||= deletable end @@ -88,7 +88,7 @@ def object_fields(*fields_to_class_map) end end - def sanitize_mapping(fields_to_class_map) + def sanitize_mapping(fields_to_class_map) # rubocop:disable Metrics/MethodLength fields_map = {} fields_to_class_map.each do |field_definition| if field_definition.is_a?(Hash) @@ -103,7 +103,7 @@ def sanitize_mapping(fields_to_class_map) end end - def initialize(given_values = nil) + def initialize(given_values = nil) # rubocop:disable Metrics/MethodLength return self if given_values.nil? if id_fields.count == 1 && !given_values.is_a?(Hash) @@ -138,6 +138,7 @@ def reload def save return post unless ids_set? + patch end @@ -158,7 +159,7 @@ def delete self end - def update(new_values) + def update(new_values) # rubocop:disable Metrics/MethodLength new_values.each do |attribute, values| s_attribute = attribute.to_s next if readonly_fields.include? s_attribute @@ -191,7 +192,7 @@ def []=(name, value) dirty_data[name.to_s] = value end - def method_missing(name_as_symbol, *args, &block) + def method_missing(name_as_symbol, *args, &block) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength name = name_as_symbol.to_s if name.end_with?('=') @@ -212,7 +213,7 @@ def method_missing(name_as_symbol, *args, &block) super end - def respond_to_missing?(name_as_symbol, *args) + def respond_to_missing?(name_as_symbol, *args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity name = name_as_symbol.to_s return false if name.end_with?('=') && readonly_fields.include?(name[0..-2]) @@ -325,6 +326,7 @@ def replace_path_variables_in(path) path.scan(/:([a-zA-Z_][a-zA-Z0-9_]+[!?=]?)/) do |match, *| path_variable_value = send(match) return interpreted_path.gsub! ":#{match}", path_variable_value.to_s unless path_variable_value.nil? + raise LocalError, "Received 'nil' while replacing ':#{match}' in '#{path}' with a value." end interpreted_path @@ -340,9 +342,7 @@ def id_fields def extract_ids id_fields.each do |id_attr, id_field| - unless data.key?(id_field) - raise LocalError, "Can't find the id field '#{id_field}' in the received data." - end + raise LocalError, "Can't find the id field '#{id_field}' in the received data." unless data.key?(id_field) instance_variable_set(:"@#{id_attr}", data[id_field]) end diff --git a/netbox-client-ruby.gemspec b/netbox-client-ruby.gemspec index 4c58c5f..31ec3f9 100644 --- a/netbox-client-ruby.gemspec +++ b/netbox-client-ruby.gemspec @@ -13,6 +13,10 @@ Gem::Specification.new do |spec| if spec.respond_to?(:metadata) spec.metadata['allowed_push_host'] = 'https://rubygems.org' + spec.metadata['homepage_uri'] = 'https://github.com/ninech/netbox-client-ruby' + spec.metadata['changelog_uri'] = 'https://github.com/ninech/netbox-client-ruby/releases' + spec.metadata['source_code_uri'] = 'https://github.com/ninech/netbox-client-ruby' + spec.metadata['bug_tracker_uri'] = 'https://github.com/ninech/netbox-client-ruby/issues' end spec.files = `git ls-files -z`.split("\x0").reject do |f| @@ -21,10 +25,10 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.7.0' - spec.add_runtime_dependency 'dry-configurable', '~> 1' - spec.add_runtime_dependency 'faraday', '>= 0.11.0', '< 3' - spec.add_runtime_dependency 'faraday-detailed_logger', '~> 2.1' - spec.add_runtime_dependency 'ipaddress', '~> 0.8', '>= 0.8.3' - spec.add_runtime_dependency 'openssl', '>= 2.0.5' - spec.add_runtime_dependency 'zeitwerk', '~> 2.6.0' + spec.add_dependency 'dry-configurable', '~> 1' + spec.add_dependency 'faraday', '>= 0.11.0', '< 3' + spec.add_dependency 'faraday-detailed_logger', '~> 2.1' + spec.add_dependency 'ipaddress', '~> 0.8', '>= 0.8.3' + spec.add_dependency 'openssl', '>= 2.0.5' + spec.add_dependency 'zeitwerk', '~> 2.6.0' end From 235389903772814129fd5a7613b83e8e4e0e0569 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 30 Sep 2025 00:22:05 +0200 Subject: [PATCH 5/9] Improve Rspec config --- .rspec | 2 +- Gemfile | 1 + gemfiles/faraday0.gemfile | 1 + gemfiles/faraday1.gemfile | 1 + gemfiles/faraday2.gemfile | 1 + spec/spec_helper.rb | 18 ++++++++++++++---- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.rspec b/.rspec index 4e1e0d2..372b5ac 100644 --- a/.rspec +++ b/.rspec @@ -1 +1 @@ ---color +--warnings diff --git a/Gemfile b/Gemfile index 66803cb..42a5e23 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,7 @@ gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' gem 'pry' gem 'rake' gem 'rspec' +gem 'warning' # fallback to faraday 1.x in dev environment gem 'faraday', '~> 1.10' diff --git a/gemfiles/faraday0.gemfile b/gemfiles/faraday0.gemfile index 57cc7b5..2e62bf4 100644 --- a/gemfiles/faraday0.gemfile +++ b/gemfiles/faraday0.gemfile @@ -6,6 +6,7 @@ gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "pry" gem "rake" gem "rspec" +gem "warning" gem "faraday", "< 1.0" gem "faraday_middleware", "< 1" gem "rubocop", require: false diff --git a/gemfiles/faraday1.gemfile b/gemfiles/faraday1.gemfile index f2eb6cc..4d456d0 100644 --- a/gemfiles/faraday1.gemfile +++ b/gemfiles/faraday1.gemfile @@ -6,6 +6,7 @@ gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "pry" gem "rake" gem "rspec" +gem "warning" gem "faraday", "= 1.0" gem "faraday_middleware", "< 2" gem "rubocop", require: false diff --git a/gemfiles/faraday2.gemfile b/gemfiles/faraday2.gemfile index 517e1cd..1645ae6 100644 --- a/gemfiles/faraday2.gemfile +++ b/gemfiles/faraday2.gemfile @@ -6,6 +6,7 @@ gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" gem "pry" gem "rake" gem "rspec" +gem "warning" gem "faraday", "< 3" gem "rubocop", require: false gem "rubocop-performance", require: false diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9338366..9322e3c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,12 @@ # frozen_string_literal: true -require 'bundler/setup' +require 'warning' + +# Ignore all warnings in Gem dependencies +Gem.path.each do |path| + Warning.ignore(//, path) +end + require 'netbox-client-ruby' require 'shared_context' require 'faraday/net_http_persistent' if Faraday::VERSION > '2' @@ -8,13 +14,17 @@ RSpec.configure do |config| config.example_status_persistence_file_path = '.rspec_status' + config.color = true + config.fail_fast = false + config.fail_if_no_examples = true + + config.order = :random + Kernel.srand config.seed + config.run_all_when_everything_filtered = true config.filter_run :focus - config.order = 'random' config.include_context 'connection setup' - config.fail_if_no_examples = true - config.expect_with :rspec do |c| c.syntax = :expect end From 1a5b38a308e9adf39fae2df46e5c29577fb14d8d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 30 Sep 2025 00:38:36 +0200 Subject: [PATCH 6/9] Fix warning: loading in progress, circular require considered harmful /Users/nicolas/PROJECTS/GITHUB/FORKS/netbox-client-ruby/spec/spec_helper.rb Backtrace: from bin/rspec:27:in `
' from bin/rspec:27:in `load' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/exe/rspec:4:in `' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/runner.rb:45:in `invoke' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/runner.rb:71:in `run' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/runner.rb:86:in `run' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/runner.rb:102:in `setup' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/configuration.rb:1641:in `load_spec_files' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/configuration.rb:1641:in `each' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/configuration.rb:1643:in `block in load_spec_files' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/configuration.rb:2144:in `load_file_handling_errors' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.5/lib/rspec/core/configuration.rb:2144:in `load' from /Users/nicolas/PROJECTS/GITHUB/FORKS/netbox-client-ruby/spec/netbox_client_ruby/api/circuits/circuit_spec.rb:3:in `' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/3.3.0/bundled_gems.rb:69:in `block (2 levels) in replace_require' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/3.3.0/bundled_gems.rb:69:in `require' from /Users/nicolas/PROJECTS/GITHUB/FORKS/netbox-client-ruby/spec/spec_helper.rb:11:in `' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/3.3.0/bundled_gems.rb:69:in `block (2 levels) in replace_require' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/3.3.0/bundled_gems.rb:69:in `require' from /Users/nicolas/PROJECTS/GITHUB/FORKS/netbox-client-ruby/spec/shared_context.rb:3:in `' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.18/lib/zeitwerk/kernel.rb:34:in `require' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/3.3.0/bundled_gems.rb:69:in `block (2 levels) in replace_require' from /Users/nicolas/.asdf/installs/ruby/3.3.9/lib/ruby/3.3.0/bundled_gems.rb:69:in `require' --- spec/shared_context.rb | 5 ----- spec/spec_helper.rb | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 spec/shared_context.rb diff --git a/spec/shared_context.rb b/spec/shared_context.rb deleted file mode 100644 index 7512335..0000000 --- a/spec/shared_context.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require 'shared_contexts/netbox_client' -require 'shared_contexts/faraday' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9322e3c..062db0f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,8 @@ end require 'netbox-client-ruby' -require 'shared_context' +require_relative 'shared_contexts/netbox_client' +require_relative 'shared_contexts/faraday' require 'faraday/net_http_persistent' if Faraday::VERSION > '2' RSpec.configure do |config| From 29bd9b188e11aa97bb12a7ae74bb8e343320d732 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 30 Sep 2025 01:20:49 +0200 Subject: [PATCH 7/9] Improve Warning gem config, fix Ruby warning about ostruct --- Gemfile | 1 + gemfiles/faraday0.gemfile | 1 + gemfiles/faraday1.gemfile | 1 + gemfiles/faraday2.gemfile | 1 + spec/spec_helper.rb | 9 +++++++++ 5 files changed, 13 insertions(+) diff --git a/Gemfile b/Gemfile index 42a5e23..e5dfff4 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gemspec # Dev libs gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' +gem 'ostruct' gem 'pry' gem 'rake' gem 'rspec' diff --git a/gemfiles/faraday0.gemfile b/gemfiles/faraday0.gemfile index 2e62bf4..abd8a6a 100644 --- a/gemfiles/faraday0.gemfile +++ b/gemfiles/faraday0.gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "ostruct" gem "pry" gem "rake" gem "rspec" diff --git a/gemfiles/faraday1.gemfile b/gemfiles/faraday1.gemfile index 4d456d0..02d1905 100644 --- a/gemfiles/faraday1.gemfile +++ b/gemfiles/faraday1.gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "ostruct" gem "pry" gem "rake" gem "rspec" diff --git a/gemfiles/faraday2.gemfile b/gemfiles/faraday2.gemfile index 1645ae6..4d91d74 100644 --- a/gemfiles/faraday2.gemfile +++ b/gemfiles/faraday2.gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "ostruct" gem "pry" gem "rake" gem "rspec" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 062db0f..199869b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,16 +2,25 @@ require 'warning' +Warning[:deprecated] = true +Warning[:experimental] = true +Warning[:performance] = true if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3.0") + # Ignore all warnings in Gem dependencies Gem.path.each do |path| Warning.ignore(//, path) end +# Ignore OpenStruct warning (only used in tests) +Warning.ignore(/OpenStruct use is discouraged for performance reasons/) + +# Load gem require 'netbox-client-ruby' require_relative 'shared_contexts/netbox_client' require_relative 'shared_contexts/faraday' require 'faraday/net_http_persistent' if Faraday::VERSION > '2' +# Configure rspec RSpec.configure do |config| config.example_status_persistence_file_path = '.rspec_status' From c7449ced68f18a42393fd9a0f1c24e41c498077d Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 30 Sep 2025 01:36:57 +0200 Subject: [PATCH 8/9] Fix Rubocop offenses in spec --- .rubocop.yml | 48 +++++- .../api/circuits/circuit_spec.rb | 28 ++-- .../api/circuits/circuit_termination_spec.rb | 24 +-- .../api/circuits/circuit_type_spec.rb | 22 +-- .../api/circuits/provider_spec.rb | 22 +-- spec/netbox_client_ruby/api/circuits_spec.rb | 11 +- .../api/dcim/console_connection_spec.rb | 22 +-- .../api/dcim/console_port_spec.rb | 30 ++-- .../api/dcim/console_server_port_spec.rb | 30 ++-- .../api/dcim/device_role_spec.rb | 24 +-- .../api/dcim/device_spec.rb | 38 ++--- .../api/dcim/device_type_spec.rb | 30 ++-- .../api/dcim/interface_connection_spec.rb | 22 +-- .../api/dcim/interface_spec.rb | 26 ++-- .../api/dcim/inventory_item_spec.rb | 24 +-- .../api/dcim/mac_address_spec.rb | 28 ++-- .../api/dcim/manufacturer_spec.rb | 24 +-- .../api/dcim/platform_spec.rb | 24 +-- .../api/dcim/power_connection_spec.rb | 22 +-- .../api/dcim/power_outlet_spec.rb | 22 +-- .../api/dcim/power_port_spec.rb | 22 +-- .../api/dcim/rack_group_spec.rb | 22 +-- .../api/dcim/rack_reservation_spec.rb | 22 +-- .../api/dcim/rack_role_spec.rb | 22 +-- spec/netbox_client_ruby/api/dcim/rack_spec.rb | 24 +-- .../api/dcim/region_spec.rb | 36 ++--- spec/netbox_client_ruby/api/dcim/site_spec.rb | 30 ++-- .../netbox_client_ruby/api/dcim/sites_spec.rb | 4 +- .../api/dcim/virtual_chassis_spec.rb | 22 +-- spec/netbox_client_ruby/api/dcim_spec.rb | 9 +- .../api/extras/config_context_spec.rb | 26 ++-- .../api/extras/journal_entry_spec.rb | 28 ++-- .../netbox_client_ruby/api/extras/tag_spec.rb | 26 ++-- spec/netbox_client_ruby/api/extras_spec.rb | 4 +- .../api/ipam/aggregate_spec.rb | 30 ++-- .../api/ipam/ip_address_spec.rb | 36 ++--- .../api/ipam/ip_range_spec.rb | 38 ++--- .../api/ipam/prefix_spec.rb | 36 ++--- spec/netbox_client_ruby/api/ipam/rir_spec.rb | 26 ++-- spec/netbox_client_ruby/api/ipam/role_spec.rb | 28 ++-- .../api/ipam/service_spec.rb | 28 ++-- .../api/ipam/vlan_group_spec.rb | 28 ++-- spec/netbox_client_ruby/api/ipam/vlan_spec.rb | 32 ++-- spec/netbox_client_ruby/api/ipam/vrf_spec.rb | 32 ++-- spec/netbox_client_ruby/api/ipam_spec.rb | 11 +- .../api/secrets/secret_role_spec.rb | 26 ++-- .../api/secrets/secret_spec.rb | 30 ++-- .../api/secrets/session_key_spec.rb | 1 + spec/netbox_client_ruby/api/secrets_spec.rb | 17 +- .../api/tenancy/contact_group_spec.rb | 32 ++-- .../api/tenancy/contact_spec.rb | 30 ++-- .../api/tenancy/tenant_group_spec.rb | 26 ++-- .../api/tenancy/tenant_spec.rb | 30 ++-- spec/netbox_client_ruby/api/tenancy_spec.rb | 4 +- .../api/virtualization/cluster_group_spec.rb | 22 +-- .../api/virtualization/cluster_spec.rb | 24 +-- .../api/virtualization/cluster_type_spec.rb | 22 +-- .../api/virtualization/interface_spec.rb | 22 +-- .../virtualization/virtual_machine_spec.rb | 22 +-- .../api/virtualization_spec.rb | 7 +- spec/netbox_client_ruby/communication_spec.rb | 9 +- spec/netbox_client_ruby/connection_spec.rb | 32 ++-- spec/netbox_client_ruby/entities_spec.rb | 62 ++++---- .../entity_object_fields_spec.rb | 145 +++++++++--------- spec/netbox_client_ruby/entity_spec.rb | 79 +++++----- spec/netbox_client_ruby/netbox_spec.rb | 28 ++-- spec/shared_contexts/faraday.rb | 9 +- spec/shared_contexts/netbox_client.rb | 2 +- spec/spec_helper.rb | 2 +- 69 files changed, 947 insertions(+), 879 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3bfe4a5..6368d68 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,7 +12,6 @@ AllCops: Exclude: - bin/* - gemfiles/* - - spec/**/* - lib/netbox-client-ruby.rb Gemspec/RequireMFA: @@ -36,3 +35,50 @@ Style/TrailingCommaInArguments: Style/AccessModifierDeclarations: Enabled: false + +######### +# RSPEC # +######### + +RSpec/NotToNot: + EnforcedStyle: to_not + +RSpec/MultipleMemoizedHelpers: + Max: 10 + +RSpec/MultipleExpectations: + Max: 10 + +RSpec/NestedGroups: + Max: 5 + +RSpec/ExampleLength: + Max: 7 + +RSpec/MetadataStyle: + EnforcedStyle: hash + +RSpec/MessageSpies: + EnforcedStyle: receive + +# Configure me :) +RSpec/NamedSubject: + Enabled: false + +RSpec/ContextWording: + Enabled: false + +RSpec/SubjectDeclaration: + Enabled: false + +Style/OpenStructUse: + Enabled: false + +RSpec/VerifiedDoubles: + Enabled: false + +RSpec/SpecFilePathFormat: + Enabled: false + +RSpec/IteratedExpectation: + Enabled: false diff --git a/spec/netbox_client_ruby/api/circuits/circuit_spec.rb b/spec/netbox_client_ruby/api/circuits/circuit_spec.rb index 049d7fc..8288e14 100644 --- a/spec/netbox_client_ruby/api/circuits/circuit_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuit_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Circuits::Circuit, faraday_stub: true do + subject { described_class.new id } + let(:id) { 1 } let(:base_url) { '/api/circuits/circuits/' } let(:request_url) { "#{base_url}#{id}/" } 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) @@ -17,7 +17,7 @@ end describe '#description' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.description @@ -29,7 +29,7 @@ end describe '.tenant' do - it 'should be a Tenant object' do + it 'is a Tenant object' do tenant = subject.tenant expect(tenant).to be_a NetboxClientRuby::Tenancy::Tenant expect(tenant.id).to eq(1) @@ -37,7 +37,7 @@ end describe '.provider' do - it 'should be a Provider object' do + it 'is a Provider object' do provider = subject.provider expect(provider).to be_a NetboxClientRuby::Circuits::Provider expect(provider.id).to eq(1) @@ -45,7 +45,7 @@ end describe '.type' do - it 'should be a Type object' do + it 'is a Type object' do provider = subject.type expect(provider).to be_a NetboxClientRuby::Circuits::CircuitType expect(provider.id).to eq(1) @@ -57,7 +57,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -67,14 +67,14 @@ let(:request_method) { :patch } let(:request_params) { { 'description' => 'noob' } } - it 'should update the object' do + it 'updates 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 '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -87,14 +87,14 @@ let(:request_params) { { 'description' => description } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new id entity.description = description entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -117,15 +117,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.description = description entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/circuits/circuit_termination_spec.rb b/spec/netbox_client_ruby/api/circuits/circuit_termination_spec.rb index 63718ed..f016ede 100644 --- a/spec/netbox_client_ruby/api/circuits/circuit_termination_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuit_termination_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Circuits::CircuitTermination, faraday_stub: true do + subject { described_class.new id } + let(:id) { 1 } let(:base_url) { '/api/circuits/circuit-terminations/' } let(:request_url) { "#{base_url}#{id}/" } let(:response) { File.read("spec/fixtures/circuits/circuit-termination_#{id}.json") } - subject { described_class.new id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(id) @@ -17,7 +17,7 @@ end describe '#term_side' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.term_side @@ -29,7 +29,7 @@ end describe '.site' do - it 'should be a Site object' do + it 'is a Site object' do site = subject.site expect(site).to be_a NetboxClientRuby::DCIM::Site expect(site.id).to eq(1) @@ -41,7 +41,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -51,14 +51,14 @@ let(:request_method) { :patch } let(:request_params) { { 'term_side' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(term_side: 'noob').term_side).to eq('A') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -71,14 +71,14 @@ let(:request_params) { { 'term_side' => term_side } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new id entity.term_side = term_side entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -101,15 +101,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.term_side = term_side entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/circuits/circuit_type_spec.rb b/spec/netbox_client_ruby/api/circuits/circuit_type_spec.rb index 88cce4b..b0a5394 100644 --- a/spec/netbox_client_ruby/api/circuits/circuit_type_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/circuit_type_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Circuits::CircuitType, faraday_stub: true do + subject { described_class.new id } + let(:id) { 1 } let(:base_url) { '/api/circuits/circuit-types/' } let(:request_url) { "#{base_url}#{id}/" } let(:response) { File.read("spec/fixtures/circuits/circuit-type_#{id}.json") } - subject { described_class.new id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -33,7 +33,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -43,14 +43,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('Circuit Type 0') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -63,14 +63,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -93,15 +93,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/circuits/provider_spec.rb b/spec/netbox_client_ruby/api/circuits/provider_spec.rb index ac5eb6c..e864a6d 100644 --- a/spec/netbox_client_ruby/api/circuits/provider_spec.rb +++ b/spec/netbox_client_ruby/api/circuits/provider_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Circuits::Provider, faraday_stub: true do + subject { described_class.new id } + let(:id) { 1 } let(:base_url) { '/api/circuits/providers/' } let(:request_url) { "#{base_url}#{id}/" } let(:response) { File.read("spec/fixtures/circuits/provider_#{id}.json") } - subject { described_class.new id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -33,7 +33,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -43,14 +43,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('Circuit Provider 0') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -63,14 +63,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -93,15 +93,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/circuits_spec.rb b/spec/netbox_client_ruby/api/circuits_spec.rb index e707e64..8382356 100644 --- a/spec/netbox_client_ruby/api/circuits_spec.rb +++ b/spec/netbox_client_ruby/api/circuits_spec.rb @@ -7,7 +7,7 @@ providers: NetboxClientRuby::Circuits::Providers, circuits: NetboxClientRuby::Circuits::Circuits, circuit_terminations: NetboxClientRuby::Circuits::CircuitTerminations, - circuit_types: NetboxClientRuby::Circuits::CircuitTypes + circuit_types: NetboxClientRuby::Circuits::CircuitTypes, }.each do |method, klass| describe ".#{method}" do subject { described_class.public_send(method) } @@ -18,7 +18,7 @@ context 'is a different instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method) end end @@ -33,19 +33,20 @@ provider: NetboxClientRuby::Circuits::Provider, circuit: NetboxClientRuby::Circuits::Circuit, circuit_termination: NetboxClientRuby::Circuits::CircuitTermination, - circuit_type: NetboxClientRuby::Circuits::CircuitType + circuit_type: NetboxClientRuby::Circuits::CircuitType, }.each do |method, expected_class| describe ".#{method}" do - let(:id) { 1 } subject { described_class.public_send(method, id) } + let(:id) { 1 } + context 'is of the expected type' do it { is_expected.to be_a expected_class } end context 'it is a new instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method, id) end end diff --git a/spec/netbox_client_ruby/api/dcim/console_connection_spec.rb b/spec/netbox_client_ruby/api/dcim/console_connection_spec.rb index 6360a93..dc6772f 100644 --- a/spec/netbox_client_ruby/api/dcim/console_connection_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_connection_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::ConsoleConnection, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'rj45' } let(:base_url) { '/api/dcim/console-connections/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'foobar' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'foobar').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/console_port_spec.rb b/spec/netbox_client_ruby/api/dcim/console_port_spec.rb index 2ac9412..11b52a6 100644 --- a/spec/netbox_client_ruby/api/dcim/console_port_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_port_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::ConsolePort, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'rj45' } let(:base_url) { '/api/dcim/console-ports/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -31,20 +31,20 @@ end describe '#device' do - it 'should return a Device' do + it 'returns a Device' do expect(subject.device).to be_a(NetboxClientRuby::DCIM::Device) end end - describe '#device' do - it 'should return a Device' do + describe '#cs_port' do + it 'returns a Device' do expect(subject.cs_port).to be_a(NetboxClientRuby::DCIM::ConsoleServerPort) end context 'unconnected port' do let(:entity_id) { 3 } - it 'should return nil' do + it 'returns nil' do expect(subject.cs_port).to be_nil end end @@ -55,7 +55,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -65,14 +65,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -85,14 +85,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -115,15 +115,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/console_server_port_spec.rb b/spec/netbox_client_ruby/api/dcim/console_server_port_spec.rb index 61b9cbd..996cc20 100644 --- a/spec/netbox_client_ruby/api/dcim/console_server_port_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/console_server_port_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::ConsoleServerPort, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'Console Server Port 0' } let(:base_url) { '/api/dcim/console-server-ports/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -31,20 +31,20 @@ end describe '#device' do - it 'should return a Device' do + it 'returns a Device' do expect(subject.device).to be_a(NetboxClientRuby::DCIM::Device) end end - describe '#device' do - it 'should return a Device' do + describe '#connected_console' do + it 'returns a Device' do expect(subject.connected_console).to be_a(NetboxClientRuby::DCIM::ConsolePort) end context 'unconnected port' do let(:entity_id) { 3 } - it 'should return nil' do + it 'returns nil' do expect(subject.connected_console).to be_nil end end @@ -55,7 +55,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -65,14 +65,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -85,14 +85,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -115,15 +115,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/device_role_spec.rb b/spec/netbox_client_ruby/api/dcim/device_role_spec.rb index 5c401ab..fd0c532 100644 --- a/spec/netbox_client_ruby/api/dcim/device_role_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/device_role_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::DeviceRole, faraday_stub: true do + subject { sut.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'devicerole1' } - let(:sut) { NetboxClientRuby::DCIM::DeviceRole } + let(:sut) { described_class } let(:base_url) { '/api/dcim/device-roles/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/device-role_#{entity_id}.json") } - subject { sut.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -36,7 +36,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -46,14 +46,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -67,8 +67,6 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do region = sut.new entity_id region.name = name @@ -76,6 +74,8 @@ region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -100,9 +100,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = sut.new region.name = name @@ -110,6 +107,9 @@ region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/device_spec.rb b/spec/netbox_client_ruby/api/dcim/device_spec.rb index 72fb5ab..1e66538 100644 --- a/spec/netbox_client_ruby/api/dcim/device_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/device_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::Device, faraday_stub: true do + subject { sut.new entity_id } + let(:entity_id) { 2 } let(:expected_name) { 'device2' } - let(:sut) { NetboxClientRuby::DCIM::Device } + let(:sut) { described_class } let(:base_url) { '/api/dcim/devices/' } let(:response) { File.read("spec/fixtures/dcim/device_#{entity_id}.json") } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { sut.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -40,35 +40,35 @@ rack: [NetboxClientRuby::DCIM::Rack, 1], primary_ip: [NetboxClientRuby::IPAM::IpAddress, 5], primary_ip4: [NetboxClientRuby::IPAM::IpAddress, 1], - primary_ip6: [NetboxClientRuby::IPAM::IpAddress, 5] + primary_ip6: [NetboxClientRuby::IPAM::IpAddress, 5], }.each do |method_name, expected_values| expected_type = expected_values[0] expected_id = expected_values[1] describe "##{method_name}" do - it "should return a #{expected_type}" do + it "returns a #{expected_type}" do expect(subject.public_send(method_name)) .to be_a(expected_type) end - it "should be the expected #{method_name}" do + it "is the expected #{method_name}" do expect(subject.public_send(method_name).id).to eq(expected_id) end end end - describe "#tags" do - it "should return an Array" do + describe '#tags' do + it 'returns an Array' do expect(subject.tags) .to be_a(Array) end - it "should have NetboxClientRuby::Extras::Tag as elements" do + it 'has NetboxClientRuby::Extras::Tag as elements' do expect(subject.tags[0]) .to be_a(NetboxClientRuby::Extras::Tag) end - it "should be the expected tag" do + it 'is the expected tag' do expect(subject.tags[0].id).to eq(1) end end @@ -78,7 +78,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -88,14 +88,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -109,8 +109,6 @@ let(:request_params) { { 'name' => name, 'display_name' => display_name } } context 'update' do - let(:request_method) { :patch } - subject do region = sut.new entity_id region.name = name @@ -118,6 +116,8 @@ region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -142,9 +142,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = sut.new region.name = name @@ -152,6 +149,9 @@ region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/device_type_spec.rb b/spec/netbox_client_ruby/api/dcim/device_type_spec.rb index 90648f1..10910e0 100644 --- a/spec/netbox_client_ruby/api/dcim/device_type_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/device_type_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::DeviceType, faraday_stub: true do + subject { sut.new entity_id } + let(:entity_id) { 1 } let(:expected_model) { 'devicetype1' } - let(:sut) { NetboxClientRuby::DCIM::DeviceType } + let(:sut) { described_class } let(:base_url) { '/api/dcim/device-types/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/device-type_#{entity_id}.json") } - subject { sut.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#model' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.model).to_not be_nil @@ -32,17 +32,17 @@ end describe '#manufacturer' do - it 'should return a Manufacturer' do + it 'returns a Manufacturer' do expect(subject.manufacturer).to be_a(NetboxClientRuby::DCIM::Manufacturer) end - it 'should be the expected manufacturer' do + it 'is the expected manufacturer' do expect(subject.manufacturer.id).to be(1) end end describe '#interface_ordering' do - it 'should return a InterfaceOrdering' do + it 'returns a InterfaceOrdering' do expect(subject.interface_ordering).to be_a(NetboxClientRuby::DCIM::InterfaceOrdering) end end @@ -52,7 +52,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -62,14 +62,14 @@ let(:request_method) { :patch } let(:request_params) { { 'model' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(model: 'noob').model).to eq(expected_model) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -83,8 +83,6 @@ let(:request_params) { { 'model' => model, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do region = sut.new entity_id region.model = model @@ -92,6 +90,8 @@ region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -116,9 +116,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = sut.new region.model = model @@ -126,6 +123,9 @@ region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/interface_connection_spec.rb b/spec/netbox_client_ruby/api/dcim/interface_connection_spec.rb index a6e708f..0abbc49 100644 --- a/spec/netbox_client_ruby/api/dcim/interface_connection_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/interface_connection_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::InterfaceConnection, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 9 } let(:expected_connection_status) { true } let(:base_url) { '/api/dcim/interface-connections/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#connection_status' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.connection_status['value']).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'connection_status' => false } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(connection_status: false).connection_status['value']).to eq(expected_connection_status) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'connection_status' => connection_status } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.connection_status = connection_status entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.connection_status = connection_status entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/interface_spec.rb b/spec/netbox_client_ruby/api/dcim/interface_spec.rb index 90bc5ba..6f46964 100644 --- a/spec/netbox_client_ruby/api/dcim/interface_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/interface_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::Interface, faraday_stub: true do + subject { sut.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'e0' } - let(:sut) { NetboxClientRuby::DCIM::Interface } + let(:sut) { described_class } let(:base_url) { '/api/dcim/interfaces/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/interface_#{entity_id}.json") } - subject { sut.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -32,7 +32,7 @@ end describe '#device' do - it 'should fetch data' do + it 'fetches data' do expect(faraday).to receive(:get).and_call_original expect(subject.device).to_not be_nil @@ -52,7 +52,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -62,14 +62,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -82,14 +82,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do region = sut.new entity_id region.name = name region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -112,15 +112,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = sut.new region.name = name region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/inventory_item_spec.rb b/spec/netbox_client_ruby/api/dcim/inventory_item_spec.rb index f4be6f0..6ab948e 100644 --- a/spec/netbox_client_ruby/api/dcim/inventory_item_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/inventory_item_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::InventoryItem, faraday_stub: true do + subject { sut.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'inventory_item1' } - let(:sut) { NetboxClientRuby::DCIM::InventoryItem } + let(:sut) { described_class } let(:base_url) { '/api/dcim/inventory-items/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/inventory-item_#{entity_id}.json") } - subject { sut.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -36,7 +36,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -46,14 +46,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -66,14 +66,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do region = sut.new entity_id region.name = name region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -96,15 +96,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = sut.new region.name = name region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/mac_address_spec.rb b/spec/netbox_client_ruby/api/dcim/mac_address_spec.rb index 8dfca66..046db5b 100644 --- a/spec/netbox_client_ruby/api/dcim/mac_address_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/mac_address_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::MacAddress, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:base_url) { '/api/dcim/mac-addresses/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/mac-address_#{entity_id}.json") } - subject { NetboxClientRuby::DCIM::MacAddress.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -17,7 +17,7 @@ end describe '#mac_address' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.mac_address @@ -33,7 +33,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -44,14 +44,14 @@ let(:request_params) { { 'mac_address' => '23:2f:bd:ad:aa:d2' } } let(:response) { File.read("spec/fixtures/dcim/mac-address_#{entity_id}-update.json") } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(mac_address: '23:2f:bd:ad:aa:d2').mac_address).to eq('23:2f:bd:ad:aa:d2') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -67,21 +67,21 @@ { 'mac_address' => mac_address, 'assigned_object_type' => assigned_object_type, - 'assigned_object_id' => assigned_object_id + 'assigned_object_id' => assigned_object_id, } end context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::DCIM::MacAddress.new entity_id + entity = described_class.new entity_id entity.mac_address = mac_address entity.assigned_object_type = assigned_object_type entity.assigned_object_id = assigned_object_id entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -108,17 +108,17 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::DCIM::MacAddress.new + entity = described_class.new entity.mac_address = mac_address entity.assigned_object_type = assigned_object_type entity.assigned_object_id = assigned_object_id entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/manufacturer_spec.rb b/spec/netbox_client_ruby/api/dcim/manufacturer_spec.rb index 0e2e1f3..dedd867 100644 --- a/spec/netbox_client_ruby/api/dcim/manufacturer_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/manufacturer_spec.rb @@ -3,15 +3,15 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::Manufacturer, faraday_stub: true do + subject { sut.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'manu1' } - let(:sut) { NetboxClientRuby::DCIM::Manufacturer } + let(:sut) { described_class } let(:base_url) { '/api/dcim/manufacturers/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/manufacturer_#{entity_id}.json") } - subject { sut.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -66,8 +66,6 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do region = sut.new entity_id region.name = name @@ -75,6 +73,8 @@ region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -99,9 +99,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = sut.new region.name = name @@ -109,6 +106,9 @@ region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/platform_spec.rb b/spec/netbox_client_ruby/api/dcim/platform_spec.rb index 9421005..e2461fb 100644 --- a/spec/netbox_client_ruby/api/dcim/platform_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/platform_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::Platform, faraday_stub: true do + subject { sut.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'platform1' } - let(:sut) { NetboxClientRuby::DCIM::Platform } + let(:sut) { described_class } let(:base_url) { '/api/dcim/platforms/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/platform_#{entity_id}.json") } - subject { sut.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -36,7 +36,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -46,14 +46,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -67,8 +67,6 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do region = sut.new entity_id region.name = name @@ -76,6 +74,8 @@ region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -100,9 +100,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = sut.new region.name = name @@ -110,6 +107,9 @@ region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/power_connection_spec.rb b/spec/netbox_client_ruby/api/dcim/power_connection_spec.rb index 8b6fb6e..27f19e1 100644 --- a/spec/netbox_client_ruby/api/dcim/power_connection_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/power_connection_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::PowerConnection, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'power port 0' } let(:base_url) { '/api/dcim/power-connections/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'foobar' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'foobar').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/power_outlet_spec.rb b/spec/netbox_client_ruby/api/dcim/power_outlet_spec.rb index 56783a3..2d821eb 100644 --- a/spec/netbox_client_ruby/api/dcim/power_outlet_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/power_outlet_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::PowerOutlet, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 3 } let(:expected_name) { '3' } let(:base_url) { '/api/dcim/power-outlets/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/power-outlets_#{entity_id}.json") } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do region = described_class.new entity_id region.name = name region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = described_class.new region.name = name region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/power_port_spec.rb b/spec/netbox_client_ruby/api/dcim/power_port_spec.rb index 186178c..8a7464b 100644 --- a/spec/netbox_client_ruby/api/dcim/power_port_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/power_port_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::PowerPort, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 3 } let(:expected_name) { 'psu1' } let(:base_url) { '/api/dcim/power-ports/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/dcim/power-ports_#{entity_id}.json") } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do region = described_class.new entity_id region.name = name region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do region = described_class.new region.name = name region end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/rack_group_spec.rb b/spec/netbox_client_ruby/api/dcim/rack_group_spec.rb index fbad820..5b35e49 100644 --- a/spec/netbox_client_ruby/api/dcim/rack_group_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/rack_group_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::RackGroup, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'Colozüri 4.1' } let(:base_url) { '/api/dcim/rack-groups/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -66,8 +66,6 @@ let(:request_params) { { 'name' => name, 'facility' => facility } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name @@ -75,6 +73,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -99,9 +99,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name @@ -109,6 +106,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/rack_reservation_spec.rb b/spec/netbox_client_ruby/api/dcim/rack_reservation_spec.rb index 6397ab5..eaa51bb 100644 --- a/spec/netbox_client_ruby/api/dcim/rack_reservation_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/rack_reservation_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::RackReservation, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_description) { 'Reservation 0' } let(:base_url) { '/api/dcim/rack-reservations/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#description' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.description).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'description' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(description: 'noob').description).to eq(expected_description) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'description' => description } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.description = description entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.description = description entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/rack_role_spec.rb b/spec/netbox_client_ruby/api/dcim/rack_role_spec.rb index 1421cc0..78a3092 100644 --- a/spec/netbox_client_ruby/api/dcim/rack_role_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/rack_role_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::RackRole, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'Housing' } let(:base_url) { '/api/dcim/rack-roles/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/rack_spec.rb b/spec/netbox_client_ruby/api/dcim/rack_spec.rb index ac7dd2c..a91d125 100644 --- a/spec/netbox_client_ruby/api/dcim/rack_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/rack_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::Rack, faraday_stub: true do + subject { sut.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { 'test2rack' } - let(:sut) { NetboxClientRuby::DCIM::Rack } + let(:sut) { described_class } let(:base_url) { '/api/dcim/racks/' } let(:response) { File.read("spec/fixtures/dcim/rack_#{entity_id}.json") } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { sut.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -36,7 +36,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -46,14 +46,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -67,8 +67,6 @@ let(:request_params) { { 'name' => name, 'display_name' => display_name } } context 'update' do - let(:request_method) { :patch } - subject do entity = sut.new entity_id entity.name = name @@ -76,6 +74,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -100,9 +100,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = sut.new entity.name = name @@ -110,6 +107,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/region_spec.rb b/spec/netbox_client_ruby/api/dcim/region_spec.rb index 7529416..b011461 100644 --- a/spec/netbox_client_ruby/api/dcim/region_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/region_spec.rb @@ -3,12 +3,12 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::Region, faraday_stub: true do + subject { described_class.new region_id } + let(:region_id) { 1 } let(:response) { File.read("spec/fixtures/dcim/region_#{region_id}.json") } let(:request_url) { "/api/dcim/regions/#{region_id}/" } - subject { NetboxClientRuby::DCIM::Region.new region_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(region_id) @@ -16,7 +16,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -28,16 +28,16 @@ end describe '.parent' do - it 'should be nil' do + it 'is nil' do expect(subject.parent).to be_nil end context 'Sub Region' do let(:region_id) { 2 } - it 'should be a Region object' do + it 'is a Region object' do parent_region = subject.parent - expect(parent_region).to be_a NetboxClientRuby::DCIM::Region + expect(parent_region).to be_a described_class expect(parent_region.id).to eq(1) end end @@ -48,7 +48,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -58,7 +58,7 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('region1') end @@ -69,7 +69,7 @@ context 'delete a parent' do let(:request_params) { { 'parent' => nil } } - it 'should remove the parent' do + it 'removes the parent' do expect(subject.update(parent: nil)).to be subject end end @@ -77,7 +77,7 @@ context 'add a parent' do let(:request_params) { { 'parent' => 1 } } - it 'should add a parent' do + it 'adds a parent' do expect(subject.update(parent: 1)).to be subject end end @@ -85,7 +85,7 @@ end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -99,15 +99,15 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do - region = NetboxClientRuby::DCIM::Region.new region_id + region = described_class.new region_id region.name = name region.slug = slug region end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -132,16 +132,16 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { '/api/dcim/regions/' } - subject do - region = NetboxClientRuby::DCIM::Region.new + region = described_class.new region.name = name region.slug = slug region end + let(:request_method) { :post } + let(:request_url) { '/api/dcim/regions/' } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/site_spec.rb b/spec/netbox_client_ruby/api/dcim/site_spec.rb index 18805ec..6d5c85a 100644 --- a/spec/netbox_client_ruby/api/dcim/site_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/site_spec.rb @@ -3,12 +3,12 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::Site, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:response) { File.read("spec/fixtures/dcim/site_#{entity_id}.json") } let(:request_url) { "/api/dcim/sites/#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -16,7 +16,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -28,11 +28,11 @@ end describe '#count_prefixes' do - it 'should have the expected value' do + it 'has the expected value' do expect(subject.count_prefixes).to eq(0) end - it 'should not be updateable' do + it 'is not updateable' do expect { subject.count_prefixes = 2 }.to raise_exception(NoMethodError) end end @@ -40,10 +40,10 @@ { region: NetboxClientRuby::DCIM::Region, tenant: NetboxClientRuby::Tenancy::Tenant, - status: Symbol + status: Symbol, }.each_pair do |method_name, expected_type| describe ".#{method_name}" do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.public_send(method_name)).to_not be_nil @@ -60,7 +60,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -70,14 +70,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('test') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -91,8 +91,6 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name @@ -100,6 +98,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -124,9 +124,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { '/api/dcim/sites/' } - subject do entity = described_class.new entity.name = name @@ -134,6 +131,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { '/api/dcim/sites/' } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim/sites_spec.rb b/spec/netbox_client_ruby/api/dcim/sites_spec.rb index 3a922dc..6b0f198 100644 --- a/spec/netbox_client_ruby/api/dcim/sites_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/sites_spec.rb @@ -3,14 +3,14 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::Sites, faraday_stub: true do + subject { described_class.new } + let(:response) { File.read('spec/fixtures/dcim/sites.json') } let(:request_url) { '/api/dcim/sites/' } let(:request_url_params) do { limit: NetboxClientRuby.config.netbox.pagination.default_limit } end - subject { NetboxClientRuby::DCIM::Sites.new } - context 'unpaged fetch' do describe '#length' do it 'shall be the expected length' do diff --git a/spec/netbox_client_ruby/api/dcim/virtual_chassis_spec.rb b/spec/netbox_client_ruby/api/dcim/virtual_chassis_spec.rb index 6296e51..bb83881 100644 --- a/spec/netbox_client_ruby/api/dcim/virtual_chassis_spec.rb +++ b/spec/netbox_client_ruby/api/dcim/virtual_chassis_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::DCIM::VirtualChassis, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_domain) { 'Virtual Chassis 0' } let(:base_url) { '/api/dcim/virtual-chassis/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#domain' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.domain).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'domain' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(domain: 'noob').domain).to eq(expected_domain) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'domain' => domain } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.domain = domain entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.domain = domain entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/dcim_spec.rb b/spec/netbox_client_ruby/api/dcim_spec.rb index fa2fdd7..823d747 100644 --- a/spec/netbox_client_ruby/api/dcim_spec.rb +++ b/spec/netbox_client_ruby/api/dcim_spec.rb @@ -27,7 +27,7 @@ module DCIM rack_roles: RackRoles, regions: Regions, sites: Sites, - virtual_chassis_list: VirtualChassisList + virtual_chassis_list: VirtualChassisList, }.each do |method, expected_class| describe ".#{method}" do subject { described_class.public_send(method) } @@ -38,7 +38,7 @@ module DCIM context 'is a different instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method) end end @@ -71,10 +71,11 @@ module DCIM rack_role: RackRole, region: Region, site: Site, - virtual_chassis: VirtualChassis + virtual_chassis: VirtualChassis, }.each do |method, expected_class| describe ".#{method}" do let(:id) { 1 } + subject { described_class.public_send(method, id) } context 'is of the expected type' do @@ -83,7 +84,7 @@ module DCIM context 'it is a new instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method, id) end end diff --git a/spec/netbox_client_ruby/api/extras/config_context_spec.rb b/spec/netbox_client_ruby/api/extras/config_context_spec.rb index 75e3add..e8d7212 100644 --- a/spec/netbox_client_ruby/api/extras/config_context_spec.rb +++ b/spec/netbox_client_ruby/api/extras/config_context_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Extras::ConfigContext, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:base_url) { '/api/extras/config-contexts/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/extras/config_context_#{entity_id}.json") } - subject { NetboxClientRuby::Extras::ConfigContext.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -33,7 +33,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -43,14 +43,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('Production') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -64,15 +64,15 @@ let(:request_params) { { 'name' => name, 'weight' => weight } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Extras::ConfigContext.new entity_id + entity = described_class.new entity_id entity.name = name entity.weight = weight entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -97,16 +97,16 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Extras::ConfigContext.new + entity = described_class.new entity.name = name entity.weight = weight entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/extras/journal_entry_spec.rb b/spec/netbox_client_ruby/api/extras/journal_entry_spec.rb index 6cdd0e1..545f964 100644 --- a/spec/netbox_client_ruby/api/extras/journal_entry_spec.rb +++ b/spec/netbox_client_ruby/api/extras/journal_entry_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Extras::JournalEntry, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:base_url) { '/api/extras/journal-entries/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/extras/journal_entry_#{entity_id}.json") } - subject { NetboxClientRuby::Extras::JournalEntry.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -17,7 +17,7 @@ end describe '#comments' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.comments @@ -33,7 +33,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -43,14 +43,14 @@ let(:request_method) { :patch } let(:request_params) { { 'comments' => 'Hi' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(comments: 'Hi').comments).to eq('Hello') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -66,21 +66,21 @@ { 'comments' => comments, 'assigned_object_type' => assigned_object_type, - 'assigned_object_id' => assigned_object_id + 'assigned_object_id' => assigned_object_id, } end context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Extras::JournalEntry.new entity_id + entity = described_class.new entity_id entity.comments = comments entity.assigned_object_type = assigned_object_type entity.assigned_object_id = assigned_object_id entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -107,17 +107,17 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Extras::JournalEntry.new + entity = described_class.new entity.comments = comments entity.assigned_object_type = assigned_object_type entity.assigned_object_id = assigned_object_id entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/extras/tag_spec.rb b/spec/netbox_client_ruby/api/extras/tag_spec.rb index 13d4231..dae3f5b 100644 --- a/spec/netbox_client_ruby/api/extras/tag_spec.rb +++ b/spec/netbox_client_ruby/api/extras/tag_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Extras::Tag, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:base_url) { '/api/extras/tags/' } let(:request_url) { "#{base_url}#{entity_id}/" } let(:response) { File.read("spec/fixtures/extras/tag_#{entity_id}.json") } - subject { NetboxClientRuby::Extras::Tag.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -33,7 +33,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -43,14 +43,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('Production') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -64,15 +64,15 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Extras::Tag.new entity_id + entity = described_class.new entity_id entity.name = name entity.slug = slug entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -97,16 +97,16 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Extras::Tag.new + entity = described_class.new entity.name = name entity.slug = slug entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/extras_spec.rb b/spec/netbox_client_ruby/api/extras_spec.rb index f8b65cf..706768e 100644 --- a/spec/netbox_client_ruby/api/extras_spec.rb +++ b/spec/netbox_client_ruby/api/extras_spec.rb @@ -4,7 +4,7 @@ RSpec.describe NetboxClientRuby::Extras do { - tags: NetboxClientRuby::Extras::Tags + tags: NetboxClientRuby::Extras::Tags, }.each do |method, klass| describe ".#{method}" do subject { described_class.public_send(method) } @@ -15,7 +15,7 @@ context 'is a different instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method) end end diff --git a/spec/netbox_client_ruby/api/ipam/aggregate_spec.rb b/spec/netbox_client_ruby/api/ipam/aggregate_spec.rb index 97e3536..5547017 100644 --- a/spec/netbox_client_ruby/api/ipam/aggregate_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/aggregate_spec.rb @@ -3,7 +3,9 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::IPAM::Aggregate, faraday_stub: true do - let(:class_under_test) { NetboxClientRuby::IPAM::Aggregate } + subject { class_under_test.new entity_id } + + let(:class_under_test) { described_class } let(:base_url) { '/api/ipam/aggregates/' } let(:response) { File.read("spec/fixtures/ipam/aggregate_#{entity_id}.json") } @@ -11,8 +13,6 @@ let(:entity_id) { 1 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { class_under_test.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#prefix' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.prefix).to_not be_nil @@ -33,7 +33,7 @@ describe '.rir' do context 'entity with rir' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.rir).to_not be_nil @@ -43,7 +43,7 @@ expect(subject.rir).to be_a(NetboxClientRuby::IPAM::Rir) end - it 'should an entity with the right it' do + it 'ans entity with the right it' do expect(subject.rir.id).to eq(entity_id) end end @@ -54,7 +54,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -64,14 +64,14 @@ let(:request_method) { :patch } let(:request_params) { { 'prefix' => '192.168.0.0/16' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(prefix: '192.168.0.0/16').prefix).to eq(expected_prefix) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -84,14 +84,14 @@ let(:request_params) { { 'prefix' => prefix } } context 'update' do - let(:request_method) { :patch } - subject do entity = class_under_test.new entity_id entity.prefix = prefix entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -113,16 +113,16 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do entity = class_under_test.new entity.prefix = prefix entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/ip_address_spec.rb b/spec/netbox_client_ruby/api/ipam/ip_address_spec.rb index 02fef88..c5bcc91 100644 --- a/spec/netbox_client_ruby/api/ipam/ip_address_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/ip_address_spec.rb @@ -4,7 +4,9 @@ require 'ipaddress' RSpec.describe NetboxClientRuby::IPAM::IpAddress, faraday_stub: true do - let(:class_under_test) { NetboxClientRuby::IPAM::IpAddress } + subject { class_under_test.new entity_id } + + let(:class_under_test) { described_class } let(:base_url) { '/api/ipam/ip-addresses/' } let(:response) { File.read("spec/fixtures/ipam/ip-address_#{entity_id}.json") } @@ -12,8 +14,6 @@ let(:entity_id) { 1 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { class_under_test.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -21,7 +21,7 @@ end describe '#address' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.address @@ -81,10 +81,10 @@ { vrf: NetboxClientRuby::IPAM::Vrf, tenant: NetboxClientRuby::Tenancy::Tenant, - status: Symbol + status: Symbol, }.each_pair do |method_name, expected_type| describe ".#{method_name}" do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.public_send(method_name)).to_not be_nil @@ -97,7 +97,7 @@ end describe '.status' do - it 'should return the correct symbol' do + it 'returns the correct symbol' do expect(subject.status).to eq(:active) end end @@ -107,7 +107,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -118,7 +118,7 @@ let(:request_method) { :patch } let(:request_params) { { 'address' => address } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(address: address).address).to eq(expected_address) end @@ -126,7 +126,7 @@ context 'status update' do let(:request_params) { { 'status' => 2 } } - it 'should resolve the status to a number' do + it 'resolves the status to a number' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(status: :reserved).status).to eq(:active) end @@ -134,7 +134,7 @@ context 'with an unknown status' do let(:request_params) { { 'status' => 42 } } - it 'should send a request with the unknown status' do + it 'sends a request with the unknown status' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(status: 42).status).to eq(:active) end @@ -143,7 +143,7 @@ end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -156,14 +156,14 @@ let(:request_params) { { 'address' => address } } context 'update' do - let(:request_method) { :patch } - subject do entity = class_under_test.new entity_id entity.address = address entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -185,16 +185,16 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do entity = class_under_test.new entity.address = address entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/ip_range_spec.rb b/spec/netbox_client_ruby/api/ipam/ip_range_spec.rb index 99eac8d..df83334 100644 --- a/spec/netbox_client_ruby/api/ipam/ip_range_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/ip_range_spec.rb @@ -4,7 +4,9 @@ require 'ipaddress' RSpec.describe NetboxClientRuby::IPAM::IpRange, faraday_stub: true do - let(:class_under_test) { NetboxClientRuby::IPAM::IpRange } + subject { class_under_test.new entity_id } + + let(:class_under_test) { described_class } let(:base_url) { '/api/ipam/ip-ranges/' } let(:response) { File.read("spec/fixtures/ipam/ip-range_#{entity_id}.json") } @@ -13,8 +15,6 @@ let(:entity_id) { 3 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { class_under_test.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -22,7 +22,7 @@ end describe '#start_address' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.start_address @@ -34,7 +34,7 @@ end describe '#end_address' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.end_address @@ -51,11 +51,11 @@ status: NetboxClientRuby::IPAM::IpRangeStatus, role: NetboxClientRuby::IPAM::Role, start_address: IPAddress, - end_address: IPAddress + end_address: IPAddress, }.each_pair do |method_name, expected_type| context 'entity with references' do describe ".#{method_name}" do - it 'should fetch the data and not return nil' do + it 'fetches the data and not return nil' do expect(faraday).to receive(:get).and_call_original expect(subject.public_send(method_name)).to_not be_nil @@ -69,10 +69,10 @@ context 'entity without references' do describe ".#{method_name}" do - it 'should fetch the data and return nil' do + it 'fetches the data and return nil' do expect(faraday).to receive(:get).and_call_original - expect(subject.public_send(method_name)).to be + expect(subject.public_send(method_name)).to_not be_nil end it 'shall return the expected type' do @@ -83,7 +83,7 @@ end describe '.status' do - it 'should assign the correct value' do + it 'assigns the correct value' do expect(subject.status.label).to eq('Active') end end @@ -93,7 +93,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -104,14 +104,14 @@ let(:request_method) { :patch } let(:request_params) { { 'start_address' => start_address } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(start_address: start_address).start_address).to eq(expected_start_address) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -124,14 +124,14 @@ let(:request_params) { { 'start_address' => start_address } } context 'update' do - let(:request_method) { :patch } - subject do entity = class_under_test.new entity_id entity.start_address = start_address entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -153,16 +153,16 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do entity = class_under_test.new entity.start_address = start_address entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/prefix_spec.rb b/spec/netbox_client_ruby/api/ipam/prefix_spec.rb index fe81776..0a84d24 100644 --- a/spec/netbox_client_ruby/api/ipam/prefix_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/prefix_spec.rb @@ -4,7 +4,9 @@ require 'ipaddress' RSpec.describe NetboxClientRuby::IPAM::Prefix, faraday_stub: true do - let(:class_under_test) { NetboxClientRuby::IPAM::Prefix } + subject { class_under_test.new entity_id } + + let(:class_under_test) { described_class } let(:base_url) { '/api/ipam/prefixes/' } let(:response) { File.read("spec/fixtures/ipam/prefix_#{entity_id}.json") } @@ -12,8 +14,6 @@ let(:entity_id) { 3 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { class_under_test.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -21,7 +21,7 @@ end describe '#prefix' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.prefix @@ -39,11 +39,11 @@ vlan: NetboxClientRuby::IPAM::Vlan, status: NetboxClientRuby::IPAM::PrefixStatus, role: NetboxClientRuby::IPAM::Role, - prefix: IPAddress + prefix: IPAddress, }.each_pair do |method_name, expected_type| context 'entity with references' do describe ".#{method_name}" do - it 'should fetch the data and not return nil' do + it 'fetches the data and not return nil' do expect(faraday).to receive(:get).and_call_original expect(subject.public_send(method_name)).to_not be_nil @@ -57,10 +57,10 @@ context 'entity without references' do describe ".#{method_name}" do - it 'should fetch the data and return nil' do + it 'fetches the data and return nil' do expect(faraday).to receive(:get).and_call_original - expect(subject.public_send(method_name)).to be + expect(subject.public_send(method_name)).to_not be_nil end it 'shall return the expected type' do @@ -71,7 +71,7 @@ end describe '.status' do - it 'should assign the correct value' do + it 'assigns the correct value' do expect(subject.status.label).to eq('Container') end end @@ -81,7 +81,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -92,14 +92,14 @@ let(:request_method) { :patch } let(:request_params) { { 'prefix' => prefix } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(prefix: prefix).prefix).to eq(expected_prefix) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -112,14 +112,14 @@ let(:request_params) { { 'prefix' => prefix } } context 'update' do - let(:request_method) { :patch } - subject do entity = class_under_test.new entity_id entity.prefix = prefix entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -141,16 +141,16 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do entity = class_under_test.new entity.prefix = prefix entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/rir_spec.rb b/spec/netbox_client_ruby/api/ipam/rir_spec.rb index fb59131..1f7d6a9 100644 --- a/spec/netbox_client_ruby/api/ipam/rir_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/rir_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::IPAM::Rir, faraday_stub: true do + subject { class_under_test.new entity_id } + let(:expected_name) { 'rir1' } - let(:class_under_test) { NetboxClientRuby::IPAM::Rir } + let(:class_under_test) { described_class } let(:base_url) { '/api/ipam/rirs/' } let(:response) { File.read("spec/fixtures/ipam/rir_#{entity_id}.json") } let(:entity_id) { 1 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { class_under_test.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -36,7 +36,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -46,14 +46,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -67,8 +67,6 @@ let(:request_params) { { 'name' => name, 'slug' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = class_under_test.new entity_id entity.name = name @@ -76,6 +74,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -98,10 +98,7 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do entity = class_under_test.new entity.name = name @@ -109,6 +106,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/role_spec.rb b/spec/netbox_client_ruby/api/ipam/role_spec.rb index b28d12f..7adf1fb 100644 --- a/spec/netbox_client_ruby/api/ipam/role_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/role_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::IPAM::Role, faraday_stub: true do + subject { described_class.new entity_id } + let(:expected_name) { 'role1' } let(:expected_slug) { expected_name } let(:base_url) { '/api/ipam/roles/' } @@ -11,8 +13,6 @@ let(:entity_id) { 1 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { NetboxClientRuby::IPAM::Role.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -36,7 +36,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -46,14 +46,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -67,15 +67,15 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::IPAM::Role.new entity_id + entity = described_class.new entity_id entity.name = name entity.slug = slug entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -99,17 +99,17 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do - entity = NetboxClientRuby::IPAM::Role.new + entity = described_class.new entity.name = name entity.slug = slug entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/service_spec.rb b/spec/netbox_client_ruby/api/ipam/service_spec.rb index eaff5e1..f17b1d8 100644 --- a/spec/netbox_client_ruby/api/ipam/service_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/service_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::IPAM::Service, faraday_stub: true do + subject { described_class.new entity_id } + let(:expected_name) { 'Service 0' } let(:base_url) { '/api/ipam/services/' } let(:response) { File.read("spec/fixtures/ipam/service_#{entity_id}.json") } @@ -10,8 +12,6 @@ let(:entity_id) { 1 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { NetboxClientRuby::IPAM::Service.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -66,14 +66,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::IPAM::Service.new entity_id + entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,16 +95,16 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do - entity = NetboxClientRuby::IPAM::Service.new + entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/vlan_group_spec.rb b/spec/netbox_client_ruby/api/ipam/vlan_group_spec.rb index 17c679b..ee7daed 100644 --- a/spec/netbox_client_ruby/api/ipam/vlan_group_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/vlan_group_spec.rb @@ -3,17 +3,17 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::IPAM::VlanGroup, faraday_stub: true do + subject { class_under_test.new entity_id } + let(:expected_name) { 'vlan1' } let(:expected_slug) { expected_name } - let(:class_under_test) { NetboxClientRuby::IPAM::VlanGroup } + let(:class_under_test) { described_class } let(:base_url) { '/api/ipam/vlan-groups/' } let(:response) { File.read("spec/fixtures/ipam/vlan-group_#{entity_id}.json") } let(:entity_id) { 1 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { class_under_test.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -21,7 +21,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -37,7 +37,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -47,14 +47,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -67,9 +67,7 @@ let(:slug) { name } let(:request_params) { { 'name' => name, 'slug' => slug } } - context 'update' do - let(:request_method) { :patch } - + context 'update' do # rubocop:disable RSpec/MultipleMemoizedHelpers subject do entity = class_under_test.new entity_id entity.name = name @@ -77,6 +75,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -100,10 +100,7 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do # rubocop:disable RSpec/MultipleMemoizedHelpers subject do entity = class_under_test.new entity.name = name @@ -111,6 +108,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/vlan_spec.rb b/spec/netbox_client_ruby/api/ipam/vlan_spec.rb index e1309a1..3123fe7 100644 --- a/spec/netbox_client_ruby/api/ipam/vlan_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/vlan_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::IPAM::Vlan, faraday_stub: true do + subject { class_under_test.new entity_id } + let(:expected_name) { 'vlan_1' } - let(:class_under_test) { NetboxClientRuby::IPAM::Vlan } + let(:class_under_test) { described_class } let(:base_url) { '/api/ipam/vlans/' } let(:response) { File.read("spec/fixtures/ipam/vlan_#{entity_id}.json") } let(:entity_id) { 1 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { class_under_test.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -35,10 +35,10 @@ tenant: NetboxClientRuby::Tenancy::Tenant, group: NetboxClientRuby::IPAM::VlanGroup, status: NetboxClientRuby::IPAM::VlanStatus, - role: NetboxClientRuby::IPAM::Role + role: NetboxClientRuby::IPAM::Role, }.each_pair do |method_name, expected_type| describe ".#{method_name}" do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.public_send(method_name)).to_not be_nil @@ -51,7 +51,7 @@ end describe '.status' do - it 'should assign the correct value' do + it 'assigns the correct value' do expect(subject.status.label).to eq('Active') end end @@ -61,7 +61,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -71,14 +71,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -92,8 +92,6 @@ let(:request_params) { { 'name' => name, 'rd' => rd } } context 'update' do - let(:request_method) { :patch } - subject do entity = class_under_test.new entity_id entity.name = name @@ -101,6 +99,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -123,10 +123,7 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do entity = class_under_test.new entity.name = name @@ -134,6 +131,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam/vrf_spec.rb b/spec/netbox_client_ruby/api/ipam/vrf_spec.rb index f0f46a8..62ce023 100644 --- a/spec/netbox_client_ruby/api/ipam/vrf_spec.rb +++ b/spec/netbox_client_ruby/api/ipam/vrf_spec.rb @@ -3,16 +3,16 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::IPAM::Vrf, faraday_stub: true do + subject { class_under_test.new entity_id } + let(:expected_name) { 'vrf1' } - let(:class_under_test) { NetboxClientRuby::IPAM::Vrf } + let(:class_under_test) { described_class } let(:base_url) { '/api/ipam/vrfs/' } let(:response) { File.read("spec/fixtures/ipam/vrf_#{entity_id}.json") } let(:entity_id) { 1 } let(:request_url) { "#{base_url}#{entity_id}/" } - subject { class_under_test.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -20,7 +20,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -33,7 +33,7 @@ describe '.tenant' do context 'entity without tenant' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.tenant).to be_nil @@ -43,7 +43,7 @@ context 'entity with tenant' do let(:entity_id) { 2 } - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.tenant).to_not be_nil @@ -53,7 +53,7 @@ expect(subject.tenant).to be_a(NetboxClientRuby::Tenancy::Tenant) end - it 'should an entity with the right it' do + it 'ans entity with the right it' do expect(subject.tenant.id).to eq(3) end end @@ -64,7 +64,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -74,14 +74,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -95,8 +95,6 @@ let(:request_params) { { 'name' => name, 'rd' => rd } } context 'update' do - let(:request_method) { :patch } - subject do entity = class_under_test.new entity_id entity.name = name @@ -104,6 +102,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -126,10 +126,7 @@ end end - context '.new' do - let(:request_method) { :post } - let(:request_url) { base_url } - + context 'new' do subject do entity = class_under_test.new entity.name = name @@ -137,6 +134,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/ipam_spec.rb b/spec/netbox_client_ruby/api/ipam_spec.rb index 4d63947..1485c3d 100644 --- a/spec/netbox_client_ruby/api/ipam_spec.rb +++ b/spec/netbox_client_ruby/api/ipam_spec.rb @@ -11,7 +11,7 @@ vrfs: NetboxClientRuby::IPAM::Vrfs, vlans: NetboxClientRuby::IPAM::Vlans, rirs: NetboxClientRuby::IPAM::Rirs, - prefixes: NetboxClientRuby::IPAM::Prefixes + prefixes: NetboxClientRuby::IPAM::Prefixes, }.each do |method, klass| describe ".#{method}" do subject { described_class.public_send(method) } @@ -22,7 +22,7 @@ context 'is a different instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method) end end @@ -41,19 +41,20 @@ vrf: NetboxClientRuby::IPAM::Vrf, vlan: NetboxClientRuby::IPAM::Vlan, rir: NetboxClientRuby::IPAM::Rir, - prefix: NetboxClientRuby::IPAM::Prefix + prefix: NetboxClientRuby::IPAM::Prefix, }.each do |method, expected_class| describe ".#{method}" do - let(:id) { 1 } subject { described_class.public_send(method, id) } + let(:id) { 1 } + context 'is of the expected type' do it { is_expected.to be_a expected_class } end context 'it is a new instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method, id) end end diff --git a/spec/netbox_client_ruby/api/secrets/secret_role_spec.rb b/spec/netbox_client_ruby/api/secrets/secret_role_spec.rb index 9424e1d..4a404b3 100644 --- a/spec/netbox_client_ruby/api/secrets/secret_role_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/secret_role_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Secrets::SecretRole, faraday_stub: true do + subject { described_class.new secret_id } + let(:secret_id) { 1 } let(:base_url) { '/api/secrets/secret-roles/' } let(:request_url) { "#{base_url}#{secret_id}/" } let(:response) { File.read("spec/fixtures/secrets/secret-role_#{secret_id}.json") } - subject { NetboxClientRuby::Secrets::SecretRole.new secret_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(secret_id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -33,7 +33,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -43,14 +43,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('ipmi_password') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -63,14 +63,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Secrets::SecretRole.new secret_id + entity = described_class.new secret_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -93,15 +93,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Secrets::SecretRole.new + entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/secrets/secret_spec.rb b/spec/netbox_client_ruby/api/secrets/secret_spec.rb index ade9faf..c0f1ddf 100644 --- a/spec/netbox_client_ruby/api/secrets/secret_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/secret_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Secrets::Secret, faraday_stub: true do + subject { described_class.new secret_id } + let(:secret_id) { 1 } let(:base_url) { '/api/secrets/secrets/' } let(:request_url) { "#{base_url}#{secret_id}/" } let(:response) { File.read("spec/fixtures/secrets/secret_#{secret_id}.json") } - subject { NetboxClientRuby::Secrets::Secret.new secret_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(secret_id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -30,7 +30,7 @@ describe '#plaintext' do context 'no plaintext value' do - it 'should return a nil value' do + it 'returns a nil value' do expect(subject.plaintext).to be_nil end end @@ -38,7 +38,7 @@ context 'a plaintext value' do let(:response) { File.read("spec/fixtures/secrets/secret_#{secret_id}_with_plaintext.json") } - it 'should return the plaintext value' do + it 'returns the plaintext value' do expect(subject.plaintext).to eql('n00b') end end @@ -49,7 +49,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -59,14 +59,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('secret1') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -79,14 +79,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Secrets::Secret.new secret_id + entity = described_class.new secret_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -109,15 +109,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Secrets::Secret.new + entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/secrets/session_key_spec.rb b/spec/netbox_client_ruby/api/secrets/session_key_spec.rb index c5526c1..0b5e068 100644 --- a/spec/netbox_client_ruby/api/secrets/session_key_spec.rb +++ b/spec/netbox_client_ruby/api/secrets/session_key_spec.rb @@ -50,6 +50,7 @@ context 'but a wrong password is given' do let(:netbox_auth_rsa_private_key_pass) { 'wrong_password' } + it 'does not send any request to the server' do expect(faraday).to_not receive(request_method) diff --git a/spec/netbox_client_ruby/api/secrets_spec.rb b/spec/netbox_client_ruby/api/secrets_spec.rb index 4e3ba0f..80df516 100644 --- a/spec/netbox_client_ruby/api/secrets_spec.rb +++ b/spec/netbox_client_ruby/api/secrets_spec.rb @@ -5,7 +5,7 @@ RSpec.describe NetboxClientRuby::Secrets do { secret_roles: NetboxClientRuby::Secrets::SecretRoles, - secrets: NetboxClientRuby::Secrets::Secrets + secrets: NetboxClientRuby::Secrets::Secrets, }.each do |method, klass| describe ".#{method}" do subject { described_class.public_send(method) } @@ -16,7 +16,7 @@ context 'is a different instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method) end end @@ -29,19 +29,20 @@ { secret: NetboxClientRuby::Secrets::Secret, - secret_role: NetboxClientRuby::Secrets::SecretRole + secret_role: NetboxClientRuby::Secrets::SecretRole, }.each do |method, expected_class| describe ".#{method}" do - let(:id) { 1 } subject { described_class.public_send(method, id) } + let(:id) { 1 } + context 'is of the expected type' do it { is_expected.to be_a expected_class } end context 'it is a new instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method, id) end end @@ -61,7 +62,7 @@ context 'it is a new instance each time' do it do - is_expected + expect(subject) .to_not be described_class.generate_rsa_key_pair end end @@ -71,7 +72,7 @@ subject { described_class.get_session_key } before do - allow_any_instance_of(NetboxClientRuby::Secrets::SessionKey).to receive(:session_key).and_return('a') + allow_any_instance_of(NetboxClientRuby::Secrets::SessionKey).to receive(:session_key).and_return('a') # rubocop:disable RSpec/AnyInstance end context 'is of the expected type' do @@ -80,7 +81,7 @@ context 'it is a new instance each time' do it do - is_expected + expect(subject) .to_not be described_class.get_session_key end end diff --git a/spec/netbox_client_ruby/api/tenancy/contact_group_spec.rb b/spec/netbox_client_ruby/api/tenancy/contact_group_spec.rb index 47ba97e..65a54a5 100644 --- a/spec/netbox_client_ruby/api/tenancy/contact_group_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy/contact_group_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Tenancy::ContactGroup, faraday_stub: true do + subject { described_class.new contact_group_id } + let(:contact_group_id) { 1 } let(:base_url) { '/api/tenancy/contact-groups/' } let(:request_url) { "#{base_url}#{contact_group_id}/" } let(:response) { File.read("spec/fixtures/tenancy/contact-group_#{contact_group_id}.json") } - subject { NetboxClientRuby::Tenancy::ContactGroup.new contact_group_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(contact_group_id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -29,16 +29,16 @@ end describe '.parent' do - it 'should be nil' do + it 'is nil' do expect(subject.parent).to be_nil end context 'Child Contact Group' do let(:contact_group_id) { 2 } - it 'should be a Contact Group object' do + it 'is a Contact Group object' do parent_contact_group = subject.parent - expect(parent_contact_group).to be_a NetboxClientRuby::Tenancy::ContactGroup + expect(parent_contact_group).to be_a described_class expect(parent_contact_group.id).to eq(1) end end @@ -49,7 +49,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -59,14 +59,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('Parent Customers') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -80,15 +80,15 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Tenancy::ContactGroup.new contact_group_id + entity = described_class.new contact_group_id entity.name = name entity.slug = slug entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -113,16 +113,16 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Tenancy::ContactGroup.new + entity = described_class.new entity.name = name entity.slug = slug entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/tenancy/contact_spec.rb b/spec/netbox_client_ruby/api/tenancy/contact_spec.rb index 340ccd8..9e6200b 100644 --- a/spec/netbox_client_ruby/api/tenancy/contact_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy/contact_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Tenancy::Contact, faraday_stub: true do + subject { described_class.new contact_id } + let(:contact_id) { 1 } let(:base_url) { '/api/tenancy/contacts/' } let(:request_url) { "#{base_url}#{contact_id}/" } let(:response) { File.read("spec/fixtures/tenancy/contact_#{contact_id}.json") } - subject { NetboxClientRuby::Tenancy::Contact.new contact_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(contact_id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -29,14 +29,14 @@ end describe '.group' do - it 'should be nil' do + it 'is nil' do expect(subject.group).to be_nil end context 'Contact with Group' do let(:contact_id) { 3 } - it 'should be a ContactGroup object' do + it 'is a ContactGroup object' do contact_group = subject.group expect(contact_group).to be_a NetboxClientRuby::Tenancy::ContactGroup expect(contact_group.id).to eq(2) @@ -49,7 +49,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -59,14 +59,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('contact1') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -80,15 +80,15 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Tenancy::Contact.new contact_id + entity = described_class.new contact_id entity.name = name entity.slug = slug entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -113,16 +113,16 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Tenancy::Contact.new + entity = described_class.new entity.name = name entity.slug = slug entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/tenancy/tenant_group_spec.rb b/spec/netbox_client_ruby/api/tenancy/tenant_group_spec.rb index 596888a..20d8459 100644 --- a/spec/netbox_client_ruby/api/tenancy/tenant_group_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy/tenant_group_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Tenancy::TenantGroup, faraday_stub: true do + subject { described_class.new tenant_group_id } + let(:tenant_group_id) { 1 } let(:base_url) { '/api/tenancy/tenant-groups/' } let(:request_url) { "#{base_url}#{tenant_group_id}/" } let(:response) { File.read("spec/fixtures/tenancy/tenant-group_#{tenant_group_id}.json") } - subject { NetboxClientRuby::Tenancy::TenantGroup.new tenant_group_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(tenant_group_id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -33,7 +33,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -43,14 +43,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('Customer') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -64,15 +64,15 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Tenancy::TenantGroup.new tenant_group_id + entity = described_class.new tenant_group_id entity.name = name entity.slug = slug entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -97,16 +97,16 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Tenancy::TenantGroup.new + entity = described_class.new entity.name = name entity.slug = slug entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/tenancy/tenant_spec.rb b/spec/netbox_client_ruby/api/tenancy/tenant_spec.rb index 399e106..49f3a76 100644 --- a/spec/netbox_client_ruby/api/tenancy/tenant_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy/tenant_spec.rb @@ -3,13 +3,13 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Tenancy::Tenant, faraday_stub: true do + subject { described_class.new tenant_id } + let(:tenant_id) { 1 } let(:base_url) { '/api/tenancy/tenants/' } let(:request_url) { "#{base_url}#{tenant_id}/" } let(:response) { File.read("spec/fixtures/tenancy/tenant_#{tenant_id}.json") } - subject { NetboxClientRuby::Tenancy::Tenant.new tenant_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(tenant_id) @@ -17,7 +17,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original subject.name @@ -29,14 +29,14 @@ end describe '.group' do - it 'should be nil' do + it 'is nil' do expect(subject.group).to be_nil end context 'Tenant with Group' do let(:tenant_id) { 3 } - it 'should be a TenantGroup object' do + it 'is a TenantGroup object' do tenant_group = subject.group expect(tenant_group).to be_a NetboxClientRuby::Tenancy::TenantGroup expect(tenant_group.id).to eq(1) @@ -49,7 +49,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -59,14 +59,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq('tenant1') end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -80,15 +80,15 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do - entity = NetboxClientRuby::Tenancy::Tenant.new tenant_id + entity = described_class.new tenant_id entity.name = name entity.slug = slug entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -113,16 +113,16 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do - entity = NetboxClientRuby::Tenancy::Tenant.new + entity = described_class.new entity.name = name entity.slug = slug entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/tenancy_spec.rb b/spec/netbox_client_ruby/api/tenancy_spec.rb index 171b457..e35858f 100644 --- a/spec/netbox_client_ruby/api/tenancy_spec.rb +++ b/spec/netbox_client_ruby/api/tenancy_spec.rb @@ -7,7 +7,7 @@ tenant_groups: NetboxClientRuby::Tenancy::TenantGroups, tenants: NetboxClientRuby::Tenancy::Tenants, contact_groups: NetboxClientRuby::Tenancy::ContactGroups, - contacts: NetboxClientRuby::Tenancy::Contacts + contacts: NetboxClientRuby::Tenancy::Contacts, }.each do |method, klass| describe ".#{method}" do subject { described_class.public_send(method) } @@ -18,7 +18,7 @@ context 'is a different instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method) end end diff --git a/spec/netbox_client_ruby/api/virtualization/cluster_group_spec.rb b/spec/netbox_client_ruby/api/virtualization/cluster_group_spec.rb index 1579b40..d89d3c7 100644 --- a/spec/netbox_client_ruby/api/virtualization/cluster_group_spec.rb +++ b/spec/netbox_client_ruby/api/virtualization/cluster_group_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Virtualization::ClusterGroup, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { '1' } let(:base_url) { '/api/virtualization/cluster-groups/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -66,8 +66,6 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name @@ -75,6 +73,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -99,9 +99,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name @@ -109,6 +106,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/virtualization/cluster_spec.rb b/spec/netbox_client_ruby/api/virtualization/cluster_spec.rb index 22d4bb9..fc53e88 100644 --- a/spec/netbox_client_ruby/api/virtualization/cluster_spec.rb +++ b/spec/netbox_client_ruby/api/virtualization/cluster_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Virtualization::Cluster, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { '1' } let(:base_url) { '/api/virtualization/clusters/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -31,7 +31,7 @@ end describe '#site' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -51,7 +51,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -61,14 +61,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -81,14 +81,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -111,15 +111,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/virtualization/cluster_type_spec.rb b/spec/netbox_client_ruby/api/virtualization/cluster_type_spec.rb index 4b0ca9f..310be88 100644 --- a/spec/netbox_client_ruby/api/virtualization/cluster_type_spec.rb +++ b/spec/netbox_client_ruby/api/virtualization/cluster_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Virtualization::ClusterType, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { '1' } let(:base_url) { '/api/virtualization/cluster-types/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -66,8 +66,6 @@ let(:request_params) { { 'name' => name, 'slug' => slug } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name @@ -75,6 +73,8 @@ entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -99,9 +99,6 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name @@ -109,6 +106,9 @@ entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/virtualization/interface_spec.rb b/spec/netbox_client_ruby/api/virtualization/interface_spec.rb index 643855f..2d6b1d2 100644 --- a/spec/netbox_client_ruby/api/virtualization/interface_spec.rb +++ b/spec/netbox_client_ruby/api/virtualization/interface_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Virtualization::Interface, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { '1' } let(:base_url) { '/api/virtualization/interfaces/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/virtualization/virtual_machine_spec.rb b/spec/netbox_client_ruby/api/virtualization/virtual_machine_spec.rb index 3cc5450..2720291 100644 --- a/spec/netbox_client_ruby/api/virtualization/virtual_machine_spec.rb +++ b/spec/netbox_client_ruby/api/virtualization/virtual_machine_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby::Virtualization::VirtualMachine, faraday_stub: true do + subject { described_class.new entity_id } + let(:entity_id) { 1 } let(:expected_name) { '1' } let(:base_url) { '/api/virtualization/virtual-machines/' } @@ -10,8 +12,6 @@ let(:request_url) { "#{base_url}#{entity_id}/" } - subject { described_class.new entity_id } - describe '#id' do it 'shall be the expected id' do expect(subject.id).to eq(entity_id) @@ -19,7 +19,7 @@ end describe '#name' do - it 'should fetch the data' do + it 'fetches the data' do expect(faraday).to receive(:get).and_call_original expect(subject.name).to_not be_nil @@ -35,7 +35,7 @@ let(:response_status) { 204 } let(:response) { nil } - it 'should delete the object' do + it 'deletes the object' do expect(faraday).to receive(request_method).and_call_original subject.delete end @@ -45,14 +45,14 @@ let(:request_method) { :patch } let(:request_params) { { 'name' => 'noob' } } - it 'should update the object' do + it 'updates the object' do expect(faraday).to receive(request_method).and_call_original expect(subject.update(name: 'noob').name).to eq(expected_name) end end describe '.reload' do - it 'should reload the object' do + it 'reloads the object' do expect(faraday).to receive(request_method).twice.and_call_original subject.reload @@ -65,14 +65,14 @@ let(:request_params) { { 'name' => name } } context 'update' do - let(:request_method) { :patch } - subject do entity = described_class.new entity_id entity.name = name entity end + let(:request_method) { :patch } + it 'does not call PATCH until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) @@ -95,15 +95,15 @@ end context 'create' do - let(:request_method) { :post } - let(:request_url) { base_url } - subject do entity = described_class.new entity.name = name entity end + let(:request_method) { :post } + let(:request_url) { base_url } + it 'does not POST until save is called' do expect(faraday).to_not receive(request_method) expect(faraday).to_not receive(:get) diff --git a/spec/netbox_client_ruby/api/virtualization_spec.rb b/spec/netbox_client_ruby/api/virtualization_spec.rb index 2b85c4a..28f0b22 100644 --- a/spec/netbox_client_ruby/api/virtualization_spec.rb +++ b/spec/netbox_client_ruby/api/virtualization_spec.rb @@ -19,7 +19,7 @@ context 'is a different instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method) end end @@ -38,16 +38,17 @@ interface: NetboxClientRuby::Virtualization::Interface, }.each do |method, expected_class| describe ".#{method}" do - let(:id) { 1 } subject { described_class.public_send(method, id) } + let(:id) { 1 } + context 'is of the expected type' do it { is_expected.to be_a expected_class } end context 'it is a new instance each time' do it do - is_expected + expect(subject) .to_not be described_class.public_send(method, id) end end diff --git a/spec/netbox_client_ruby/communication_spec.rb b/spec/netbox_client_ruby/communication_spec.rb index dbc4b9d..029e81e 100644 --- a/spec/netbox_client_ruby/communication_spec.rb +++ b/spec/netbox_client_ruby/communication_spec.rb @@ -3,19 +3,20 @@ require 'spec_helper' require 'json' +class Victim + include NetboxClientRuby::Communication +end + RSpec.describe NetboxClientRuby::Communication do let(:faraday) { double('Faraday') } let(:url) { '/api' } let(:response) { double('response', body: response_body, status: 200) } let(:subject) { Victim.new } - class Victim - include NetboxClientRuby::Communication - end describe 'get connection' do it 'returns a valid connection' do - expect(NetboxClientRuby::Connection).to receive(:new).and_return faraday + expect(NetboxClientRuby::Connection).to receive(:new).and_return faraday # rubocop:disable RSpec/StubbedMock expect(subject.connection).to be faraday end diff --git a/spec/netbox_client_ruby/connection_spec.rb b/spec/netbox_client_ruby/connection_spec.rb index d263835..8293c75 100644 --- a/spec/netbox_client_ruby/connection_spec.rb +++ b/spec/netbox_client_ruby/connection_spec.rb @@ -15,16 +15,16 @@ end it 'returns a Faraday::Connection' do - expect(NetboxClientRuby::Connection.new).to be_a Faraday::Connection + expect(described_class.new).to be_a Faraday::Connection end it 'correctly sets the base url' do - expect(NetboxClientRuby::Connection.new.url_prefix) + expect(described_class.new.url_prefix) .to eq(URI.parse('https://netbox.test/api/')) end it 'sets the correct auth headers' do - actual_headers = NetboxClientRuby::Connection.new.headers + actual_headers = described_class.new.headers expect(actual_headers['Authorization']).to eq 'Token 2e35594ec8710e9922d14365a1ea66f27ea69450' end @@ -35,33 +35,33 @@ NetboxClientRuby::Secrets.session_key = expected_session_key end + after do + NetboxClientRuby::Secrets.session_key = nil + end + it 'adds the session_key header if available' do - actual_headers = NetboxClientRuby::Connection.new.headers + actual_headers = described_class.new.headers expect(actual_headers['X-Session-Key']).to eq expected_session_key end - - after do - NetboxClientRuby::Secrets.session_key = nil - end end it 'sets the adapter' do if Faraday::VERSION < '1.0' - expect(NetboxClientRuby::Connection.new.builder.handlers) + expect(described_class.new.builder.handlers) .to include Faraday::Adapter::NetHttp else - expect(NetboxClientRuby::Connection.new.builder.adapter) + expect(described_class.new.builder.adapter) .to eq Faraday::Adapter::NetHttp end end it 'adds the json middleware' do if Faraday::VERSION < '2' - expect(NetboxClientRuby::Connection.new.builder.handlers) + expect(described_class.new.builder.handlers) .to include FaradayMiddleware::ParseJson else - expect(NetboxClientRuby::Connection.new.builder.handlers) + expect(described_class.new.builder.handlers) .to include Faraday::Request::Json, Faraday::Response::Json end end @@ -78,10 +78,10 @@ it 'sets the adapter' do if Faraday::VERSION < '1.0' - expect(NetboxClientRuby::Connection.new.builder.handlers) + expect(described_class.new.builder.handlers) .to include Faraday::Adapter::NetHttpPersistent else - expect(NetboxClientRuby::Connection.new.builder.adapter) + expect(described_class.new.builder.adapter) .to eq Faraday::Adapter::NetHttpPersistent end end @@ -99,7 +99,7 @@ end it 'sets the logger' do - expect(NetboxClientRuby::Connection.new.builder.handlers) + expect(described_class.new.builder.handlers) .to include Faraday::Response::Logger end end @@ -124,7 +124,7 @@ end it 'sets the logger' do - expect(NetboxClientRuby::Connection.new.builder.handlers) + expect(described_class.new.builder.handlers) .to include Faraday::DetailedLogger::Middleware end end diff --git a/spec/netbox_client_ruby/entities_spec.rb b/spec/netbox_client_ruby/entities_spec.rb index b237c93..3be6029 100644 --- a/spec/netbox_client_ruby/entities_spec.rb +++ b/spec/netbox_client_ruby/entities_spec.rb @@ -4,37 +4,37 @@ require 'ostruct' require 'uri' -RSpec.describe NetboxClientRuby::Entities, faraday_stub: true do - class TestEntities - include NetboxClientRuby::Entities +class TestEntities + include NetboxClientRuby::Entities - attr_accessor :collected_raw_entities + attr_accessor :collected_raw_entities - path 'tests/42' - data_key 'data_node' - count_key 'total_count' - limit 321 - entity_creator :entity_creator + path 'tests/42' + data_key 'data_node' + count_key 'total_count' + limit 321 + entity_creator :entity_creator - private + private - def entity_creator(raw_entity) - OpenStruct.new raw_entity - end + def entity_creator(raw_entity) + OpenStruct.new raw_entity end +end - class TestEntities2 - include NetboxClientRuby::Entities +class TestEntities2 + include NetboxClientRuby::Entities - path '/test' - data_key 'non_existent' - count_key 'non_existent' - end + path '/test' + data_key 'non_existent' + count_key 'non_existent' +end - class TestEntities3 - include NetboxClientRuby::Entities - end +class TestEntities3 + include NetboxClientRuby::Entities +end +RSpec.describe NetboxClientRuby::Entities, faraday_stub: true do let(:raw_data) do { 'total_count' => 999, @@ -42,8 +42,8 @@ class TestEntities3 'data_node' => [ { 'name' => 'obj1' }, { 'name' => 'obj2' }, - { 'name' => 'obj3' } - ] + { 'name' => 'obj3' }, + ], } end let(:response) { JSON.generate(raw_data) } @@ -65,6 +65,7 @@ class TestEntities3 context 'nonexistent count_key provided' do subject { TestEntities2.new } + let(:request_url) { '/test' } let(:request_url_params) do { limit: NetboxClientRuby.config.netbox.pagination.default_limit } @@ -152,6 +153,7 @@ class TestEntities3 context 'nonexistent data_key provided' do subject { TestEntities2.new } + let(:request_url) { '/test' } let(:request_url_params) do { limit: NetboxClientRuby.config.netbox.pagination.default_limit } @@ -341,7 +343,7 @@ class TestEntities3 context 'check filter on connection' do let(:request_url_params) { filter } - it 'applies the filter' do + it 'applies the filter' do # rubocop:disable RSpec/NoExpectationExample subject.filter(filter).reload end end @@ -357,16 +359,16 @@ class TestEntities3 expect(subject.all).to be subject end - it 'fetches all the articles until the maximum allowed value' do + it 'fetches all the articles until the maximum allowed value' do # rubocop:disable RSpec/NoExpectationExample subject.limit(limit).reload end context 'complex test' do before do - url_params_string = '?' + URI.encode_www_form(limit: 321) + url_params_string = '?' + URI.encode_www_form(limit: 321) # rubocop:disable Style/StringConcatenation faraday_stubs.public_send(request_method, "#{request_url}#{url_params_string}", - request_params) do |_env| + request_params) do |_env| # rubocop:disable Style/TrailingCommaInArguments [response_status, response_config, response] end end @@ -428,7 +430,7 @@ class TestEntities3 context "page #{counter}" do let(:page) { counter } - it 'fetches the correct data from the right offset' do + it 'fetches the correct data from the right offset' do # rubocop:disable RSpec/NoExpectationExample subject.page(page).reload end end @@ -466,7 +468,7 @@ class TestEntities3 context "page #{counter}" do let(:offset) { counter * limit } - it 'fetches the correct data from the right offset' do + it 'fetches the correct data from the right offset' do # rubocop:disable RSpec/NoExpectationExample subject.offset(offset).reload end end diff --git a/spec/netbox_client_ruby/entity_object_fields_spec.rb b/spec/netbox_client_ruby/entity_object_fields_spec.rb index ae853c6..73a346d 100644 --- a/spec/netbox_client_ruby/entity_object_fields_spec.rb +++ b/spec/netbox_client_ruby/entity_object_fields_spec.rb @@ -2,96 +2,103 @@ require 'spec_helper' -RSpec.describe NetboxClientRuby::Entity do - class TestSubPoro - attr_accessor :name +class TestSubPoro + attr_accessor :name - def initialize(data) - @name = data['name'] - end + def initialize(data) + @name = data['name'] end - class TestSubEntity - include NetboxClientRuby::Entity +end - id my_id: 'name' - path 'tests/:my_id/sub' +class TestSubEntity + include NetboxClientRuby::Entity - def initialize(my_id, data = nil) - self.data = data - super my_id: my_id - end + id my_id: 'name' + path 'tests/:my_id/sub' + + def initialize(my_id, data = nil) + self.data = data + super(my_id: my_id) end - module ArrayObjectField - class TestEntitySimple - include NetboxClientRuby::Entity +end + +module ArrayObjectField + class TestEntitySimple + include NetboxClientRuby::Entity - id test_id: 'id' - path 'tests/:test_id' - object_fields 'an_object_array' + id test_id: 'id' + path 'tests/:test_id' + object_fields 'an_object_array' - def initialize - super test_id: 42 - end + def initialize + super(test_id: 42) end - class TestEntityPoro - include NetboxClientRuby::Entity + end + + class TestEntityPoro + include NetboxClientRuby::Entity - id test_id: 'id' - path 'tests/:test_id' - object_fields an_object_array: TestSubPoro + id test_id: 'id' + path 'tests/:test_id' + object_fields an_object_array: TestSubPoro - def initialize - super test_id: 42 - end + def initialize + super(test_id: 42) end - class TestEntityProc - include NetboxClientRuby::Entity + end + + class TestEntityProc + include NetboxClientRuby::Entity - id test_id: 'id' - path 'tests/:test_id' - object_fields an_object_array: proc { |data| TestSubEntity.new(@test_id, data) } + id test_id: 'id' + path 'tests/:test_id' + object_fields an_object_array: proc { |data| TestSubEntity.new(@test_id, data) } - def initialize - super test_id: 42 - end + def initialize + super(test_id: 42) end end - module ObjectField - class TestEntityPlain - include NetboxClientRuby::Entity +end + +module ObjectField + class TestEntityPlain + include NetboxClientRuby::Entity - id test_id: 'id' - path 'tests/:test_id' - object_fields :an_object + id test_id: 'id' + path 'tests/:test_id' + object_fields :an_object - def initialize - super test_id: 42 - end + def initialize + super(test_id: 42) end - class TestEntityPoro - include NetboxClientRuby::Entity + end + + class TestEntityPoro + include NetboxClientRuby::Entity - id test_id: 'id' - path 'tests/:test_id' - object_fields an_object: TestSubPoro + id test_id: 'id' + path 'tests/:test_id' + object_fields an_object: TestSubPoro - def initialize - super test_id: 42 - end + def initialize + super(test_id: 42) end - class TestEntityProc - include NetboxClientRuby::Entity + end + + class TestEntityProc + include NetboxClientRuby::Entity - id test_id: 'id' - path 'tests/:test_id' - object_fields an_object: proc { |data| TestSubEntity.new(@test_id, data) } + id test_id: 'id' + path 'tests/:test_id' + object_fields an_object: proc { |data| TestSubEntity.new(@test_id, data) } - def initialize - super test_id: 42 - end + def initialize + super(test_id: 42) end end +end +RSpec.describe NetboxClientRuby::Entity do let(:faraday_stubs) { Faraday::Adapter::Test::Stubs.new } let(:faraday) do Faraday.new(url: 'https://netbox.test/api/', headers: NetboxClientRuby::Connection.headers) do |faraday| @@ -100,7 +107,7 @@ def initialize end end let(:response_json) do - <<-json + <<-JSON { "id": 42, "name": "Beat", @@ -127,7 +134,7 @@ def initialize }, "counter": 1 } - json + JSON end let(:url) { '/api/tests/42' } @@ -243,7 +250,7 @@ def initialize end describe 'objectification of the content of object fields' do - context 'anonymous class' do + context 'with anonymous class' do let(:subject) { ObjectField::TestEntityPlain.new } it 'does not return `an_object` as a Hash' do @@ -270,7 +277,7 @@ def initialize end end - context 'poro class' do + context 'with poro class' do let(:subject) { ObjectField::TestEntityPoro.new } it 'does not return `an_object` as a Hash' do @@ -297,7 +304,7 @@ def initialize end end - context 'entity class' do + context 'with entity class' do let(:subject) { ObjectField::TestEntityProc.new } it 'does not return `an_object` as a Hashe' do diff --git a/spec/netbox_client_ruby/entity_spec.rb b/spec/netbox_client_ruby/entity_spec.rb index a83d214..87ab121 100644 --- a/spec/netbox_client_ruby/entity_spec.rb +++ b/spec/netbox_client_ruby/entity_spec.rb @@ -2,48 +2,51 @@ require 'spec_helper' -RSpec.describe NetboxClientRuby::Entity, faraday_stub: true do - class TestEntity - include NetboxClientRuby::Entity +class TestEntity + include NetboxClientRuby::Entity - attr_accessor :name + attr_accessor :name - id test_id: 'id' - readonly_fields :counter - deletable true - path 'tests/:test_id' - creation_path 'tests/' - object_fields :an_object, :an_object_array + id test_id: 'id' + readonly_fields :counter + deletable true + path 'tests/:test_id' + creation_path 'tests/' + object_fields :an_object, :an_object_array - def initialize(id = nil, name = nil) - @name = name - super id - end + def initialize(id = nil, name = nil) + @name = name + super(id) end - class TestEntity2 - include NetboxClientRuby::Entity +end - id test_id: 'id' - readonly_fields :counter - creation_path 'tests/' - # not deletable +class TestEntity2 + include NetboxClientRuby::Entity - path 'tests/42' - end - class TestEntity3 - include NetboxClientRuby::Entity + id test_id: 'id' + readonly_fields :counter + creation_path 'tests/' + # not deletable - id test_id: 'id' - # Wrong URL (starts with '/') - path '/tests/42' - end - class TestEntity4 - include NetboxClientRuby::Entity + path 'tests/42' +end - id test_id: 'id' - # no path defined - end +class TestEntity3 + include NetboxClientRuby::Entity + id test_id: 'id' + # Wrong URL (starts with '/') + path '/tests/42' +end + +class TestEntity4 + include NetboxClientRuby::Entity + + id test_id: 'id' + # no path defined +end + +RSpec.describe NetboxClientRuby::Entity, faraday_stub: true do let(:raw_data) do { 'id' => 43, @@ -54,15 +57,15 @@ class TestEntity4 'date' => '2014-05-28T18:46:18.764425Z', 'an_object' => { 'key' => 'value', - 'second' => 2 + 'second' => 2, }, 'an_array' => [], 'an_object_array' => [ { 'name' => 'obj1' }, { 'name' => 'obj2' }, - { 'name' => 'obj3' } + { 'name' => 'obj3' }, ], - 'counter' => 1 + 'counter' => 1, } end @@ -316,6 +319,7 @@ class TestEntity4 context 'non-deletable entity' do let(:subject) { TestEntity2.new 42 } + it 'raises an error' do expect { subject.delete }.to raise_error NetboxClientRuby::LocalError end @@ -348,6 +352,7 @@ class TestEntity4 context 'non-deletable entity' do let(:subject) { TestEntity2.new 42 } + it 'raises an error' do expect { subject.delete }.to raise_error NetboxClientRuby::LocalError end @@ -400,7 +405,7 @@ class TestEntity4 describe 'calling an attribute' do describe 'for an unsaved entity' do - it 'should raise a NoMethodError' do + it 'raises a NoMethodError' do expect { subject.unknown_attribute }.to raise_error NoMethodError end end diff --git a/spec/netbox_client_ruby/netbox_spec.rb b/spec/netbox_client_ruby/netbox_spec.rb index 9c8512f..763b847 100644 --- a/spec/netbox_client_ruby/netbox_spec.rb +++ b/spec/netbox_client_ruby/netbox_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' RSpec.describe NetboxClientRuby do - it 'is configurable' do - NetboxClientRuby.configure do |config| + it 'is configurable' do # rubocop:disable RSpec/ExampleLength + described_class.configure do |config| config.netbox.auth.token = 'my_very_special_token' config.netbox.auth.rsa_private_key.path = 'spec/fixtures/rsa_private_key' config.netbox.auth.rsa_private_key.password = 'password' @@ -17,25 +17,25 @@ config.faraday.ssl_options = { verify: true } end - expect(NetboxClientRuby.config.netbox.auth.token) + expect(described_class.config.netbox.auth.token) .to eq 'my_very_special_token' - expect(NetboxClientRuby.config.netbox.auth.rsa_private_key.path) + expect(described_class.config.netbox.auth.rsa_private_key.path) .to eq 'spec/fixtures/rsa_private_key' - expect(NetboxClientRuby.config.netbox.auth.rsa_private_key.password) + expect(described_class.config.netbox.auth.rsa_private_key.password) .to eq 'password' - expect(NetboxClientRuby.config.netbox.api_base_url) + expect(described_class.config.netbox.api_base_url) .to eq 'https://netbox.test/api/' - expect(NetboxClientRuby.config.netbox.pagination.default_limit) + expect(described_class.config.netbox.pagination.default_limit) .to eq 42 - expect(NetboxClientRuby.config.netbox.pagination.max_limit) + expect(described_class.config.netbox.pagination.max_limit) .to eq 84 - expect(NetboxClientRuby.config.faraday.adapter) + expect(described_class.config.faraday.adapter) .to be :net_http_persistent - expect(NetboxClientRuby.config.faraday.logger) + expect(described_class.config.faraday.logger) .to be :detailed_logger - expect(NetboxClientRuby.config.faraday.request_options) + expect(described_class.config.faraday.request_options) .to eq(open_timeout: 3, timeout: 15) - expect(NetboxClientRuby.config.faraday.ssl_options) + expect(described_class.config.faraday.ssl_options) .to eq(verify: true) end @@ -44,11 +44,11 @@ dcim: NetboxClientRuby::DCIM, ipam: NetboxClientRuby::IPAM, secrets: NetboxClientRuby::Secrets, - tenancy: NetboxClientRuby::Tenancy + tenancy: NetboxClientRuby::Tenancy, }.each do |method, klass| context "returns the initialized #{method} object" do it 'is of the correct type' do - expect(NetboxClientRuby.public_send(method)).to be klass + expect(described_class.public_send(method)).to be klass end end end diff --git a/spec/shared_contexts/faraday.rb b/spec/shared_contexts/faraday.rb index d42733b..ebc7022 100644 --- a/spec/shared_contexts/faraday.rb +++ b/spec/shared_contexts/faraday.rb @@ -9,7 +9,7 @@ let(:faraday_stubs) { Faraday::Adapter::Test::Stubs.new } let(:faraday) do Faraday.new(url: NetboxClientRuby.config.netbox.api_base_url, - headers: NetboxClientRuby::Connection.headers) do |faraday| + headers: NetboxClientRuby::Connection.headers) do |faraday| # rubocop:disable Style/TrailingCommaInArguments faraday.response :json, content_type: /\bjson$/ faraday.request faraday_logger if faraday_logger faraday.adapter :test, faraday_stubs @@ -26,14 +26,15 @@ let(:request_url_params_string) do return request_url_params if request_url_params.nil? return "?#{request_url_params}" if request_url_params.is_a? String - '?' + URI.encode_www_form(request_url_params) + + '?' + URI.encode_www_form(request_url_params) # rubocop:disable Style/StringConcatenation end before do - #puts "expected request: #{request_method} #{request_url}#{request_url_params_string} (#{request_params})" + # puts "expected request: #{request_method} #{request_url}#{request_url_params_string} (#{request_params})" faraday_stubs.public_send(request_method, "#{request_url}#{request_url_params_string}", - request_params) do |_env| + request_params) do |_env| # rubocop:disable Style/TrailingCommaInArguments [response_status, response_config, response] end allow(Faraday).to receive(:new).and_return faraday diff --git a/spec/shared_contexts/netbox_client.rb b/spec/shared_contexts/netbox_client.rb index 0338cae..a9c1864 100644 --- a/spec/shared_contexts/netbox_client.rb +++ b/spec/shared_contexts/netbox_client.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "dry/configurable/test_interface" +require 'dry/configurable/test_interface' # https://dry-rb.org/gems/dry-configurable/1.0/testing/ module NetboxClientRuby diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 199869b..5b57b62 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,7 @@ Warning[:deprecated] = true Warning[:experimental] = true -Warning[:performance] = true if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.3.0") +Warning[:performance] = true if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3.0') # Ignore all warnings in Gem dependencies Gem.path.each do |path| From 736952de42733c40e2d4272f606a9e198eb71cf6 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 30 Sep 2025 02:30:21 +0200 Subject: [PATCH 9/9] Add code coverage with SimpleCov --- Gemfile | 1 + gemfiles/faraday0.gemfile | 1 + gemfiles/faraday1.gemfile | 1 + gemfiles/faraday2.gemfile | 1 + spec/spec_helper.rb | 11 +++++++++++ 5 files changed, 15 insertions(+) diff --git a/Gemfile b/Gemfile index e5dfff4..4d41344 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem 'ostruct' gem 'pry' gem 'rake' gem 'rspec' +gem 'simplecov' gem 'warning' # fallback to faraday 1.x in dev environment diff --git a/gemfiles/faraday0.gemfile b/gemfiles/faraday0.gemfile index abd8a6a..8f13648 100644 --- a/gemfiles/faraday0.gemfile +++ b/gemfiles/faraday0.gemfile @@ -7,6 +7,7 @@ gem "ostruct" gem "pry" gem "rake" gem "rspec" +gem "simplecov" gem "warning" gem "faraday", "< 1.0" gem "faraday_middleware", "< 1" diff --git a/gemfiles/faraday1.gemfile b/gemfiles/faraday1.gemfile index 02d1905..7be7363 100644 --- a/gemfiles/faraday1.gemfile +++ b/gemfiles/faraday1.gemfile @@ -7,6 +7,7 @@ gem "ostruct" gem "pry" gem "rake" gem "rspec" +gem "simplecov" gem "warning" gem "faraday", "= 1.0" gem "faraday_middleware", "< 2" diff --git a/gemfiles/faraday2.gemfile b/gemfiles/faraday2.gemfile index 4d91d74..6151da1 100644 --- a/gemfiles/faraday2.gemfile +++ b/gemfiles/faraday2.gemfile @@ -7,6 +7,7 @@ gem "ostruct" gem "pry" gem "rake" gem "rspec" +gem "simplecov" gem "warning" gem "faraday", "< 3" gem "rubocop", require: false diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5b57b62..75784c0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# Load ruby-warning gem require 'warning' Warning[:deprecated] = true @@ -14,6 +15,16 @@ # Ignore OpenStruct warning (only used in tests) Warning.ignore(/OpenStruct use is discouraged for performance reasons/) +# Load simplecov +require 'simplecov' +require 'simplecov_json_formatter' + +# Start SimpleCov +SimpleCov.start do + formatter SimpleCov::Formatter::MultiFormatter.new([SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::JSONFormatter]) + add_filter 'spec/' +end + # Load gem require 'netbox-client-ruby' require_relative 'shared_contexts/netbox_client'