Add shared example for CLI command specs (#28165)

This commit is contained in:
Matt Jankowski 2023-12-01 07:00:34 -05:00 committed by GitHub
parent 92fa9b109f
commit 7753e5f715
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 28 additions and 81 deletions

View file

@ -6,6 +6,8 @@ require 'mastodon/cli/accounts'
describe Mastodon::CLI::Accounts do describe Mastodon::CLI::Accounts do
let(:cli) { described_class.new } let(:cli) { described_class.new }
it_behaves_like 'CLI Command'
# `parallelize_with_progress` cannot run in transactions, so instead, # `parallelize_with_progress` cannot run in transactions, so instead,
# stub it with an alternative implementation that runs sequentially # stub it with an alternative implementation that runs sequentially
# and can run in transactions. # and can run in transactions.
@ -24,12 +26,6 @@ describe Mastodon::CLI::Accounts do
end end
end end
describe '.exit_on_failure?' do
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#create' do describe '#create' do
shared_examples 'a new user with given email address and username' do shared_examples 'a new user with given email address and username' do
it 'creates a new user with the specified email address' do it 'creates a new user with the specified email address' do

View file

@ -6,11 +6,7 @@ require 'mastodon/cli/cache'
describe Mastodon::CLI::Cache do describe Mastodon::CLI::Cache do
let(:cli) { described_class.new } let(:cli) { described_class.new }
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#clear' do describe '#clear' do
before { allow(Rails.cache).to receive(:clear) } before { allow(Rails.cache).to receive(:clear) }

View file

@ -6,11 +6,7 @@ require 'mastodon/cli/canonical_email_blocks'
describe Mastodon::CLI::CanonicalEmailBlocks do describe Mastodon::CLI::CanonicalEmailBlocks do
let(:cli) { described_class.new } let(:cli) { described_class.new }
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#find' do describe '#find' do
let(:arguments) { ['user@example.com'] } let(:arguments) { ['user@example.com'] }

View file

@ -4,9 +4,5 @@ require 'rails_helper'
require 'mastodon/cli/domains' require 'mastodon/cli/domains'
describe Mastodon::CLI::Domains do describe Mastodon::CLI::Domains do
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
end end

View file

@ -4,9 +4,5 @@ require 'rails_helper'
require 'mastodon/cli/email_domain_blocks' require 'mastodon/cli/email_domain_blocks'
describe Mastodon::CLI::EmailDomainBlocks do describe Mastodon::CLI::EmailDomainBlocks do
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
end end

View file

@ -4,9 +4,5 @@ require 'rails_helper'
require 'mastodon/cli/emoji' require 'mastodon/cli/emoji'
describe Mastodon::CLI::Emoji do describe Mastodon::CLI::Emoji do
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
end end

View file

@ -6,11 +6,7 @@ require 'mastodon/cli/feeds'
describe Mastodon::CLI::Feeds do describe Mastodon::CLI::Feeds do
let(:cli) { described_class.new } let(:cli) { described_class.new }
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#build' do describe '#build' do
before { Fabricate(:account) } before { Fabricate(:account) }

View file

@ -6,11 +6,7 @@ require 'mastodon/cli/ip_blocks'
describe Mastodon::CLI::IpBlocks do describe Mastodon::CLI::IpBlocks do
let(:cli) { described_class.new } let(:cli) { described_class.new }
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#add' do describe '#add' do
let(:ip_list) do let(:ip_list) do

View file

@ -4,11 +4,7 @@ require 'rails_helper'
require 'mastodon/cli/main' require 'mastodon/cli/main'
describe Mastodon::CLI::Main do describe Mastodon::CLI::Main do
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe 'version' do describe 'version' do
it 'returns the Mastodon version' do it 'returns the Mastodon version' do

View file

@ -6,11 +6,7 @@ require 'mastodon/cli/maintenance'
describe Mastodon::CLI::Maintenance do describe Mastodon::CLI::Maintenance do
let(:cli) { described_class.new } let(:cli) { described_class.new }
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#fix_duplicates' do describe '#fix_duplicates' do
context 'when the database version is too old' do context 'when the database version is too old' do

View file

@ -6,11 +6,7 @@ require 'mastodon/cli/media'
describe Mastodon::CLI::Media do describe Mastodon::CLI::Media do
let(:cli) { described_class.new } let(:cli) { described_class.new }
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#remove' do describe '#remove' do
context 'with --prune-profiles and --remove-headers' do context 'with --prune-profiles and --remove-headers' do

View file

@ -6,11 +6,7 @@ require 'mastodon/cli/preview_cards'
describe Mastodon::CLI::PreviewCards do describe Mastodon::CLI::PreviewCards do
let(:cli) { described_class.new } let(:cli) { described_class.new }
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#remove' do describe '#remove' do
context 'with relevant preview cards' do context 'with relevant preview cards' do

View file

@ -4,9 +4,5 @@ require 'rails_helper'
require 'mastodon/cli/search' require 'mastodon/cli/search'
describe Mastodon::CLI::Search do describe Mastodon::CLI::Search do
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
end end

View file

@ -4,11 +4,7 @@ require 'rails_helper'
require 'mastodon/cli/settings' require 'mastodon/cli/settings'
describe Mastodon::CLI::Settings do describe Mastodon::CLI::Settings do
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe 'subcommand "registrations"' do describe 'subcommand "registrations"' do
let(:cli) { Mastodon::CLI::Registrations.new } let(:cli) { Mastodon::CLI::Registrations.new }

View file

@ -6,11 +6,7 @@ require 'mastodon/cli/statuses'
describe Mastodon::CLI::Statuses do describe Mastodon::CLI::Statuses do
let(:cli) { described_class.new } let(:cli) { described_class.new }
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
describe '#remove', use_transactional_tests: false do describe '#remove', use_transactional_tests: false do
context 'with small batch size' do context 'with small batch size' do

View file

@ -4,9 +4,5 @@ require 'rails_helper'
require 'mastodon/cli/upgrade' require 'mastodon/cli/upgrade'
describe Mastodon::CLI::Upgrade do describe Mastodon::CLI::Upgrade do
describe '.exit_on_failure?' do it_behaves_like 'CLI Command'
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
end end

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
shared_examples 'CLI Command' do
it 'configures Thor to exit on failure' do
expect(described_class.exit_on_failure?).to be true
end
it 'descends from the CLI base class' do
expect(described_class.new).to be_a(Mastodon::CLI::Base)
end
end