sandthorn_event_filter 0.0.2.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/sandthorn_event_filter/rspec/custom_matchers.rb +29 -0
- data/lib/sandthorn_event_filter/version.rb +1 -1
- data/spec/filter_spec.rb +9 -0
- data/spec/matchers/attribute_changed_matcher_spec.rb +2 -2
- data/spec/matchers/block_matcher_spec.rb +2 -2
- data/spec/matchers/class_matcher_spec.rb +4 -4
- data/spec/matchers/event_name_matcher_spec.rb +3 -4
- data/spec/matchers/extract_spec.rb +6 -6
- data/spec/matchers/matcher_collection_spec.rb +2 -2
- data/spec/matchers/sequence_number_matcher_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -11
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49c7333b460d91409411e0513f2af60e62a9f2da
|
4
|
+
data.tar.gz: 4b8c59519bf1a4f8f6d98ff77626a3e5a9cccd00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62a0d64ef0a763a31655a7953c241c765166deb5a85ce98125e9b1e734c97e5e44ea84bd0a8d54b8365cb92bcd2f44b10ad623c1c86609dbe1664cfdbe590579
|
7
|
+
data.tar.gz: 0620d2f171ed87ee1c96a758a306b858262c3a9c69e2522a86fcb8bb8fbe53e935d78e5b93fe3f6e8c88ab2be3896bdd3c2e3cae92c86a378d25bee703b99e1a
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
module SandthornEventFilter
|
2
|
+
module Rspec
|
3
|
+
module CustomMatchers
|
4
|
+
def self.install!
|
5
|
+
if defined?(Rspec)
|
6
|
+
::RSpec::Matchers.define :have_name do |expected|
|
7
|
+
match do |actual|
|
8
|
+
actual[:event_name] == expected
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
::RSpec::Matchers.define :have_aggregate_type do |expected|
|
13
|
+
match do |actual|
|
14
|
+
actual[:aggregate_type] == expected
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
::RSpec::Matchers.define :match do |expected|
|
19
|
+
match do |actual|
|
20
|
+
actual.match?(expected)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
self.install!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/filter_spec.rb
CHANGED
@@ -97,6 +97,15 @@ module SandthornEventFilter
|
|
97
97
|
|
98
98
|
end
|
99
99
|
|
100
|
+
describe ".match?" do
|
101
|
+
context "when the filter is empty" do
|
102
|
+
it "should match everything" do
|
103
|
+
filter = Filter.new
|
104
|
+
expect(filter).to match({})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
100
109
|
describe 'tests on actual data' do
|
101
110
|
let(:events) { SandthornEventFilter::Fixtures::EVENTS }
|
102
111
|
|
@@ -32,14 +32,14 @@ module SandthornEventFilter
|
|
32
32
|
context "when given a changed attributes" do
|
33
33
|
it "should return true" do
|
34
34
|
matcher = AttributeChangedMatcher.new("name")
|
35
|
-
expect(matcher.match
|
35
|
+
expect(matcher).to match(event)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "when given a non-changed attribute" do
|
40
40
|
it "should return false" do
|
41
41
|
matcher = AttributeChangedMatcher.new("foo")
|
42
|
-
expect(matcher.match
|
42
|
+
expect(matcher).to_not match(event)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -8,7 +8,7 @@ module SandthornEventFilter
|
|
8
8
|
matcher = BlockMatcher.new do |event|
|
9
9
|
true
|
10
10
|
end
|
11
|
-
expect(matcher.match
|
11
|
+
expect(matcher).to match({})
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -17,7 +17,7 @@ module SandthornEventFilter
|
|
17
17
|
matcher = BlockMatcher.new do |event|
|
18
18
|
false
|
19
19
|
end
|
20
|
-
expect(matcher.match
|
20
|
+
expect(matcher).to_not match({})
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -11,14 +11,14 @@ module SandthornEventFilter
|
|
11
11
|
context "and given an event of that class" do
|
12
12
|
it "should return true" do
|
13
13
|
filter = AggregateTypeMatcher.new("Foo")
|
14
|
-
expect(filter.match
|
14
|
+
expect(filter).to match(foo_event)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "when given a non-matching event" do
|
19
19
|
it "should return false" do
|
20
20
|
filter = AggregateTypeMatcher.new("Foo")
|
21
|
-
expect(filter.match
|
21
|
+
expect(filter).to_not match(bar_event)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -26,8 +26,8 @@ module SandthornEventFilter
|
|
26
26
|
context "when given multiple types" do
|
27
27
|
it "should return true if event matches any of the input types" do
|
28
28
|
filter = AggregateTypeMatcher.new(["Bar", "Foo"])
|
29
|
-
expect(filter.match
|
30
|
-
expect(filter.match
|
29
|
+
expect(filter).to match(foo_event)
|
30
|
+
expect(filter).to match(bar_event)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -11,14 +11,14 @@ module SandthornEventFilter
|
|
11
11
|
context "and given an event of that name" do
|
12
12
|
it "should return true" do
|
13
13
|
filter = EventNameMatcher.new("Foo")
|
14
|
-
expect(filter.match
|
14
|
+
expect(filter).to match(foo_event)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "when given a non-matching event" do
|
19
19
|
it "should return false" do
|
20
20
|
filter = EventNameMatcher.new("Foo")
|
21
|
-
expect(filter.match
|
21
|
+
expect(filter).to_not match(bar_event)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -26,8 +26,7 @@ module SandthornEventFilter
|
|
26
26
|
context "when given multiple event names" do
|
27
27
|
it "should return true if event matches any of the input event names" do
|
28
28
|
filter = EventNameMatcher.new(["Bar", "Foo"])
|
29
|
-
expect(filter.match
|
30
|
-
expect(filter.match?(bar_event)).to be_truthy
|
29
|
+
expect(filter).to match(foo_event).and(match(bar_event))
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -12,13 +12,13 @@ module SandthornEventFilter
|
|
12
12
|
|
13
13
|
context "when given a matching event" do
|
14
14
|
it "should match" do
|
15
|
-
expect(foo_extractor.match
|
15
|
+
expect(foo_extractor).to match(foo_event)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context "when given a non-matching event" do
|
20
20
|
it "shouldn't match" do
|
21
|
-
expect(foo_extractor.match
|
21
|
+
expect(foo_extractor).to_not match(bar_event)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -28,13 +28,13 @@ module SandthornEventFilter
|
|
28
28
|
|
29
29
|
context "when given a matching event" do
|
30
30
|
it "should match" do
|
31
|
-
expect(foo_extractor.match
|
31
|
+
expect(foo_extractor).to match(foo_event)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context "when given a non-matching event" do
|
36
36
|
it "should not match" do
|
37
|
-
expect(foo_extractor.match
|
37
|
+
expect(foo_extractor).to_not match(bar_event)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -43,14 +43,14 @@ module SandthornEventFilter
|
|
43
43
|
let(:combo) { Extract.new(types: "Foo", events: "foo") }
|
44
44
|
context "when given an event that matches all of the criteria" do
|
45
45
|
it "should match" do
|
46
|
-
expect(combo.match
|
46
|
+
expect(combo).to match(foo_event)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
context "when given a partially matching event" do
|
51
51
|
it "should not match" do
|
52
52
|
event = { event_name: "foo", aggregate_type: "Baz" }
|
53
|
-
expect(combo.match
|
53
|
+
expect(combo).to_not match(event)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -47,7 +47,7 @@ module SandthornEventFilter
|
|
47
47
|
it "returns true" do
|
48
48
|
filters = [IdentityMatcher.new, IdentityMatcher.new]
|
49
49
|
new_chain = chain.add(filters)
|
50
|
-
expect(new_chain.match
|
50
|
+
expect(new_chain).to match({foo: :bar})
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -55,7 +55,7 @@ module SandthornEventFilter
|
|
55
55
|
it "returns false" do
|
56
56
|
filters = [IdentityMatcher.new, NotMatcher.new(IdentityMatcher.new)]
|
57
57
|
new_chain = chain.add(filters)
|
58
|
-
expect(new_chain.match
|
58
|
+
expect(new_chain).to_not match({foo: :bar})
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -13,7 +13,7 @@ module SandthornEventFilter
|
|
13
13
|
it "should match" do
|
14
14
|
sequence_number = event[:sequence_number]
|
15
15
|
matcher = SequenceNumberMatcher.new(sequence_number - 1)
|
16
|
-
expect(matcher.match
|
16
|
+
expect(matcher).to match(event)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,8 +22,8 @@ module SandthornEventFilter
|
|
22
22
|
sequence_number = event[:sequence_number]
|
23
23
|
exact_matcher = SequenceNumberMatcher.new(sequence_number)
|
24
24
|
larger_matcher = SequenceNumberMatcher.new(sequence_number + 1)
|
25
|
-
expect(exact_matcher.match
|
26
|
-
expect(larger_matcher.match
|
25
|
+
expect(exact_matcher).to_not match(event)
|
26
|
+
expect(larger_matcher).to_not match(event)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,17 +9,7 @@ end
|
|
9
9
|
require 'sandthorn_event_filter'
|
10
10
|
require './spec/data/events'
|
11
11
|
|
12
|
+
require 'sandthorn_event_filter/rspec/custom_matchers'
|
12
13
|
|
13
14
|
RSpec.configure do |config|
|
14
15
|
end
|
15
|
-
RSpec::Matchers.define :have_name do |expected|
|
16
|
-
match do |actual|
|
17
|
-
actual[:event_name] == expected
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
RSpec::Matchers.define :have_aggregate_type do |expected|
|
22
|
-
match do |actual|
|
23
|
-
actual[:aggregate_type] == expected
|
24
|
-
end
|
25
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandthorn_event_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesper Josefsson
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/sandthorn_event_filter/matchers/matcher_collection.rb
|
164
164
|
- lib/sandthorn_event_filter/matchers/not_matcher.rb
|
165
165
|
- lib/sandthorn_event_filter/matchers/sequence_number_matcher.rb
|
166
|
+
- lib/sandthorn_event_filter/rspec/custom_matchers.rb
|
166
167
|
- lib/sandthorn_event_filter/version.rb
|
167
168
|
- sandthorn_event_filter.gemspec
|
168
169
|
- spec/data/events.rb
|