rimless 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c4f8ffaba9e9935ef3dce5dbb9dbe983c0b7405fd2b94b0e3c49abf4d23f37a
4
- data.tar.gz: 2590e8e7d9858460924a7947413770b51b1b367f77add354d79af8f95621eb1e
3
+ metadata.gz: 5763fa79c04ca9d1db4e4c75d98bb76da2ff843acdd6d4be001a85bdfb37bfc2
4
+ data.tar.gz: ede22c5243eab5f54ded67dd3f7c5d9b5d8aafb02b0c0d63280341e5ca96fc29
5
5
  SHA512:
6
- metadata.gz: d06e180257c7c14b712aac3e7bb47105354ab03ad177c68737d32c5867166b83503a25afbd5b3bb60625da05deedc4a77581497a2c02f5b8344452ad0d3fe097
7
- data.tar.gz: e1859640122aaab64ee8af5c1272cc29a86e43551e7b505d5295f18b214baa94db6d6f7273086f10b5417c5af12e7a739643415a218131a95e8a8d1f171761de
6
+ metadata.gz: 5e9c10c5e6699c126aba2aafbbea3812bb429b2bbcc6337fc4b324a06ca2eaf3560fb51b59481763b37f6e8014ff66efee3be831049da3cf1179d3966a0029a5
7
+ data.tar.gz: 996be359cf6113ae58dc7847351b438987af6436510c7f8da5031eaf1e4bd957737c9f0feff8acab3b336b9c7b232348cf2f9b1978e9a911da2b0f46eebca5ce
@@ -0,0 +1,38 @@
1
+ name: Build Documentation
2
+ on:
3
+ repository_dispatch:
4
+ types: [documentation]
5
+
6
+ concurrency:
7
+ group: 'docs'
8
+
9
+ jobs:
10
+ docs:
11
+ name: Build gem documentation
12
+ runs-on: ubuntu-20.04
13
+ timeout-minutes: 5
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+
17
+ - name: Install the correct Ruby version
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 2.5
21
+ bundler-cache: true
22
+
23
+ - name: Prepare the virtual environment
24
+ uses: hausgold/actions/ci@master
25
+ with:
26
+ clone_token: '${{ secrets.CLONE_TOKEN }}'
27
+ settings: '${{ github.repository }}'
28
+ target: ci/gem-test
29
+
30
+ - name: Build gem documentation
31
+ run: make docs
32
+
33
+ - name: Upload the code coverage report
34
+ run: coverage
35
+
36
+ - name: Add this job to the commit status
37
+ run: commit-status '${{ job.status }}'
38
+ if: always()
@@ -0,0 +1,66 @@
1
+ name: Test
2
+ on:
3
+ push:
4
+ branches:
5
+ - '**'
6
+ schedule:
7
+ - cron: '0 0 * * MON'
8
+
9
+ concurrency:
10
+ group: '${{ github.ref }}'
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ test:
15
+ name: 'Test the gem (Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }})'
16
+ runs-on: ubuntu-20.04
17
+ timeout-minutes: 5
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ ruby: [2.5, 2.6, 2.7]
22
+ rails: [4.2, '5.0', 5.1, 5.2, '6.0']
23
+ exclude:
24
+ # Rails 4.2 is not compatible with Ruby 2.7
25
+ - ruby: 2.7
26
+ rails: 4.2
27
+ env:
28
+ BUNDLE_GEMFILE: 'gemfiles/rails_${{ matrix.rails }}.gemfile'
29
+ steps:
30
+ - uses: actions/checkout@v2
31
+
32
+ - name: Install the correct Ruby version
33
+ uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: ${{ matrix.ruby }}
36
+ bundler-cache: true
37
+
38
+ - name: Prepare the virtual environment
39
+ uses: hausgold/actions/ci@master
40
+ with:
41
+ clone_token: '${{ secrets.CLONE_TOKEN }}'
42
+ settings: '${{ github.repository }}'
43
+ target: ci/gem-test
44
+
45
+ - name: Run the gem tests
46
+ run: make test
47
+
48
+ - name: Upload the code coverage report
49
+ run: coverage
50
+
51
+ trigger-docs:
52
+ name: Trigger the documentation upload
53
+ runs-on: ubuntu-20.04
54
+ timeout-minutes: 2
55
+ needs: test
56
+ if: github.ref == 'refs/heads/master'
57
+ steps:
58
+ - name: Prepare the virtual environment
59
+ uses: hausgold/actions/ci@master
60
+ with:
61
+ clone_token: '${{ secrets.CLONE_TOKEN }}'
62
+ settings: '${{ github.repository }}'
63
+ target: ci/noop
64
+
65
+ - name: Trigger the documentation upload
66
+ run: workflow documentation
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 1.2.0
2
+
3
+ * Added a `capture_kafka_messages` helper for RSpec (#12)
4
+
1
5
  ### 1.1.1
2
6
 
3
7
  * Corrected the GNU Make release target
data/Makefile CHANGED
@@ -30,7 +30,6 @@ APPRAISAL ?= appraisal
30
30
  BUNDLE ?= bundle
31
31
  GEM ?= gem
32
32
  RAKE ?= rake
33
- RAKE ?= rake
34
33
  RUBOCOP ?= rubocop
35
34
  YARD ?= yard
36
35
 
@@ -80,7 +79,7 @@ install:
80
79
  $(GEM) install bundler -v "~> 1.0")
