From b742ce9d0961d9b992fce66ba4ecb3ff414c90c0 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 15 Oct 2024 09:58:45 -0400 Subject: [PATCH] Reduce factory creation (17 -> 0) in `PlainTextFormatter` spec (#32487) --- spec/lib/plain_text_formatter_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/lib/plain_text_formatter_spec.rb b/spec/lib/plain_text_formatter_spec.rb index b22f473d0c..4683e15093 100644 --- a/spec/lib/plain_text_formatter_spec.rb +++ b/spec/lib/plain_text_formatter_spec.rb @@ -7,7 +7,7 @@ RSpec.describe PlainTextFormatter do subject { described_class.new(status.text, status.local?).to_s } context 'when status is local' do - let(:status) { Fabricate(:status, text: '

a text by a nerd who uses an HTML tag in text

', uri: nil) } + let(:status) { Fabricate.build(:status, text: '

a text by a nerd who uses an HTML tag in text

', uri: nil) } it 'returns the raw text' do expect(subject).to eq '

a text by a nerd who uses an HTML tag in text

' @@ -15,10 +15,10 @@ RSpec.describe PlainTextFormatter do end context 'when status is remote' do - let(:remote_account) { Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') } + let(:remote_account) { Fabricate.build(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/') } context 'when text contains inline HTML tags' do - let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem ipsum') } + let(:status) { Fabricate.build(:status, account: remote_account, text: 'Lorem ipsum') } it 'strips the tags' do expect(subject).to eq 'Lorem ipsum' @@ -26,7 +26,7 @@ RSpec.describe PlainTextFormatter do end context 'when text contains

tags' do - let(:status) { Fabricate(:status, account: remote_account, text: '

Lorem

ipsum

') } + let(:status) { Fabricate.build(:status, account: remote_account, text: '

Lorem

ipsum

') } it 'inserts a newline' do expect(subject).to eq "Lorem\nipsum" @@ -34,7 +34,7 @@ RSpec.describe PlainTextFormatter do end context 'when text contains a single
tag' do - let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem
ipsum') } + let(:status) { Fabricate.build(:status, account: remote_account, text: 'Lorem
ipsum') } it 'inserts a newline' do expect(subject).to eq "Lorem\nipsum" @@ -42,7 +42,7 @@ RSpec.describe PlainTextFormatter do end context 'when text contains consecutive
tag' do - let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem


ipsum') } + let(:status) { Fabricate.build(:status, account: remote_account, text: 'Lorem


ipsum') } it 'inserts a single newline' do expect(subject).to eq "Lorem\nipsum" @@ -50,7 +50,7 @@ RSpec.describe PlainTextFormatter do end context 'when text contains HTML entity' do - let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem & ipsum ❤') } + let(:status) { Fabricate.build(:status, account: remote_account, text: 'Lorem & ipsum ❤') } it 'unescapes the entity' do expect(subject).to eq 'Lorem & ipsum ❤' @@ -58,7 +58,7 @@ RSpec.describe PlainTextFormatter do end context 'when text contains ipsum') } + let(:status) { Fabricate.build(:status, account: remote_account, text: 'Lorem ipsum') } it 'strips the tag and its contents' do expect(subject).to eq 'Lorem ipsum' @@ -66,7 +66,7 @@ RSpec.describe PlainTextFormatter do end context 'when text contains an HTML comment tags' do - let(:status) { Fabricate(:status, account: remote_account, text: 'Lorem ipsum') } + let(:status) { Fabricate.build(:status, account: remote_account, text: 'Lorem ipsum') } it 'strips the comment' do expect(subject).to eq 'Lorem ipsum' @@ -74,7 +74,7 @@ RSpec.describe PlainTextFormatter do end context 'when text contains HTML ruby tags' do - let(:status) { Fabricate(:status, account: remote_account, text: '

Lorem 明日 (Ashita) ipsum

') } + let(:status) { Fabricate.build(:status, account: remote_account, text: '

Lorem 明日 (Ashita) ipsum

') } it 'strips the comment' do expect(subject).to eq 'Lorem 明日 (Ashita) ipsum'