From fa767ff3bb5045114933cc0e2fb6141ce6d2ebbc Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Sun, 2 Jul 2023 17:29:47 +0330 Subject: [PATCH] Update specs --- spec/bidify_spec.rb | 178 ++--------------------------- spec/html_string_bidifier_spec.rb | 183 ++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 171 deletions(-) create mode 100644 spec/html_string_bidifier_spec.rb diff --git a/spec/bidify_spec.rb b/spec/bidify_spec.rb index 254b127..cdd194b 100644 --- a/spec/bidify_spec.rb +++ b/spec/bidify_spec.rb @@ -1,181 +1,17 @@ # frozen_string_literal: true require 'bidify' +require 'bidify/html_string_bidifier' describe 'Bidify' do - describe '#bidify' do - it 'bidifies a single paragraph' do - input = '

some text

' - expected_output = '

some text

' + it '#bidify_html_string calls HtmlStringBidifier#apply with the given input' do + input = '

some text

' - actual_output = Bidify.bidify(input) + html_string_bidifier = instance_spy(Bidify::HtmlStringBidifier) + allow(Bidify::HtmlStringBidifier).to receive(:new).and_return(html_string_bidifier) - expect(actual_output).to eq expected_output - end + Bidify.bidify_html_string(input) - it 'bidifies all non-list tags in bidifiable tags list' do - input = <<~HTML -
Content
-

Content

-

Content

-

Content

-

Content

-
Content
-
Content
-

Content

-
Content
- HTML - - expected_output = <<~HTML -
Content
-

Content

-

Content

-

Content

-

Content

-
Content
-
Content
-

Content

-
Content
- HTML - - actual_output = Bidify.bidify(input) - - expect(actual_output).to eq expected_output - end - - it 'bidifies non list nested elements and ignore the first inner element' do - input = <<~HTML -
-

Item 1

-

Item 2

-
- HTML - - expected_output = <<~HTML -
-

Item 1

-

Item 2

-
- HTML - - actual_output = Bidify.bidify(input) - - expect(actual_output).to eq expected_output - end - - it "doesn't bidify li elements by default" do - input = <<~HTML - - HTML - - expected_output = <<~HTML - - HTML - - actual_output = Bidify.bidify(input) - - expect(actual_output).to eq expected_output - end - - it 'bidifies non-list nested elements with plain text as the first content' do - input = <<~HTML -
- blah -

Item 1

-

Item 2

-
- HTML - - expected_output = <<~HTML -
- blah -

Item 1

-

Item 2

-
- HTML - - actual_output = Bidify.bidify(input) - - expect(actual_output).to eq expected_output - end - - it 'bidifies non-list nested elements and ignores html comments' do - input = <<~HTML -
- -

Item 1

-

Item 2

-
- HTML - - expected_output = <<~HTML -
- -

Item 1

-

Item 2

-
- HTML - - actual_output = Bidify.bidify(input) - - expect(actual_output).to eq expected_output - end - - it 'skips tags not included in bidifiable tags by default' do - input = <<~HTML - Not getting affected - -
content
-
content
- - content - HTML - - expected_output = input - - actual_output = Bidify.bidify(input) - - expect(actual_output).to eq expected_output - end - - it 'skips blank lines' do - input = <<~HTML -
- -

Item 1

-

Item 2

-
- HTML - - expected_output = <<~HTML -
- -

Item 1

-

Item 2

-
- HTML - - actual_output = Bidify.bidify(input) - - expect(actual_output).to eq expected_output - end + expect(html_string_bidifier).to have_received(:apply).with(input) end end diff --git a/spec/html_string_bidifier_spec.rb b/spec/html_string_bidifier_spec.rb new file mode 100644 index 0000000..77c5f25 --- /dev/null +++ b/spec/html_string_bidifier_spec.rb @@ -0,0 +1,183 @@ +# frozen_string_literal: true + +require 'bidify' + +describe 'Bidify' do + describe '::StringHtmlBidifier.apply' do + let(:bidifier) { Bidify::HtmlStringBidifier.new } + + it 'bidifies a single paragraph' do + input = '

some text

' + expected_output = '

some text

' + + actual_output = bidifier.apply(input) + + expect(actual_output).to eq expected_output + end + + it 'bidifies all non-list tags in bidifiable tags list' do + input = <<~HTML +
Content
+

Content

+

Content

+

Content

+

Content

+
Content
+
Content
+

Content

+
Content
+ HTML + + expected_output = <<~HTML +
Content
+

Content

+

Content

+

Content

+

Content

+
Content
+
Content
+

Content

+
Content
+ HTML + + actual_output = bidifier.apply(input) + + expect(actual_output).to eq expected_output + end + + it 'bidifies non list nested elements and ignore the first inner element' do + input = <<~HTML +
+

Item 1

+

Item 2

+
+ HTML + + expected_output = <<~HTML +
+

Item 1

+

Item 2

+
+ HTML + + actual_output = bidifier.apply(input) + + expect(actual_output).to eq expected_output + end + + it "doesn't bidify li elements by default" do + input = <<~HTML + + HTML + + expected_output = <<~HTML + + HTML + + actual_output = bidifier.apply(input) + + expect(actual_output).to eq expected_output + end + + it 'bidifies non-list nested elements with plain text as the first content' do + input = <<~HTML +
+ blah +

Item 1

+

Item 2

+
+ HTML + + expected_output = <<~HTML +
+ blah +

Item 1

+

Item 2

+
+ HTML + + actual_output = bidifier.apply(input) + + expect(actual_output).to eq expected_output + end + + it 'bidifies non-list nested elements and ignores html comments' do + input = <<~HTML +
+ +

Item 1

+

Item 2

+
+ HTML + + expected_output = <<~HTML +
+ +

Item 1

+

Item 2

+
+ HTML + + actual_output = bidifier.apply(input) + + expect(actual_output).to eq expected_output + end + + it 'skips tags not included in bidifiable tags by default' do + input = <<~HTML + Not getting affected + +
content
+
content
+ + content + HTML + + expected_output = input + + actual_output = bidifier.apply(input) + + expect(actual_output).to eq expected_output + end + + it 'skips blank lines' do + input = <<~HTML +
+ +

Item 1

+

Item 2

+
+ HTML + + expected_output = <<~HTML +
+ +

Item 1

+

Item 2

+
+ HTML + + actual_output = bidifier.apply(input) + + expect(actual_output).to eq expected_output + end + end +end