mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
dryer and more reusable tests for collection/model
This commit is contained in:
parent
68295a56d9
commit
71915f6174
7 changed files with 93 additions and 117 deletions
|
@ -8,6 +8,9 @@ $LOAD_PATH.unshift __DIR__ unless
|
|||
$LOAD_PATH.include?(__DIR__) ||
|
||||
$LOAD_PATH.include?(File.expand_path(__DIR__))
|
||||
|
||||
require 'tests/helpers/collection_tests'
|
||||
require 'tests/helpers/model_tests'
|
||||
|
||||
require 'tests/helpers/storage/directory_tests'
|
||||
require 'tests/helpers/storage/directories_tests'
|
||||
require 'tests/helpers/storage/file_tests'
|
||||
|
|
47
tests/helpers/collection_tests.rb
Normal file
47
tests/helpers/collection_tests.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
def collection_tests(collection, params, mocks_implemented = true)
|
||||
|
||||
tests('success') do
|
||||
|
||||
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
|
||||
|
||||
tests("#all").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
collection.all
|
||||
end
|
||||
|
||||
@identity = @instance.identity
|
||||
|
||||
tests("#get(#{@identity})").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
collection.get(@identity)
|
||||
end
|
||||
|
||||
if block_given?
|
||||
yield
|
||||
end
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@instance.destroy
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
@identity = @identity.gsub(/\w/, '0')
|
||||
|
||||
tests("#get('#{@identity}')").returns(nil) do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
collection.get(@identity)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
28
tests/helpers/model_tests.rb
Normal file
28
tests/helpers/model_tests.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
def model_tests(collection, params, mocks_implemented = true)
|
||||
|
||||
tests('success') do
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@instance = collection.new(params)
|
||||
end
|
||||
|
||||
tests("#save").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@instance.save
|
||||
end
|
||||
|
||||
if block_given?
|
||||
yield
|
||||
end
|
||||
|
||||
tests("#destroy").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@instance.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
end
|
||||
|
||||
end
|
|
@ -1,39 +1,5 @@
|
|||
def directories_tests(connection, mocks_implemented = true)
|
||||
def directories_tests(connection, params = {:key => 'fogdirectoriestests'}, mocks_implemented = true)
|
||||
|
||||
tests('success') do
|
||||
collection_tests(connection.directories, params, mocks_implemented)
|
||||
|
||||
tests("#new(:key => 'fogdirectoriestests')").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@directory = connection.directories.new(:key => 'fogdirectoriestests')
|
||||
end
|
||||
|
||||
tests("#create(:key => 'fogdirectoriestests')").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@directory = connection.directories.create(:key => 'fogdirectoriestests')
|
||||
end
|
||||
|
||||
tests("#all").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
connection.directories.all
|
||||
end
|
||||
|
||||
tests("#get('fogdirectoriestests')").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
connection.directories.get('fogdirectoriestests')
|
||||
end
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@directory.destroy
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get('fognondirectory')").returns(nil) do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
connection.directories.get('fognondirectory')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,32 +1,15 @@
|
|||
def directory_tests(connection, mocks_implemented = true)
|
||||
def directory_tests(connection, params = {:key => 'fogdirectorytests'}, mocks_implemented = true)
|
||||
|
||||
tests('success') do
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@directory = connection.directories.new(:key => 'fogdirectorytests')
|
||||
end
|
||||
|
||||
tests("#save").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@directory.save
|
||||
end
|
||||
|
||||
tests("#destroy").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@directory.destroy
|
||||
end
|
||||
model_tests(connection.directories, params, mocks_implemented) do
|
||||
|
||||
tests("#public=(true)").succeeds do
|
||||
@directory.public=(true)
|
||||
@instance.public=(true)
|
||||
end
|
||||
|
||||
tests("#respond_to?(:public_url)").succeeds do
|
||||
@directory.respond_to?(:public_url)
|
||||
@instance.respond_to?(:public_url)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,36 +1,19 @@
|
|||
def file_tests(connection, mocks_implemented = true)
|
||||
def file_tests(connection, params = {:key => 'fog_file_tests', :body => lorem_file}, mocks_implemented = true)
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@directory = connection.directories.create(:key => 'fogfilestests')
|
||||
end
|
||||
|
||||
tests('success') do
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@file = @directory.files.new(:key => 'fog_file_tests', :body => lorem_file)
|
||||
end
|
||||
|
||||
tests("#save").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@file.save
|
||||
end
|
||||
|
||||
tests("#destroy").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@file.destroy
|
||||
end
|
||||
model_tests(@directory.files, params, mocks_implemented) do
|
||||
|
||||
tests("#respond_to?(:public_url)").succeeds do
|
||||
@directory.respond_to?(:public_url)
|
||||
@instance.respond_to?(:public_url)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
end
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@directory.destroy
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,47 +1,13 @@
|
|||
def files_tests(connection, mocks_implemented = true)
|
||||
def files_tests(connection, params = {:key => 'fog_files_tests', :body => lorem_file}, mocks_implemented = true)
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@directory = connection.directories.create(:key => 'fogfilestests')
|
||||
end
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#new(:key => 'fog_files_tests', :body => lorem_file)").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@directory.files.new(:key => 'fog_files_tests', :body => lorem_file)
|
||||
end
|
||||
|
||||
tests("#create(:key => 'fog_files_tests', :body => lorem_file)").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@file = @directory.files.create(:key => 'fog_files_tests', :body => lorem_file)
|
||||
end
|
||||
|
||||
tests("#all").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@directory.files.all
|
||||
end
|
||||
|
||||
tests("#get('fog_files_tests')").succeeds do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@directory.files.get('fog_files_tests')
|
||||
end
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@file.destroy
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
||||
tests("#get('fog_non_file')").returns(nil) do
|
||||
pending if Fog.mocking? && !mocks_implemented
|
||||
@directory.files.get('fog_non_file')
|
||||
end
|
||||
|
||||
end
|
||||
collection_tests(@directory.files, params, mocks_implemented)
|
||||
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@directory.destroy
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue