ruby_event_store-rspec 2.0.0 → 2.3.0

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.
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyEventStore
4
+ module RSpec
5
+ class StepByStepFailureMessageFormatter
6
+ class Lingo
7
+ def initialize(published)
8
+ @published = published
9
+ end
10
+ attr_reader :published
11
+ end
12
+
13
+ class HavePublished
14
+ def initialize(differ, lingo)
15
+ @differ = differ
16
+ @lingo = lingo
17
+ end
18
+
19
+ def failure_message(expected, events, stream_name = nil)
20
+ return failure_message_strict(expected, events) if expected.strict?
21
+ return failure_message_no_events if expected.empty?
22
+ expected.events.each do |expected_event|
23
+ correct_event_count = 0
24
+ events_with_correct_type = []
25
+ events.each do |actual_event|
26
+ if expected_event.matches?(actual_event)
27
+ correct_event_count += 1
28
+ elsif expected_event.matches_kind?(actual_event)
29
+ events_with_correct_type << actual_event
30
+ end
31
+ end
32
+
33
+ expectations = expected_message(expected, expected_event, stream_name)
34
+
35
+ if expected.specified_count?
36
+ if correct_event_count >= 1
37
+ reality = failure_message_incorrect_count(expected_event, events_with_correct_type, correct_event_count)
38
+ elsif !events_with_correct_type.empty?
39
+ reality = failure_message_correct_type_incorrect_payload(expected_event, events_with_correct_type)
40
+ else
41
+ reality = failure_message_incorrect_type
42
+ end
43
+ else
44
+ if correct_event_count >= 1
45
+ next
46
+ else
47
+ if !events_with_correct_type.empty?
48
+ reality = failure_message_correct_type_incorrect_payload(expected_event, events_with_correct_type)
49
+ else
50
+ reality = failure_message_incorrect_type
51
+ end
52
+ end
53
+ end
54
+
55
+ return (expectations + reality)
56
+ end
57
+ end
58
+
59
+ def failure_message_when_negated(expected, events, _stream_name = nil)
60
+ return failure_message_when_negated_no_events if expected.empty?
61
+ if expected.specified_count?
62
+ <<~EOS
63
+ expected
64
+ #{expected.events.first.description}
65
+ not to be #{lingo.published} exactly #{expected.count} times
66
+
67
+ #{actual_events_list(events)}
68
+ EOS
69
+ else
70
+ <<~EOS
71
+ expected #{expected_events_list(expected.events)} not to #{"exactly " if expected.strict?}be #{lingo.published}
72
+
73
+ #{actual_events_list(events)}
74
+ EOS
75
+ end
76
+ end
77
+
78
+ private
79
+ attr_reader :differ, :lingo
80
+
81
+ def failure_message_no_events
82
+ "expected anything to be #{lingo.published}\n"
83
+ end
84
+
85
+ def failure_message_when_negated_no_events
86
+ "expected something to be #{lingo.published}\n"
87
+ end
88
+
89
+ def failure_message_incorrect_count(expected_event, events_with_correct_type, correct_event_count)
90
+ [
91
+ <<~EOS,
92
+
93
+ but was #{lingo.published} #{correct_event_count} times
94
+ EOS
95
+
96
+ if !events_with_correct_type.empty?
97
+ [
98
+ <<~EOS.strip,
99
+ There are events of correct type but with incorrect payload:
100
+ EOS
101
+ events_with_correct_type.each_with_index.map {|event_with_correct_type, index| event_diff(expected_event, event_with_correct_type, index) },
102
+ nil
103
+ ]
104
+ end
105
+ ].compact.join("\n")
106
+ end
107
+
108
+ def failure_message_correct_type_incorrect_payload(expected_event, events_with_correct_type)
109
+ <<~EOS
110
+ , but it was not #{lingo.published}
111
+
112
+ There are events of correct type but with incorrect payload:
113
+ #{events_with_correct_type.each_with_index.map {|event_with_correct_type, index| event_diff(expected_event, event_with_correct_type, index) }.join("\n")}
114
+ EOS
115
+ end
116
+
117
+ def event_diff(expected_event, event_with_correct_type, index)
118
+ [
119
+ "#{index + 1}) #{event_with_correct_type.inspect}",
120
+ indent(data_diff(expected_event, event_with_correct_type), 4),
121
+ indent(metadata_diff(expected_event, event_with_correct_type), 4),
122
+ ].reject(&:empty?)
123
+ end
124
+
125
+ def indent(str, count)
126
+ str.to_s.split("\n").map {|l| l.sub(//, " " * count) }
127
+ end
128
+
129
+ def failure_message_incorrect_type
130
+ <<~EOS
131
+ , but there is no event with such type
132
+ EOS
133
+ end
134
+
135
+ def failure_message_strict(expected, events)
136
+ if expected.specified_count?
137
+ <<~EOS
138
+ expected only
139
+ #{expected.events.first.description}
140
+ to be #{lingo.published} #{expected.count} times
141
+
142
+ #{actual_events_list(events)}
143
+ EOS
144
+ else
145
+ <<~EOS
146
+ expected only #{expected_events_list(expected.events)} to be #{lingo.published}
147
+
148
+ #{actual_events_list(events)}
149
+ EOS
150
+ end
151
+ end
152
+
153
+ def data_diff(expected_event, event_with_correct_type)
154
+ if !expected_event.expected_data.nil?
155
+ "data diff:#{differ.diff(expected_event.expected_data, event_with_correct_type.data)}"
156
+ end
157
+ end
158
+
159
+ def metadata_diff(expected_event, event_with_correct_type)
160
+ if !expected_event.expected_metadata.nil?
161
+ "metadata diff:#{differ.diff(expected_event.expected_metadata, event_with_correct_type.metadata.to_h)}"
162
+ end
163
+ end
164
+
165
+ def expected_message(expected, expected_event, stream_name)
166
+ expected_stream = " in stream #{stream_name}" if stream_name
167
+ if expected.specified_count?
168
+ <<~EOS
169
+ expected event
170
+ #{expected_event.description}
171
+ to be #{lingo.published} #{expected.count} times#{expected_stream}
172
+ EOS
173
+ else
174
+ <<~EOS
175
+ expected #{expected_events_list(expected.events)} to be #{lingo.published}#{expected_stream}
176
+
177
+ i.e. expected event
178
+ #{expected_event.description}
179
+ to be #{lingo.published}
180
+ EOS
181
+ end.strip
182
+ end
183
+
184
+ def expected_events_list(expected)
185
+ <<~EOS.strip
186
+ [
187
+ #{expected.map(&:description).map {|d| indent(d, 2) }.join("\n")}
188
+ ]
189
+ EOS
190
+ end
191
+
192
+ def actual_events_list(actual)
193
+ <<~EOS.strip
194
+ but the following was #{lingo.published}: [
195
+ #{actual.map(&:inspect).map {|d| indent(d, 2) }.join("\n")}
196
+ ]
197
+ EOS
198
+ end
199
+ end
200
+
201
+ def have_published(differ)
202
+ HavePublished.new(differ, Lingo.new("published"))
203
+ end
204
+
205
+ def publish(differ)
206
+ HavePublished.new(differ, Lingo.new("published"))
207
+ end
208
+
209
+ def have_applied(differ)
210
+ HavePublished.new(differ, Lingo.new("applied"))
211
+ end
212
+
213
+ def apply(differ)
214
+ HavePublished.new(differ, Lingo.new("applied"))
215
+ end
216
+ end
217
+ end
218
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyEventStore
4
4
  module RSpec
5
- VERSION = "2.0.0"
5
+ VERSION = "2.3.0"
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rspec'
3
+ require "rspec"
4
4
 
5
5
  module RubyEventStore
6
6
  module RSpec
@@ -8,14 +8,32 @@ module RubyEventStore
8
8
  end
9
9
  end
10
10
 
11
- require "ruby_event_store/rspec/version"
12
- require "ruby_event_store/rspec/be_event"
13
- require "ruby_event_store/rspec/have_published"
14
- require "ruby_event_store/rspec/have_applied"
15
- require "ruby_event_store/rspec/have_subscribed_to_events"
16
- require "ruby_event_store/rspec/publish"
17
- require "ruby_event_store/rspec/apply"
18
- require "ruby_event_store/rspec/matchers"
11
+ require_relative "rspec/version"
12
+ require_relative "rspec/be_event"
13
+ require_relative "rspec/expected_collection"
14
+ require_relative "rspec/fetch_events"
15
+ require_relative "rspec/fetch_unpublished_events"
16
+ require_relative "rspec/match_events"
17
+ require_relative "rspec/have_published"
18
+ require_relative "rspec/have_applied"
19
+ require_relative "rspec/have_subscribed_to_events"
20
+ require_relative "rspec/publish"
21
+ require_relative "rspec/apply"
22
+ require_relative "rspec/crude_failure_message_formatter"
23
+ require_relative "rspec/step_by_step_failure_message_formatter"
24
+ require_relative "rspec/matchers"
25
+
26
+ module RubyEventStore
27
+ module RSpec
28
+ def self.default_formatter=(new_formatter)
29
+ @@default_formatter = new_formatter
30
+ end
31
+
32
+ def self.default_formatter
33
+ @@default_formatter ||= CrudeFailureMessageFormatter.new
34
+ end
35
+ end
36
+ end
19
37
 
20
38
  ::RSpec.configure do |config|
21
39
  config.include ::RubyEventStore::RSpec::Matchers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_event_store-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -25,34 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  description:
28
- email:
29
- - dev@arkency.com
28
+ email: dev@arkency.com
30
29
  executables: []
31
30
  extensions: []
32
- extra_rdoc_files: []
31
+ extra_rdoc_files:
32
+ - README.md
33
33
  files:
34
- - ".mutant.yml"
35
- - Gemfile
36
- - Gemfile.lock
37
- - Makefile
38
34
  - README.md
39
- - lib/rails_event_store/rspec.rb
40
35
  - lib/ruby_event_store/rspec.rb
41
36
  - lib/ruby_event_store/rspec/apply.rb
42
37
  - lib/ruby_event_store/rspec/be_event.rb
38
+ - lib/ruby_event_store/rspec/crude_failure_message_formatter.rb
39
+ - lib/ruby_event_store/rspec/expected_collection.rb
40
+ - lib/ruby_event_store/rspec/fetch_events.rb
41
+ - lib/ruby_event_store/rspec/fetch_unpublished_events.rb
43
42
  - lib/ruby_event_store/rspec/have_applied.rb
44
43
  - lib/ruby_event_store/rspec/have_published.rb
45
44
  - lib/ruby_event_store/rspec/have_subscribed_to_events.rb
45
+ - lib/ruby_event_store/rspec/match_events.rb
46
46
  - lib/ruby_event_store/rspec/matchers.rb
47
47
  - lib/ruby_event_store/rspec/publish.rb
48
+ - lib/ruby_event_store/rspec/step_by_step_failure_message_formatter.rb
48
49
  - lib/ruby_event_store/rspec/version.rb
49
- - rails_event_store-rspec.gemspec
50
- - ruby_event_store-rspec.gemspec
51
50
  homepage: https://railseventstore.org
52
51
  licenses:
53
52
  - MIT
54
53
  metadata:
55
- homepage_uri: https://railseventstore.org/
54
+ homepage_uri: https://railseventstore.org
56
55
  changelog_uri: https://github.com/RailsEventStore/rails_event_store/releases
57
56
  source_code_uri: https://github.com/RailsEventStore/rails_event_store
58
57
  bug_tracker_uri: https://github.com/RailsEventStore/rails_event_store/issues
@@ -64,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
63
  requirements:
65
64
  - - ">="
66
65
  - !ruby/object:Gem::Version
67
- version: '0'
66
+ version: '2.6'
68
67
  required_rubygems_version: !ruby/object:Gem::Requirement
69
68
  requirements:
70
69
  - - ">="
@@ -74,5 +73,5 @@ requirements: []
74
73
  rubygems_version: 3.1.4
75
74
  signing_key:
76
75
  specification_version: 4
77
- summary: RSpec matchers for RailsEventStore
76
+ summary: RSpec matchers for RubyEventStore
78
77
  test_files: []
data/.mutant.yml DELETED
@@ -1 +0,0 @@
1
- ../.mutant.yml
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
- git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
- gemspec name: 'ruby_event_store-rspec'
4
-
5
- eval_gemfile '../support/bundler/Gemfile.shared'
6
-
7
- gem 'ruby_event_store', path: '../ruby_event_store'
8
- gem 'aggregate_root', path: '../aggregate_root'
9
-
10
- gem 'diff-lcs', '= 1.3.0'
data/Gemfile.lock DELETED
@@ -1,113 +0,0 @@
1
- PATH
2
- remote: ../aggregate_root
3
- specs:
4
- aggregate_root (2.0.0)
5
- ruby_event_store (= 2.0.0)
6
-
7
- PATH
8
- remote: ../ruby_event_store
9
- specs:
10
- ruby_event_store (2.0.0)
11
- concurrent-ruby (~> 1.0, >= 1.1.6)
12
-
13
- PATH
14
- remote: .
15
- specs:
16
- ruby_event_store-rspec (2.0.0)
17
- rspec (~> 3.0)
18
-
19
- GEM
20
- remote: https://rubygems.org/
21
- remote: https://oss:7AXfeZdAfCqL1PvHm2nvDJO6Zd9UW8IK@gem.mutant.dev/
22
- specs:
23
- abstract_type (0.0.7)
24
- adamantium (0.2.0)
25
- ice_nine (~> 0.11.0)
26
- memoizable (~> 0.4.0)
27
- anima (0.3.2)
28
- abstract_type (~> 0.0.7)
29
- adamantium (~> 0.2)
30
- equalizer (~> 0.0.11)
31
- ast (2.4.1)
32
- concord (0.1.6)
33
- adamantium (~> 0.2.0)
34
- equalizer (~> 0.0.9)
35
- concurrent-ruby (1.1.7)
36
- diff-lcs (1.3)
37
- equalizer (0.0.11)
38
- ice_nine (0.11.2)
39
- memoizable (0.4.2)
40
- thread_safe (~> 0.3, >= 0.3.1)
41
- mprelude (0.1.0)
42
- abstract_type (~> 0.0.7)
43
- adamantium (~> 0.2.0)
44
- concord (~> 0.1.5)
45
- equalizer (~> 0.0.9)
46
- ice_nine (~> 0.11.1)
47
- procto (~> 0.0.2)
48
- mutant (0.10.22)
49
- abstract_type (~> 0.0.7)
50
- adamantium (~> 0.2.0)
51
- anima (~> 0.3.1)
52
- ast (~> 2.2)
53
- concord (~> 0.1.5)
54
- diff-lcs (~> 1.3)
55
- equalizer (~> 0.0.9)
56
- ice_nine (~> 0.11.1)
57
- memoizable (~> 0.4.2)
58
- mprelude (~> 0.1.0)
59
- parser (~> 3.0.0)
60
- procto (~> 0.0.2)
61
- unparser (~> 0.5.6)
62
- variable (~> 0.0.1)
63
- mutant-license (0.1.1.2.1627430819213747598431630701693729869473.0)
64
- mutant-rspec (0.10.22)
65
- mutant (= 0.10.22)
66
- rspec-core (>= 3.8.0, < 4.0.0)
67
- parser (3.0.0.0)
68
- ast (~> 2.4.1)
69
- procto (0.0.3)
70
- rake (13.0.3)
71
- rspec (3.10.0)
72
- rspec-core (~> 3.10.0)
73
- rspec-expectations (~> 3.10.0)
74
- rspec-mocks (~> 3.10.0)
75
- rspec-core (3.10.1)
76
- rspec-support (~> 3.10.0)
77
- rspec-expectations (3.10.1)
78
- diff-lcs (>= 1.2.0, < 2.0)
79
- rspec-support (~> 3.10.0)
80
- rspec-mocks (3.10.1)
81
- diff-lcs (>= 1.2.0, < 2.0)
82
- rspec-support (~> 3.10.0)
83
- rspec-support (3.10.1)
84
- thread_safe (0.3.6)
85
- unparser (0.5.6)
86
- abstract_type (~> 0.0.7)
87
- adamantium (~> 0.2.0)
88
- anima (~> 0.3.1)
89
- concord (~> 0.1.5)
90
- diff-lcs (~> 1.3)
91
- equalizer (~> 0.0.9)
92
- mprelude (~> 0.1.0)
93
- parser (>= 3.0.0)
94
- procto (~> 0.0.2)
95
- variable (0.0.1)
96
- equalizer (~> 0.0.11)
97
-
98
- PLATFORMS
99
- ruby
100
-
101
- DEPENDENCIES
102
- aggregate_root!
103
- diff-lcs (= 1.3.0)
104
- mutant (~> 0.10.21)
105
- mutant-license!
106
- mutant-rspec (~> 0.10.21)
107
- rake (>= 10.0)
108
- rspec (~> 3.6)
109
- ruby_event_store!
110
- ruby_event_store-rspec!
111
-
112
- BUNDLED WITH
113
- 2.1.4