Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly committed May 22, 2009
1 parent 6b9e6b0 commit 419466a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 15 deletions.
42 changes: 42 additions & 0 deletions .autotest
@@ -0,0 +1,42 @@
require 'autotest'

Autotest.add_hook :initialize do |at|
at.clear_mappings
at.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
at.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m

at.add_mapping(%r%^examples/.*_example.rb$%) { |filename, _|
filename
}

at.add_mapping(%r%^lib/(.*)\.rb$%) { |filename, m|
["examples/lib/#{m[1]}_example.rb"]
}

at.add_mapping(%r%^examples/(example_helper|shared/.*)\.rb$%) {
at.files_matching %r%^examples/.*_example\.rb$%
}
end

class MicronautCommandError < StandardError; end

class Autotest::Micronaut < Autotest
#remove_method :consolidate_failures, :make_test_cmd
#remove_method :make_test_cmd

def consolidate_failures(failed)
filters = new_hash_of_arrays
failed.each do |spec, trace|
if trace =~ /\n(\.\/)?(.*example\.rb):[\d]+:\Z?/
filters[$2] << spec
end
end
return filters
end

def make_test_cmd(files_to_test)
return '' if files_to_test.size == 0
"bin/micronaut #{files_to_test.keys.sort.join(' ')}"
end

end
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -28,7 +28,7 @@ end

Micronaut::RakeTask.new(:rcov) do |examples|
examples.pattern = 'examples/**/*_example.rb'
examples.rcov_opts = '-Ilib -Iexamples'
examples.rcov_opts = '-Ilib -Iexamples -iastrails -x\/gems\/'
examples.rcov = true
end

Expand Down
24 changes: 23 additions & 1 deletion examples/unit/local_example.rb
Expand Up @@ -5,6 +5,9 @@ def def_config
{
:local => {
:path => "/:kind~:id~:timestamp"
},
:keep => {
:local => 2
}
}
end
Expand Down Expand Up @@ -77,6 +80,25 @@ def local(config = def_config, backup = def_backup)
end

describe :cleanup do
it "should have test"
before(:each) do
@local = local
@files = [4,1,3,2].to_a.map { |i| "aaaaa#{i}" }
stub(Dir).[](anything) {@files}
stub(File).file?(anything) {true}
stub(File).size(anything) {1}
stub(File).unlink
end

it "should check [:keep, :local]" do
@local.config[:keep][:local] = nil
dont_allow(Dir).[]
@local.send :cleanup
end

it "should delete extra files" do
mock(File).unlink("aaaaa1")
mock(File).unlink("aaaaa2")
@local.send :cleanup
end
end
end
54 changes: 42 additions & 12 deletions examples/unit/s3_example.rb
Expand Up @@ -8,7 +8,6 @@ def def_config
:bucket => "_bucket",
:key => "_key",
:secret => "_secret",
:path => "s3_path"
},
:keep => {
:s3 => 2
Expand Down Expand Up @@ -40,12 +39,12 @@ def s3(config = def_config, backup = def_backup)

@files = [4,1,3,2].to_a.map { |i| stub(o = {}).key {"aaaaa#{i}"}; o }

stub(AWS::S3::Bucket).objects("_bucket", :prefix => "s3_path/_kind-_id", :max_keys => 4) {@files}
stub(AWS::S3::Bucket).objects("_bucket", :prefix => "_kind/_id/_kind-_id", :max_keys => 4) {@files}
stub(AWS::S3::Bucket).find("_bucket").stub![anything].stub!.delete
end

it "should check [:keep, :s3]" do
mock(@s3.config).[](:keep, :s3) {nil}
@s3.config[:keep][:s3] = nil
dont_allow(@s3.backup).filename
@s3.send :cleanup
end
Expand All @@ -56,21 +55,52 @@ def s3(config = def_config, backup = def_backup)
@s3.send :cleanup
end

it "should have more tests"

end

describe :active do
it "should be true when all params are set"
it "should be false if bucket is missing"
it "should be false if key is missing"
it "should be false if secret is missing"
before(:each) do
@s3 = s3
end

it "should be true when all params are set" do
@s3.should be_active
end

it "should be false if bucket is missing" do
@s3.config[:s3][:bucket] = nil
@s3.should_not be_active
end

it "should be false if key is missing" do
@s3.config[:s3][:key] = nil
@s3.should_not be_active
end

it "should be false if secret is missing" do
@s3.config[:s3][:secret] = nil
@s3.should_not be_active
end
end

describe :prefix do
it "should use s3/path 1st"
it "should use local/path 2nd"
it "should use constant 3rd"
before(:each) do
@s3 = s3
end
it "should use s3/path 1st" do
@s3.config[:s3][:path] = "s3_path"
@s3.config[:local] = {:path => "local_path"}
@s3.send(:prefix).should == "s3_path"
end

it "should use local/path 2nd" do
@s3.config[:local] = {:path => "local_path"}
@s3.send(:prefix).should == "local_path"
end

it "should use constant 3rd" do
@s3.send(:prefix).should == "_kind/_id"
end

end

describe :save do
Expand Down
2 changes: 1 addition & 1 deletion lib/astrails/safe/s3.rb
Expand Up @@ -35,7 +35,7 @@ def cleanup

base = File.basename(@backup.filename).split(".").first

puts "listing files in #{bucket}:#{prefix}/#{base}"
puts "listing files in #{bucket}:#{prefix}/#{base}" if $_VERBOSE
files = AWS::S3::Bucket.objects(bucket, :prefix => "#{prefix}/#{base}", :max_keys => keep * 2)
puts files.collect {|x| x.key} if $_VERBOSE

Expand Down

0 comments on commit 419466a

Please sign in to comment.