html-pipeline 2.4.1 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,74 +0,0 @@
1
- require "test_helper"
2
- require "helpers/mocked_instrumentation_service"
3
-
4
- class HTML::PipelineTest < Minitest::Test
5
- Pipeline = HTML::Pipeline
6
- class TestFilter
7
- def self.call(input, context, result)
8
- input.reverse
9
- end
10
- end
11
-
12
- def setup
13
- @context = {}
14
- @result_class = Hash
15
- @pipeline = Pipeline.new [TestFilter], @context, @result_class
16
- end
17
-
18
- def test_filter_instrumentation
19
- service = MockedInstrumentationService.new
20
- events = service.subscribe "call_filter.html_pipeline"
21
- @pipeline.instrumentation_service = service
22
- filter(body = "hello")
23
- event, payload, res = events.pop
24
- assert event, "event expected"
25
- assert_equal "call_filter.html_pipeline", event
26
- assert_equal TestFilter.name, payload[:filter]
27
- assert_equal @pipeline.class.name, payload[:pipeline]
28
- assert_equal body.reverse, payload[:result][:output]
29
- end
30
-
31
- def test_pipeline_instrumentation
32
- service = MockedInstrumentationService.new
33
- events = service.subscribe "call_pipeline.html_pipeline"
34
- @pipeline.instrumentation_service = service
35
- filter(body = "hello")
36
- event, payload, res = events.pop
37
- assert event, "event expected"
38
- assert_equal "call_pipeline.html_pipeline", event
39
- assert_equal @pipeline.filters.map(&:name), payload[:filters]
40
- assert_equal @pipeline.class.name, payload[:pipeline]
41
- assert_equal body.reverse, payload[:result][:output]
42
- end
43
-
44
- def test_default_instrumentation_service
45
- service = 'default'
46
- Pipeline.default_instrumentation_service = service
47
- pipeline = Pipeline.new [], @context, @result_class
48
- assert_equal service, pipeline.instrumentation_service
49
- ensure
50
- Pipeline.default_instrumentation_service = nil
51
- end
52
-
53
- def test_setup_instrumentation
54
- assert_nil @pipeline.instrumentation_service
55
-
56
- service = MockedInstrumentationService.new
57
- events = service.subscribe "call_pipeline.html_pipeline"
58
- @pipeline.setup_instrumentation name = 'foo', service
59
-
60
- assert_equal service, @pipeline.instrumentation_service
61
- assert_equal name, @pipeline.instrumentation_name
62
-
63
- filter(body = 'foo')
64
-
65
- event, payload, res = events.pop
66
- assert event, "expected event"
67
- assert_equal name, payload[:pipeline]
68
- assert_equal body.reverse, payload[:result][:output]
69
- end
70
-
71
- def filter(input)
72
- @pipeline.call(input)
73
- end
74
- end
data/test/test_helper.rb DELETED
@@ -1,16 +0,0 @@
1
- require 'bundler/setup'
2
- require 'html/pipeline'
3
- require 'minitest/autorun'
4
-
5
- require 'active_support/core_ext/string'
6
-
7
- module TestHelpers
8
- # Asserts that two html fragments are equivalent. Attribute order
9
- # will be ignored.
10
- def assert_equal_html(expected, actual)
11
- assert_equal Nokogiri::HTML::DocumentFragment.parse(expected).to_hash,
12
- Nokogiri::HTML::DocumentFragment.parse(actual).to_hash
13
- end
14
- end
15
-
16
- Minitest::Test.send(:include, TestHelpers)