81
80
  @$(call run-shell,$(BUNDLE) exec $(APPRAISAL) install)
82
81
 
83
- update: install
82
+ update:
84
83
  # Install the dependencies
85
84
  @$(MKDIR) -p $(VENDOR_DIR)
86
85
  @$(call run-shell,$(BUNDLE) exec $(APPRAISAL) update)
@@ -91,7 +90,7 @@ test: \
91
90
 
92
91
  test-specs:
93
92
  # Run the whole test suite
94
- @$(call run-shell,$(BUNDLE) exec $(RAKE))
93
+ @$(call run-shell,$(BUNDLE) exec $(RAKE) stats spec)
95
94
 
96
95
  $(TEST_GEMFILES): GEMFILE=$(@:test-%=%)
97
96
  $(TEST_GEMFILES):
@@ -130,24 +129,24 @@ endif
130
129
 
131
130
  distclean: clean clean-containers clean-images
132
131
 
133
- shell: install
132
+ shell:
134
133
  # Run an interactive shell on the container
135
134
  @$(call run-shell,$(BASH) -i)
136
135
 
137
- shell-irb: install
136
+ shell-irb:
138
137
  # Run an interactive IRB shell on the container
139
138
  @$(call run-shell,bin/console)
140
139
 
141
- docs: install
140
+ docs:
142
141
  # Build the API documentation
143
142
  @$(call run-shell,$(BUNDLE) exec $(YARD) -q && \
144
143
  $(BUNDLE) exec $(YARD) stats --list-undoc --compact)
145
144
 
146
- notes: install
145
+ notes:
147
146
  # Print the code statistics (library and test suite)
148
147
  @$(call run-shell,$(BUNDLE) exec $(RAKE) notes)
149
148
 
150
- stats: install
149
+ stats:
151
150
  # Print all the notes from the code
152
151
  @$(call run-shell,$(BUNDLE) exec $(RAKE) stats)
153
152
 
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ![rimless](doc/assets/project.svg)
2
2
 
