Skip to content

Commit 7cc7b3f

Browse files
committed
Onboard Rspec collection matcher and use exactly have, no have features in the test cases.
1 parent cf1c2e0 commit 7cc7b3f

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/log
1919

2020
## Developing
2121

22-
### 1. Plugin Developement and Testing
22+
### 1. Plugin Development and Testing
2323

2424
#### Code
2525
- To get started, you'll need JRuby with the Bundler gem installed.

logstash-output-elasticsearch.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
3333
s.add_development_dependency 'cabin', ['~> 0.6']
3434
s.add_development_dependency 'webrick'
3535
s.add_development_dependency 'webmock'
36+
s.add_development_dependency 'rspec-collection_matchers'
3637
# Still used in some specs, we should remove this ASAP
3738
s.add_development_dependency 'elasticsearch'
3839
end

spec/unit/outputs/elasticsearch_spec.rb

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
require "flores/random"
44
require 'concurrent/atomic/count_down_latch'
55
require "logstash/outputs/elasticsearch"
6-
76
require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper'
7+
require 'rspec/collection_matchers'
88

99
describe LogStash::Outputs::ElasticSearch do
1010
subject(:elasticsearch_output_instance) { described_class.new(options) }
@@ -394,10 +394,11 @@
394394
]}
395395
it "rejects unsupported actions" do
396396
event_result = subject.send(:safe_interpolation_map_events, events)
397-
expect(event_result.successful_events.size).to be == 3
397+
expect(event_result.successful_events).to have_exactly(3).items
398398
event_result.successful_events.each do |action, _|
399399
expect(action).to_not eql("unsupported_action")
400400
end
401+
expect(event_result.event_mapping_errors).to have_exactly(1).items
401402
event_result.event_mapping_errors.each do |event_mapping_error|
402403
expect(event_mapping_error.message).to eql("Elasticsearch doesn't support [unsupported_action] action")
403404
end
@@ -413,10 +414,11 @@
413414
]}
414415
it "rejects unsupported actions" do
415416
event_result = subject.send(:safe_interpolation_map_events, events)
416-
expect(event_result.successful_events.size).to be == 3
417+
expect(event_result.successful_events).to have_exactly(3).items
417418
event_result.successful_events.each do |action, _|
418419
expect(action).to_not eql("unsupported_action")
419420
end
421+
expect(event_result.event_mapping_errors).to have_exactly(1).items
420422
event_result.event_mapping_errors.each do |event_mapping_error|
421423
expect(event_mapping_error.message).to eql("Elasticsearch doesn't support [unsupported_action] action")
422424
end
@@ -432,10 +434,11 @@
432434
]}
433435
it "rejects unsupported actions" do
434436
event_result = subject.send(:safe_interpolation_map_events, events)
435-
expect(event_result.successful_events.size).to be == 0
437+
expect(event_result.successful_events).to have(:no).items
436438
event_result.successful_events.each do |action, _|
437439
expect(action).to_not eql("unsupported_action")
438440
end
441+
expect(event_result.event_mapping_errors).to have_exactly(4).items
439442
event_result.event_mapping_errors.each do |event_mapping_error|
440443
expect(event_mapping_error.message).to include "Elasticsearch doesn't support"
441444
end
@@ -451,8 +454,8 @@
451454
]}
452455
it "rejects unsupported actions" do
453456
event_result = subject.send(:safe_interpolation_map_events, events)
454-
expect(event_result.successful_events.size).to be == 2
455-
expect(event_result.event_mapping_errors.size).to be == 2
457+
expect(event_result.successful_events).to have_exactly(2).items
458+
expect(event_result.event_mapping_errors).to have_exactly(2).items
456459
event_result.event_mapping_errors.each do |event_mapping_error|
457460
expect(event_mapping_error.message).to include "Elasticsearch doesn't support"
458461
end
@@ -468,7 +471,8 @@
468471
]}
469472
it "rejects unsupported action" do
470473
event_result = subject.send(:safe_interpolation_map_events, events)
471-
expect(event_result.successful_events.size).to be == 3
474+
expect(event_result.successful_events).to have_exactly(3).items
475+
expect(event_result.event_mapping_errors).to have_exactly(1).items
472476
event_result.event_mapping_errors.each do |event_mapping_error|
473477
expect(event_mapping_error.message).to eql("Elasticsearch doesn't support [unsupported_action3] action")
474478
end

0 commit comments

Comments
 (0)