diff --git a/Gemfile b/Gemfile index d1e1dd3..45ab5d2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,6 @@ source "https://rubygems.org" +gem "utensils", github: "cookpad/utensils" + # Specify your gem's dependencies in streamy.gemspec gemspec diff --git a/lib/streamy/helpers/have_hash_matcher.rb b/lib/streamy/helpers/have_hash_matcher.rb deleted file mode 100644 index d09e59a..0000000 --- a/lib/streamy/helpers/have_hash_matcher.rb +++ /dev/null @@ -1,55 +0,0 @@ -RSpec::Matchers.define :have_hash do |expected| - match do |array| - synchronize do - hash = find_hash(array, expected) - - expect(hash).to include(expected) - expect(hash).to_not include(@unexpected_keys) - end - end - - chain :without do |*unexpected_keys| - @unexpected_keys = unexpected_keys - end - - failure_message do - @failure_message - end - - private - - def find_hash(array, expected) - hash = array.reverse.find do |item| - find_with_inclusion(item, expected) - end - - hash || better_diff(array) - end - - def find_with_inclusion(hash, expected) - expect(hash).to include(expected) - rescue RSpec::Expectations::ExpectationNotMetError - end - - def better_diff(array) - return array if array.size > 1 - - array.first - end - - # mimicking has_text/css? matchers, https://git.io/vMSo9 - def synchronize(&block) - start_time = Time.current - - begin - yield - rescue ::RSpec::Expectations::ExpectationNotMetError => e - @failure_message = e.message - raise(e) unless Capybara.current_driver == Capybara.javascript_driver - - return false if (Time.current - start_time) >= Capybara.default_max_wait_time - sleep 0.05 - retry - end - end -end diff --git a/lib/streamy/helpers/rspec_helper.rb b/lib/streamy/helpers/rspec_helper.rb index 39b8df0..4b43617 100644 --- a/lib/streamy/helpers/rspec_helper.rb +++ b/lib/streamy/helpers/rspec_helper.rb @@ -1,4 +1,4 @@ -require "streamy/helpers/have_hash_matcher" +require "utensils/have_hash_matcher" require "streamy/test_dispatcher" module Streamy diff --git a/streamy.gemspec b/streamy.gemspec index 2e5fc17..dd7bff7 100644 --- a/streamy.gemspec +++ b/streamy.gemspec @@ -40,6 +40,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength spec.add_development_dependency "rake", ">= 12.3.3" spec.add_development_dependency "rspec" spec.add_development_dependency "sinatra" + spec.add_development_dependency "utensils" spec.add_dependency "activesupport", ">= 5.2" spec.add_dependency "avro_turf", "~> 1.3.0"