1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/tests/helpers/collection_helper.rb

92 lines
2.3 KiB
Ruby
Raw Normal View History

def collection_tests(collection, params = {}, mocks_implemented = true)
tests('success') do
2014-08-06 20:58:55 -04:00
tests("#new(#{params.inspect})").succeeds do
pending if Fog.mocking? && !mocks_implemented
collection.new(params)
end
tests("#create(#{params.inspect})").succeeds do
pending if Fog.mocking? && !mocks_implemented
@instance = collection.create(params)
end
2011-09-23 17:53:01 -04:00
# FIXME: work around for timing issue on AWS describe_instances mocks
2014-08-06 20:58:55 -04:00
2011-09-23 17:53:01 -04:00
if Fog.mocking? && @instance.respond_to?(:ready?)
@instance.wait_for { ready? }
end
2014-08-06 20:58:55 -04:00
tests("#all").succeeds do
pending if Fog.mocking? && !mocks_implemented
collection.all
end
2014-08-06 20:58:55 -04:00
2010-11-16 16:24:43 -05:00
if !Fog.mocking? || mocks_implemented
@identity = @instance.identity
end
2014-08-06 20:58:55 -04:00
tests("#get(#{@identity})").succeeds do
pending if Fog.mocking? && !mocks_implemented
collection.get(@identity)
end
2014-08-06 20:58:55 -04:00
tests('Enumerable') do
pending if Fog.mocking? && !mocks_implemented
methods = [
'all?', 'any?', 'find', 'detect', 'collect', 'map',
'find_index', 'flat_map', 'collect_concat', 'group_by',
'none?', 'one?'
]
methods.each do |enum_method|
if collection.respond_to?(enum_method)
tests("##{enum_method}").succeeds do
block_called = false
collection.send(enum_method) {|x| block_called = true }
block_called
end
end
end
[
'max_by','min_by'
].each do |enum_method|
if collection.respond_to?(enum_method)
tests("##{enum_method}").succeeds do
block_called = false
collection.send(enum_method) {|x| block_called = true; 0 }
block_called
end
end
end
end
if block_given?
yield(@instance)
end
if !Fog.mocking? || mocks_implemented
@instance.destroy
end
end
tests('failure') do
2010-11-16 16:24:43 -05:00
if !Fog.mocking? || mocks_implemented
@identity = @identity.to_s
@identity = @identity.gsub(/[a-zA-Z]/) { Fog::Mock.random_letters(1) }
@identity = @identity.gsub(/\d/) { Fog::Mock.random_numbers(1) }
@identity
2010-11-16 16:24:43 -05:00
end
tests("#get('#{@identity}')").returns(nil) do
pending if Fog.mocking? && !mocks_implemented
collection.get(@identity)
end
end
end