Add shared example for CLI command specs (#28165)

shrike
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
let(:cli) { described_class.new }
it_behaves_like 'CLI Command'
# `parallelize_with_progress` cannot run in transactions, so instead,
# stub it with an alternative implementation that runs sequentially
# and can run in transactions.
@ -24,12 +26,6 @@ describe Mastodon::CLI::Accounts do
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
shared_examples 'a new user with given email address and username' 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
let(:cli) { described_class.new }
describe '.exit_on_failure?' do
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
it_behaves_like 'CLI Command'
describe '#clear' do
before { allow(Rails.cache).to receive(:clear) }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,11 +6,7 @@ require 'mastodon/cli/maintenance'
describe Mastodon::CLI::Maintenance do
let(:cli) { described_class.new }
describe '.exit_on_failure?' do
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
it_behaves_like 'CLI Command'
describe '#fix_duplicates' 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
let(:cli) { described_class.new }
describe '.exit_on_failure?' do
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
it_behaves_like 'CLI Command'
describe '#remove' 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
let(:cli) { described_class.new }
describe '.exit_on_failure?' do
it 'returns true' do
expect(described_class.exit_on_failure?).to be true
end
end
it_behaves_like 'CLI Command'
describe '#remove' do
context 'with relevant preview cards' do

View File

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

View File

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

View File

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

View File

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