Formalize some patterns in cli specs (#28255)
This commit is contained in:
parent
5d97a897c8
commit
ad34d33bfd
17 changed files with 492 additions and 449 deletions
|
@ -4,18 +4,24 @@ require 'rails_helper'
|
|||
require 'mastodon/cli/media'
|
||||
|
||||
describe Mastodon::CLI::Media do
|
||||
subject { cli.invoke(action, arguments, options) }
|
||||
|
||||
let(:cli) { described_class.new }
|
||||
let(:arguments) { [] }
|
||||
let(:options) { {} }
|
||||
|
||||
it_behaves_like 'CLI Command'
|
||||
|
||||
describe '#remove' do
|
||||
let(:action) { :remove }
|
||||
|
||||
context 'with --prune-profiles and --remove-headers' do
|
||||
let(:options) { { prune_profiles: true, remove_headers: true } }
|
||||
|
||||
it 'warns about usage and exits' do
|
||||
expect { cli.invoke(:remove, [], options) }.to output(
|
||||
a_string_including('--prune-profiles and --remove-headers should not be specified simultaneously')
|
||||
).to_stdout.and raise_error(SystemExit)
|
||||
expect { subject }
|
||||
.to output_results('--prune-profiles and --remove-headers should not be specified simultaneously')
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,9 +29,9 @@ describe Mastodon::CLI::Media do
|
|||
let(:options) { { include_follows: true } }
|
||||
|
||||
it 'warns about usage and exits' do
|
||||
expect { cli.invoke(:remove, [], options) }.to output(
|
||||
a_string_including('--include-follows can only be used with --prune-profiles or --remove-headers')
|
||||
).to_stdout.and raise_error(SystemExit)
|
||||
expect { subject }
|
||||
.to output_results('--include-follows can only be used with --prune-profiles or --remove-headers')
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,9 +44,8 @@ describe Mastodon::CLI::Media do
|
|||
let(:options) { { prune_profiles: true } }
|
||||
|
||||
it 'removes account avatars' do
|
||||
expect { cli.invoke(:remove, [], options) }.to output(
|
||||
a_string_including('Visited 1')
|
||||
).to_stdout
|
||||
expect { subject }
|
||||
.to output_results('Visited 1')
|
||||
|
||||
expect(account.reload.avatar).to be_blank
|
||||
end
|
||||
|
@ -50,9 +55,8 @@ describe Mastodon::CLI::Media do
|
|||
let(:options) { { remove_headers: true } }
|
||||
|
||||
it 'removes account header' do
|
||||
expect { cli.invoke(:remove, [], options) }.to output(
|
||||
a_string_including('Visited 1')
|
||||
).to_stdout
|
||||
expect { subject }
|
||||
.to output_results('Visited 1')
|
||||
|
||||
expect(account.reload.header).to be_blank
|
||||
end
|
||||
|
@ -64,9 +68,8 @@ describe Mastodon::CLI::Media do
|
|||
|
||||
context 'without options' do
|
||||
it 'removes account avatars' do
|
||||
expect { cli.invoke(:remove) }.to output(
|
||||
a_string_including('Removed 1')
|
||||
).to_stdout
|
||||
expect { subject }
|
||||
.to output_results('Removed 1')
|
||||
|
||||
expect(media_attachment.reload.file).to be_blank
|
||||
expect(media_attachment.reload.thumbnail).to be_blank
|
||||
|
@ -76,25 +79,24 @@ describe Mastodon::CLI::Media do
|
|||
end
|
||||
|
||||
describe '#usage' do
|
||||
context 'without options' do
|
||||
let(:options) { {} }
|
||||
let(:action) { :usage }
|
||||
|
||||
context 'without options' do
|
||||
it 'reports about storage size' do
|
||||
expect { cli.invoke(:usage, [], options) }.to output(
|
||||
a_string_including('0 Bytes')
|
||||
).to_stdout
|
||||
expect { subject }
|
||||
.to output_results('0 Bytes')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#refresh' do
|
||||
context 'without any options' do
|
||||
let(:options) { {} }
|
||||
let(:action) { :refresh }
|
||||
|
||||
context 'without any options' do
|
||||
it 'warns about usage and exits' do
|
||||
expect { cli.invoke(:refresh, [], options) }.to output(
|
||||
a_string_including('Specify the source')
|
||||
).to_stdout.and raise_error(SystemExit)
|
||||
expect { subject }
|
||||
.to output_results('Specify the source')
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -108,9 +110,8 @@ describe Mastodon::CLI::Media do
|
|||
let(:status) { Fabricate(:status) }
|
||||
|
||||
it 'redownloads the attachment file' do
|
||||
expect { cli.invoke(:refresh, [], options) }.to output(
|
||||
a_string_including('Downloaded 1 media')
|
||||
).to_stdout
|
||||
expect { subject }
|
||||
.to output_results('Downloaded 1 media')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -119,9 +120,9 @@ describe Mastodon::CLI::Media do
|
|||
let(:options) { { account: 'not-real-user@example.host' } }
|
||||
|
||||
it 'warns about usage and exits' do
|
||||
expect { cli.invoke(:refresh, [], options) }.to output(
|
||||
a_string_including('No such account')
|
||||
).to_stdout.and raise_error(SystemExit)
|
||||
expect { subject }
|
||||
.to output_results('No such account')
|
||||
.and raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -135,9 +136,8 @@ describe Mastodon::CLI::Media do
|
|||
let(:account) { Fabricate(:account) }
|
||||
|
||||
it 'redownloads the attachment file' do
|
||||
expect { cli.invoke(:refresh, [], options) }.to output(
|
||||
a_string_including('Downloaded 1 media')
|
||||
).to_stdout
|
||||
expect { subject }
|
||||
.to output_results('Downloaded 1 media')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -153,9 +153,8 @@ describe Mastodon::CLI::Media do
|
|||
let(:account) { Fabricate(:account, domain: domain) }
|
||||
|
||||
it 'redownloads the attachment file' do
|
||||
expect { cli.invoke(:refresh, [], options) }.to output(
|
||||
a_string_including('Downloaded 1 media')
|
||||
).to_stdout
|
||||
expect { subject }
|
||||
.to output_results('Downloaded 1 media')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue