Skip to content

Commit

Permalink
rspec: be_subset_of custom matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Dec 18, 2018
1 parent 6eb1e82 commit 64d1af8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
15 changes: 15 additions & 0 deletions spec/custom_matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rspec/expectations'

RSpec::Matchers.define :be_subset_of do |superset|
match do |subset|
subset.all? do |subset_elem|
superset.find do |super_set_elem|
ThreeScaleToolbox::Helper.compare_hashes(subset_elem, super_set_elem, @keys)
end
end
end

chain :comparing_keys do |keys|
@keys = keys
end
end
19 changes: 4 additions & 15 deletions spec/integration/import_openapi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
let(:external_methods) do
{
'methods' => [
{ 'method' => { 'id' => '0', 'friendly_name' => 'old_method', 'system_name' => 'old_method' } },
{ 'method' => { 'id' => '1', 'friendly_name' => 'addPet', 'system_name' => 'addpet' } },
{ 'method' => { 'id' => '2', 'friendly_name' => 'updatePet', 'system_name' => 'updatepet' } },
{ 'method' => { 'id' => '3', 'friendly_name' => 'findPetsByStatus', 'system_name' => 'findpetsbystatus' } }
Expand Down Expand Up @@ -108,11 +109,7 @@
expect(expected_methods.size).to be > 0
# test Set(service.methods) includes Set(expected_methods)
# with a custom identity method for methods
expect(
ThreeScaleToolbox::Helper.array_difference(expected_methods, service.methods) do |el1, el2|
ThreeScaleToolbox::Helper.compare_hashes(el1, el2, method_keys)
end
).to be_empty
expect(expected_methods).to be_subset_of(service.methods).comparing_keys(method_keys)
end

it 'mapping rules are created' do
Expand All @@ -121,16 +118,8 @@
expect(expected_mapping_rules.size).to be > 0
# expect Set(service.mapping_rules) == Set(expected_mapping_rules)
# with a custom identity method for mapping_rules
expect(
ThreeScaleToolbox::Helper.array_difference(expected_mapping_rules, service.mapping_rules) do |el1, el2|
ThreeScaleToolbox::Helper.compare_hashes(el1, el2, mapping_rule_keys)
end
).to be_empty
expect(
ThreeScaleToolbox::Helper.array_difference(service.mapping_rules, expected_mapping_rules) do |el1, el2|
ThreeScaleToolbox::Helper.compare_hashes(el1, el2, mapping_rule_keys)
end
).to be_empty
expect(expected_mapping_rules).to be_subset_of(service.mapping_rules).comparing_keys(mapping_rule_keys)
expect(service.mapping_rules).to be_subset_of(expected_mapping_rules).comparing_keys(mapping_rule_keys)
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'webmock/rspec'
WebMock.disable_net_connect!
require_relative 'shared_contexts'
require_relative 'custom_matchers'

# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
Expand Down

0 comments on commit 64d1af8

Please sign in to comment.