]>
cat aescling's git repositories - mastodon.git/blob - spec/lib/formatter_spec.rb
3 RSpec
.describe Formatter
do
4 let(:account) { Fabricate(:account, username
: 'alice') }
5 let(:local_status) { Fabricate(:status, text
: 'Hello world http://google.com', account
: account
) }
6 let(:remote_status) { Fabricate(:status, text
: '<script>alert("Hello")</script> Beep boop', uri
: 'beepboop', account
: account
) }
9 subject
{ Formatter
.instance
.format(local_status
) }
11 it
'returns a string' do
12 expect(subject
).to be_a String
15 it
'contains plain text' do
16 expect(subject
).to
match('Hello world')
19 it
'contains a link' do
20 expect(subject
).to
match('<a href="http://google.com" rel="nofollow noopener" target="_blank"><span class="invisible">http://</span><span class="">google.com</span><span class="invisible"></span></a>')
24 it 'matches a stand-alone medium URL' do
25 expect(subject.match('https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4')[0]).to eq 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4'
28 it 'matches a stand-alone google URL' do
29 expect(subject.match('http://google.com')[0]).to eq 'http://google.com'
32 it 'matches a URL without trailing period' do
33 expect(subject.match('http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ')[0]).to eq 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona'
36 it 'matches a URL without closing paranthesis' do
37 expect(subject.match('(http://google.com/)')[0]).to eq 'http://google.com'
40 it 'matches a URL without exclamation point' do
41 expect(subject.match('http://www.google.com! ')[0]).to eq 'http://www.google.com'
44 it 'matches a URL with a query string' do
45 expect(subject.match('https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink')[0]).to eq 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink'
48 it 'matches a URL with parenthesis in it' do
49 expect(subject.match('https://en.wikipedia.org/wiki/Diaspora_(software)')[0]).to eq 'https://en.wikipedia.org/wiki/Diaspora_(software)'
54 describe
'#reformat' do
55 subject
{ Formatter
.instance
.format(remote_status
) }
57 it
'returns a string' do
58 expect(subject
).to be_a String
61 it
'contains plain text' do
62 expect(subject
).to
match('Beep boop')
65 it
'does not contain scripts' do
66 expect(subject
).to_not
match('<script>alert("Hello")</script>')
This page took 0.187827 seconds and 4 git commands to generate.