From 08ac2a034769b1a9cd0f9c8f7d426998478f0de0 Mon Sep 17 00:00:00 2001 From: Kaka Ruto Date: Tue, 19 Dec 2023 17:18:13 +0300 Subject: [PATCH] Move helper files into spec/support --- spec/spec_helper.rb | 30 +----------------------------- spec/support/cloudflare/account.rb | 13 +++++++++++++ spec/support/cloudflare/zone.rb | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 spec/support/cloudflare/account.rb create mode 100644 spec/support/cloudflare/zone.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 38c6785..e07d884 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,35 +26,7 @@ require 'cloudflare/rspec/connection' require 'cloudflare/zones' -RSpec.shared_context Cloudflare::Account do - include_context Cloudflare::RSpec::Connection - - let(:account) do - if ACCOUNT_ID - connection.accounts.find_by_id(ACCOUNT_ID) - else - connection.accounts.first - end - end -end - -RSpec.shared_context Cloudflare::Zone do - include_context Cloudflare::Account - - let(:job_id) {JOB_ID} - let(:names) {NAMES.dup} - let(:name) {ZONE_NAME.dup} - - let(:zones) {connection.zones} - - let(:zone) {@zone = zones.find_by_name(name) || zones.create(name, account)} - - # after do - # if defined? @zone - # @zone.delete - # end - # end -end +Dir[File.expand_path('../support/**/*.rb', __FILE__)].each{|path| require path} RSpec.configure do |config| # Enable flags like --only-failures and --next-failure diff --git a/spec/support/cloudflare/account.rb b/spec/support/cloudflare/account.rb new file mode 100644 index 0000000..88e56a0 --- /dev/null +++ b/spec/support/cloudflare/account.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +RSpec.shared_context Cloudflare::Account do + include_context Cloudflare::RSpec::Connection + + let(:account) do + if ACCOUNT_ID + connection.accounts.find_by_id(ACCOUNT_ID) + else + connection.accounts.first + end + end +end diff --git a/spec/support/cloudflare/zone.rb b/spec/support/cloudflare/zone.rb new file mode 100644 index 0000000..07b194a --- /dev/null +++ b/spec/support/cloudflare/zone.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.shared_context Cloudflare::Zone do + include_context Cloudflare::Account + + let(:job_id) { JOB_ID } + let(:names) { NAMES.dup } + let(:name) { ZONE_NAME.dup } + + let(:zones) { connection.zones } + + let(:zone) { @zone = zones.find_by_name(name) || zones.create(name, account) } + + after do + @zone.delete if defined? @zone + end +end