spec/spec_helper.rb in cloudinary-1.1.1 vs spec/spec_helper.rb in cloudinary-1.1.2
- old
+ new
@@ -13,10 +13,16 @@
end
config.run_all_when_everything_filtered = true
config.filter_run_excluding :delete_all => true
end
+RSpec.shared_context "cleanup" do
+ after :all do
+ Cloudinary::Api.delete_resources_by_tag(TEST_TAG) unless Cloudinary.config.keep_test_products
+ end
+
+end
# Create a regexp with the given +tag+ name.
def html_tag_matcher( tag)
/<#{tag}([\s]+([-[:word:]]+)[\s]*\=\s*\"([^\"]*)\")*\s*>.*<\s*\/#{tag}\s*>/
end
@@ -138,5 +144,22 @@
end
end
end
+def deep_fetch(hash, path)
+ Array(path).reduce(hash) { |h, key| h && h.fetch(key, nil) }
+end
+
+# Matches deep values in the actual Hash, disregarding other keys and values.
+# @example
+# expect( {:foo => { :bar => 'foobar'}}).to have_deep_hash_values_of( [:foo, :bar] => 'foobar')
+# expect( foo_instance).to receive(:bar_method).with(deep_hash_values_of([:foo, :bar] => 'foobar'))
+RSpec::Matchers.define :deep_hash_value do |expected|
+ match do |actual|
+ expected.all? do |path, value|
+ values_match? deep_fetch(actual, path), value
+ end
+ end
+end
+
+RSpec::Matchers.alias_matcher :have_deep_hash_values_of, :deep_hash_value
\ No newline at end of file