spec cleanup/overhaul
This commit is contained in:
parent
21cd1bb796
commit
41e9724c1a
1
Rakefile
1
Rakefile
|
@ -29,7 +29,6 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|||
spec.rcov = true
|
||||
end
|
||||
|
||||
|
||||
task :default => :spec
|
||||
|
||||
require 'rake/rdoctask'
|
||||
|
|
|
@ -3,33 +3,18 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
describe 'SimpleDB.batch_put_attributes' do
|
||||
|
||||
before(:all) do
|
||||
sdb.create_domain('batch_put_attributes')
|
||||
@domain_name = "fog_domain_#{Time.now.to_i}"
|
||||
sdb.create_domain(@domain_name)
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
sdb.delete_domain('batch_put_attributes')
|
||||
sdb.delete_domain(@domain_name)
|
||||
end
|
||||
|
||||
it 'should have no attributes for y before batch_put_attributes' do
|
||||
lambda { sdb.get_attributes('batch_put_attributes', 'a') }.should eventually { |expected| expected.body[:attributes].should be_empty }
|
||||
end
|
||||
|
||||
it 'should have no attributes for x before batch_put_attributes' do
|
||||
lambda { sdb.get_attributes('batch_put_attributes', 'x') }.should eventually { |expected| expected.body[:attributes].should be_empty }
|
||||
end
|
||||
|
||||
it 'should return proper attributes from batch_put_attributes' do
|
||||
actual = sdb.batch_put_attributes('batch_put_attributes', { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
|
||||
it 'should return proper attributes' do
|
||||
actual = sdb.batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
|
||||
actual.body[:request_id].should be_a(String)
|
||||
actual.body[:box_usage].should be_a(Float)
|
||||
end
|
||||
|
||||
it 'should have correct attributes for a after batch_put_attributes' do
|
||||
lambda { sdb.get_attributes('batch_put_attributes', 'a') }.should eventually { |expected| expected.body[:attributes].should == { 'b' => ['c'] } }
|
||||
end
|
||||
|
||||
it 'should have correct attributes for x after batch_put_attributes' do
|
||||
lambda { sdb.get_attributes('batch_put_attributes', 'x') }.should eventually { |expected| expected.body[:attributes].should == { 'y' => ['z'] } }
|
||||
end
|
||||
|
||||
end
|
|
@ -2,22 +2,18 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
|
||||
describe 'SimpleDB.create_domain' do
|
||||
|
||||
before(:all) do
|
||||
@domain_name = "fog_domain_#{Time.now.to_i}"
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
sdb.delete_domain('create_domain')
|
||||
sdb.delete_domain(@domain_name)
|
||||
end
|
||||
|
||||
it 'should not include create_domain in list_domains before create_domain' do
|
||||
lambda { sdb.list_domains }.should_not eventually { |expected| expected.body[:domains].should_not include('create_domain') }
|
||||
end
|
||||
|
||||
it 'should return proper attributes from create_domain' do
|
||||
actual = sdb.create_domain('create_domain')
|
||||
it 'should return proper attributes' do
|
||||
actual = sdb.create_domain(@domain_name)
|
||||
actual.body[:request_id].should be_a(String)
|
||||
actual.body[:box_usage].should be_a(Float)
|
||||
end
|
||||
|
||||
it 'should include create_domain in list_domains after create_domain' do
|
||||
lambda { sdb.list_domains }.should eventually { |expected| expected.body[:domains].should include('create_domain') }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,21 +3,17 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
describe 'SimpleDB.delete_domain' do
|
||||
|
||||
before(:all) do
|
||||
sdb.create_domain('delete_domain')
|
||||
@domain_name = "fog_domain_#{Time.now.to_i}"
|
||||
end
|
||||
|
||||
it 'should include delete_domain in list_domains before delete_domain' do
|
||||
lambda { sdb.list_domains }.should eventually { |expected| expected.body[:domains].should include('delete_domain') }
|
||||
before(:all) do
|
||||
sdb.create_domain(@domain_name)
|
||||
end
|
||||
|
||||
it 'should return proper attributes' do
|
||||
actual = sdb.delete_domain('delete_domain')
|
||||
actual = sdb.delete_domain(@domain_name)
|
||||
actual.body[:request_id].should be_a(String)
|
||||
actual.body[:box_usage].should be_a(Float)
|
||||
end
|
||||
|
||||
it 'should not include delete_domain in list_domains after delete_domain' do
|
||||
lambda { sdb.list_domains }.should_not eventually { |expected| expected.body[:domains].should_not include('delete_domain') }
|
||||
end
|
||||
|
||||
end
|
|
@ -3,15 +3,16 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
describe 'SimpleDB.domain_metadata' do
|
||||
|
||||
before(:all) do
|
||||
sdb.create_domain('domain_metadata')
|
||||
@domain_name = "fog_domain_#{Time.now.to_i}"
|
||||
sdb.create_domain(@domain_name)
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
sdb.delete_domain('domain_metadata')
|
||||
sdb.delete_domain(@domain_name)
|
||||
end
|
||||
|
||||
it 'should return proper attributes when there are no items' do
|
||||
results = sdb.domain_metadata('domain_metadata')
|
||||
results = sdb.domain_metadata(@domain_name)
|
||||
results.body[:attribute_name_count].should == 0
|
||||
results.body[:attribute_names_size_bytes].should == 0
|
||||
results.body[:attribute_value_count].should == 0
|
||||
|
@ -24,8 +25,8 @@ describe 'SimpleDB.domain_metadata' do
|
|||
end
|
||||
|
||||
it 'should return proper attributes with items' do
|
||||
sdb.put_attributes('domain_metadata', 'foo', { :bar => :baz })
|
||||
results = sdb.domain_metadata('domain_metadata')
|
||||
sdb.put_attributes(@domain_name, 'foo', { :bar => :baz })
|
||||
results = sdb.domain_metadata(@domain_name)
|
||||
results.body[:attribute_name_count].should == 1
|
||||
results.body[:attribute_names_size_bytes].should == 3
|
||||
results.body[:attribute_value_count].should == 1
|
||||
|
|
|
@ -3,20 +3,21 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
describe 'SimpleDB.get_attributes' do
|
||||
|
||||
before(:all) do
|
||||
sdb.create_domain('get_attributes')
|
||||
@domain_name = "fog_domain_#{Time.now.to_i}"
|
||||
sdb.create_domain(@domain_name)
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
sdb.delete_domain('get_attributes')
|
||||
sdb.delete_domain(@domain_name)
|
||||
end
|
||||
|
||||
it 'should have no attributes for foo before put_attributes' do
|
||||
lambda { sdb.get_attributes('get_attributes', 'foo') }.should eventually { |expected| expected.body[:attributes].should be_empty }
|
||||
lambda { sdb.get_attributes(@domain_name, 'foo') }.should eventually { |expected| expected.body[:attributes].should be_empty }
|
||||
end
|
||||
|
||||
it 'should have attributes for foo after put_attributes' do
|
||||
sdb.put_attributes('get_attributes', 'foo', { :bar => :baz })
|
||||
lambda { sdb.get_attributes('get_attributes', 'foo') }.should eventually { |expected| expected.body[:attributes].should == { 'bar' => ['baz'] } }
|
||||
sdb.put_attributes(@domain_name, 'foo', { :bar => :baz })
|
||||
lambda { sdb.get_attributes(@domain_name, 'foo') }.should eventually { |expected| expected.body[:attributes].should == { 'bar' => ['baz'] } }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,11 +3,11 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
describe 'SimpleDB.list_domains' do
|
||||
|
||||
before(:all) do
|
||||
sdb.create_domain('list_domains')
|
||||
@domain_name = "fog_domain_#{Time.now.to_i}"
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
sdb.delete_domain('list_domains')
|
||||
sdb.delete_domain(@domain_name)
|
||||
end
|
||||
|
||||
it 'should return proper attributes' do
|
||||
|
@ -17,8 +17,9 @@ describe 'SimpleDB.list_domains' do
|
|||
results.body[:request_id].should be_a(String)
|
||||
end
|
||||
|
||||
it 'should include list_domains in list_domains' do
|
||||
lambda { sdb.list_domains }.should eventually { |expected| expected.body[:domains].should include('list_domains') }
|
||||
it 'should include created domains' do
|
||||
sdb.create_domain(@domain_name)
|
||||
lambda { sdb.list_domains }.should eventually { |expected| expected.body[:domains].should include(@domain_name) }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,25 +3,18 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|||
describe 'SimpleDB.put_attributes' do
|
||||
|
||||
before(:all) do
|
||||
sdb.create_domain('put_attributes')
|
||||
@domain_name = "fog_domain_#{Time.now.to_i}"
|
||||
sdb.create_domain(@domain_name)
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
sdb.delete_domain('put_attributes')
|
||||
end
|
||||
|
||||
it 'should have no attributes for foo before put_attributes' do
|
||||
lambda { sdb.get_attributes('put_attributes', 'foo') }.should eventually { |expected| expected.body[:attributes].should be_empty }
|
||||
sdb.delete_domain(@domain_name)
|
||||
end
|
||||
|
||||
it 'should return proper attributes from put_attributes' do
|
||||
actual = sdb.put_attributes('put_attributes', 'foo', { 'bar' => 'baz' })
|
||||
actual = sdb.put_attributes(@domain_name, 'foo', { 'bar' => 'baz' })
|
||||
actual.body[:request_id].should be_a(String)
|
||||
actual.body[:box_usage].should be_a(Float)
|
||||
end
|
||||
|
||||
it 'should have attributes for foo after put_attributes' do
|
||||
lambda { sdb.get_attributes('put_attributes', 'foo') }.should eventually { |expected| expected.body[:attributes].should == { 'bar' => ['baz'] } }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
module Spec
|
||||
module Matchers
|
||||
class Eventually #:nodoc:
|
||||
def initialize(&block)
|
||||
@block = block
|
||||
end
|
||||
|
||||
def matches?(given_proc)
|
||||
match = nil
|
||||
[0,2,4,8,16].each do |delay|
|
||||
begin
|
||||
sleep(delay)
|
||||
match = @block[given_proc.call]
|
||||
break
|
||||
rescue Spec::Expectations::ExpectationNotMetError => error
|
||||
raise error if delay == 16
|
||||
end
|
||||
end
|
||||
match
|
||||
end
|
||||
end
|
||||
|
||||
# :call-seq
|
||||
# should eventually() { |expected| ... }
|
||||
# Matches if block matches within 30 seconds
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# lambda { do_something_eventually_returning_true }.should eventually {|expected| expected.should be_true }
|
||||
#
|
||||
# lambda { do_something_eventually_returning_false }.should_not eventually {|expected| expected.should_not be_true }
|
||||
def eventually(&block)
|
||||
Matchers::Eventually.new(&block)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
require 'spec'
|
||||
|
||||
require "#{File.dirname(__FILE__)}/../lib/fog"
|
||||
current_directory = File.dirname(__FILE__)
|
||||
require "#{current_directory}/../lib/fog"
|
||||
require "#{current_directory}/eventually.rb"
|
||||
|
||||
Spec::Runner.configure do |config|
|
||||
end
|
||||
|
@ -38,44 +40,6 @@ def s3
|
|||
end
|
||||
end
|
||||
|
||||
module Spec
|
||||
module Matchers
|
||||
class Eventually #:nodoc:
|
||||
def initialize(&block)
|
||||
@block = block
|
||||
end
|
||||
|
||||
def matches?(given_proc)
|
||||
match = nil
|
||||
[0,2,4,8,16].each do |delay|
|
||||
begin
|
||||
sleep(delay)
|
||||
match = @block[given_proc.call]
|
||||
break
|
||||
rescue Spec::Expectations::ExpectationNotMetError => error
|
||||
raise error if delay == 16
|
||||
end
|
||||
end
|
||||
match
|
||||
end
|
||||
end
|
||||
|
||||
# :call-seq
|
||||
# should eventually() { |expected| ... }
|
||||
# Matches if block matches within 30 seconds
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# lambda { do_something_eventually_returning_true }.should eventually {|expected| expected.should be_true }
|
||||
#
|
||||
# lambda { do_something_eventually_returning_false }.should_not eventually {|expected| expected.should_not be_true }
|
||||
def eventually(&block)
|
||||
Matchers::Eventually.new(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Eventually
|
||||
def initialize(result, delay)
|
||||
@result = result
|
||||
|
|
Loading…
Reference in New Issue