3
- [![Build Status](https://travis-ci.com/hausgold/rimless.svg?token=4XcyqxxmkyBSSV3wWRt7&branch=master)](https://travis-ci.com/hausgold/rimless)
3
+ [![Continuous Integration](https://github.com/hausgold/rimless/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/hausgold/rimless/actions/workflows/test.yml)
4
4
  [![Gem Version](https://badge.fury.io/rb/rimless.svg)](https://badge.fury.io/rb/rimless)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/0d51996b52def6cf0262/maintainability)](https://codeclimate.com/repos/5cb06f700f7b09026e00a896/maintainability)
6
- [![Test Coverage](https://api.codeclimate.com/v1/badges/0d51996b52def6cf0262/test_coverage)](https://codeclimate.com/repos/5cb06f700f7b09026e00a896/test_coverage)
7
- [![API docs](https://img.shields.io/badge/docs-API-blue.svg)](https://www.rubydoc.info/gems/rimless)
5
+ [![Test Coverage](https://automate-api.hausgold.de/v1/coverage_reports/rimless/coverage.svg)](https://knowledge.hausgold.de/coverage)
6
+ [![Test Ratio](https://automate-api.hausgold.de/v1/coverage_reports/rimless/ratio.svg)](https://knowledge.hausgold.de/coverage)
7
+ [![API docs](https://automate-api.hausgold.de/v1/coverage_reports/rimless/documentation.svg)](https://www.rubydoc.info/gems/rimless)
8
8
 
9
9
  This project is dedicated to ship a ready to use [Apache
10
10
  Kafka](https://kafka.apache.org/) / [Confluent Schema
@@ -575,6 +575,13 @@ describe 'message producer job' do
575
575
  .with(key: user.id, topic: 'test.identity-api.users').twice
576
576
  .with_data(firstname: 'John', lastname: 'Doe').twice
577
577
  end
578
+
579
+ it 'allows to capture messages to check them in detail' do
580
+ (capture_kafka_messages { action }).tap do |messages|
581
+ expect(messages.first[:data]).to \
582
+ match(a_hash_including('entity' => a_hash_including('items' => items)))
583
+ end
584
+ end
578
585
  end
579
586
  ```
580
587
 
data/Rakefile CHANGED
@@ -54,12 +54,15 @@ end
54
54
 
55
55
  # Configure all code statistics directories
56
56
  vendors = [
57
+ [:unshift, 'Top-levels', 'lib', %r{lib(/rimless)?/[^/]+\.rb$}],
58
+ [:unshift, 'Top-levels specs', 'spec',
59
+ %r{spec/rimless(_spec\.rb|/[^/]+\.rb$)}],
60
+
57
61
  [:unshift, 'RSpec matchers', 'lib/rimless/rspec'],
58
62
  [:unshift, 'RSpec matchers specs', 'spec/rimless/rspec'],
59
63
 
60
- [:unshift, 'Top-levels', 'lib', %r{lib(/rimless)?/[^/]+\.rb$}],
61
- [:unshift, 'Top-levels specs', 'spec',
62
- %r{spec/rimless(_spec\.rb|/[^/]+\.rb$)}]
64
+ [:unshift, 'Rake Tasks', 'lib/rimless/tasks'],
65
+ [:unshift, 'Karafka Extensions', 'lib/rimless/karafka']
63
66
  ].reverse
64
67
 
65
68
  vendors.each do |method, type, dir, pattern|
@@ -38,6 +38,14 @@ module Rimless
38
38
  )
39
39
  end
40
40
  # rubocop:enable Metrics/MethodLength
41
+
42
+ # Capture all Apache Kafka messages of the given block.
43
+ #
44
+ # @yield the given block to capture the messages
45
+ # @return [Array<Hash{Symbol => Mixed}>] the captured messages
46
+ def capture_kafka_messages(&block)
47
+ Rimless::RSpec::Matchers::HaveSentKafkaMessage.new(nil).capture(&block)
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -23,6 +23,15 @@ module Rimless
23
23
  set_expected_number(:exactly, 1)
24
24
  end
25
25
 
26
+ # Capture all Apache Kafka messages of the given block.
27
+ #
28
+ # @yield the given block to capture the messages
29
+ # @return [Array<Hash{Symbol => Mixed}>] the captured messages
30
+ def capture(&block)
31
+ matches?(block)
32
+ @messages
33
+ end
34
+
26
35
  # Collect the expectation arguments for the Kafka message passing. (eg.
27
36
  # topic)
28
37
  #
@@ -173,7 +182,8 @@ module Rimless
173
182
  return true unless @schema
174
183
 
175
184
  begin
176
- Rimless.avro.decode(message[:data], schema_name: @schema.to_s)
185
+ Rimless.avro.decode(message[:encoded_data],
186
+ schema_name: @schema.to_s)
177
187
  return true
178
188
  rescue Avro::IO::SchemaMatchException
179
189
  false
@@ -199,24 +209,30 @@ module Rimless
199
209
  def data_match?(message)
200
210
  return true unless @data.any?
201
211
 
202
- actual_data = Rimless.avro.decode(message[:data])
203
- expected_data = @data.deep_stringify_keys
204
-
205
- actual_data.merge(expected_data) == actual_data
212
+ message[:data].merge(@data.deep_stringify_keys) == message[:data]
206
213
  end
207
214
 
208
215
  # Setup the +WaterDrop+ spies and record each sent message.
216
+ #
217
+ # rubocop:disable Metrics/AbcSize because of the message decoding
218
+ # rubocop:disable Metrics/MethodLength dito
209
219
  def listen_to_messages
220
+ decode = proc do |encoded|
221
+ { encoded_data: encoded, data: Rimless.avro.decode(encoded) }
222
+ end
223
+
210
224
  allow(WaterDrop::SyncProducer).to receive(:call) do |data, **args|
211
- @messages << { data: data, args: args, type: :sync }
225
+ @messages << { args: args, type: :sync }.merge(decode[data])
212
226
  nil
213
227
  end
214
228
 
215
229
  allow(WaterDrop::AsyncProducer).to receive(:call) do |data, **args|
216
- @messages << { data: data, args: args, type: :async }
230
+ @messages << { args: args, type: :async }.merge(decode[data])
217
231
  nil
218
232
  end
219
233
  end
234
+ # rubocop:enable Metrics/AbcSize
235
+ # rubocop:enable Metrics/MethodLength
220
236
 
221
237
  # Serve the RSpec API and return the positive failure message.
222
238
  #
@@ -264,7 +280,7 @@ module Rimless
264
280
  result = ['message']
265
281
 
266
282
  result << " with #{message[:args]}" if message[:args].any?
267
- result << " with data: #{Rimless.avro.decode(message[:data])}"
283
+ result << " with data: #{message[:data]}"
268
284
 
269
285
  result.join
270
286
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Rimless
4
4
  # The version of the +rimless+ gem
5
- VERSION = '1.1.1'
5
+ VERSION = '1.2.0'
6
6
  end
data/rimless.gemspec CHANGED
@@ -36,14 +36,14 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'appraisal'
37
37
  spec.add_development_dependency 'bundler', '>= 1.16', '< 3'
38
38
  spec.add_development_dependency 'factory_bot', '~> 4.11'
39
- spec.add_development_dependency 'railties', '>= 4.2.0'
39
+ spec.add_development_dependency 'railties', '>= 4.2.0', '< 6.1'
40
40
  spec.add_development_dependency 'rake', '~> 13.0'
41
41
  spec.add_development_dependency 'rdoc', '~> 6.1'
42
42
  spec.add_development_dependency 'redcarpet', '~> 3.4'
43
43
  spec.add_development_dependency 'rspec', '~> 3.0'
44
44
  spec.add_development_dependency 'rubocop', '~> 0.63.1'
45
45
  spec.add_development_dependency 'rubocop-rspec', '~> 1.31'
46
- spec.add_development_dependency 'simplecov', '~> 0.15'
46
+ spec.add_development_dependency 'simplecov', '< 0.18'
47
47
  spec.add_development_dependency 'timecop', '~> 0.9.1'
48
48
  spec.add_development_dependency 'vcr', '~> 3.0'
49
49
  spec.add_development_dependency 'yard', '~> 0.9.18'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rimless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hermann Mayer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-12 00:00:00.000000000 Z
11
+ date: 2021-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -191,6 +191,9 @@ dependencies:
191
191
  - - ">="
192
192
  - !ruby/object:Gem::Version
193
193
  version: 4.2.0
194
+ - - "<"
195
+ - !ruby/object:Gem::Version
196
+ version: '6.1'
194
197
  type: :development
195
198
  prerelease: false
196
199
  version_requirements: !ruby/object:Gem::Requirement
@@ -198,6 +201,9 @@ dependencies:
198
201
  - - ">="
199
202
  - !ruby/object:Gem::Version
200
203
  version: 4.2.0
204
+ - - "<"
205
+ - !ruby/object:Gem::Version
206
+ version: '6.1'
201
207
  - !ruby/object:Gem::Dependency
202
208
  name: rake
203
209
  requirement: !ruby/object:Gem::Requirement
@@ -286,16 +292,16 @@ dependencies:
286
292
  name: simplecov
287
293
  requirement: !ruby/object:Gem::Requirement
288
294
  requirements:
289
- - - "~>"
295
+ - - "<"
290
296
  - !ruby/object:Gem::Version
291
- version: '0.15'
297
+ version: '0.18'
292
298
  type: :development
293
299
  prerelease: false
294
300
  version_requirements: !ruby/object:Gem::Requirement
295
301
  requirements:
296
- - - "~>"
302
+ - - "<"
297
303
  - !ruby/object:Gem::Version
298
- version: '0.15'
304
+ version: '0.18'
299
305
  - !ruby/object:Gem::Dependency
300
306
  name: timecop
301
307
  requirement: !ruby/object:Gem::Requirement
@@ -360,11 +366,12 @@ extensions: []
360
366
  extra_rdoc_files: []
361
367
  files:
362
368
  - ".editorconfig"
369
+ - ".github/workflows/documentation.yml"
370
+ - ".github/workflows/test.yml"
363
371
  - ".gitignore"
364
372
  - ".rspec"
365
373
  - ".rubocop.yml"
366
374
  - ".simplecov"
367
- - ".travis.yml"
368
375
  - ".yardopts"
369
376
  - Appraisals
370
377
  - CHANGELOG.md
data/.travis.yml DELETED
@@ -1,35 +0,0 @@
1
- env:
2
- global:
3
- - CC_TEST_REPORTER_ID=f926dbf2ed89c7918e7a47f4f14f7d8386cc102d4cfa0a4e84051c6c976975ea
4
-
5
- sudo: false
6
- language: ruby
7
- cache: bundler
8
- rvm:
9
- - 2.7
10
- - 2.6
11
- - 2.5
12
-
13
- gemfile:
14
- - gemfiles/rails_4.2.gemfile
15
- - gemfiles/rails_5.0.gemfile
16
- - gemfiles/rails_5.1.gemfile
17
- - gemfiles/rails_5.2.gemfile
18
- - gemfiles/rails_6.0.gemfile
19
-
20
- before_install: gem install bundler
21
- install:
22
- # Rails 4 is not Ruby 2.7 compatible, so we skip this build
23
- - |
24
- [[ "${BUNDLE_GEMFILE}" =~ rails_4 && \
25
- "${TRAVIS_RUBY_VERSION}" =~ 2.7 ]] && exit || true
26
- # Regular build
27
- - bundle install --jobs=3 --retry=3
28
-
29
- before_script:
30
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
31
- - chmod +x ./cc-test-reporter
32
- - ./cc-test-reporter before-build
33
- script: bundle exec rake
34
- after_script:
35
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT