From 81925b2a9f482c5bc3a36b340ed69057405683cd Mon Sep 17 00:00:00 2001 From: Sameer Siruguri Date: Fri, 18 Dec 2015 12:36:36 -0800 Subject: [PATCH] Bump gems to latest * Use RSpec 2.0 syntax and remove `.should` * Use AWS-SDK v2 * Correct usage of `CommandParser` for latest version --- .travis.yml | 5 ++++ Gemfile.lock | 59 ++++++++++++++++++++------------------- lib/s3sync/cli.rb | 52 +++++++++++++++------------------- s3sync.gemspec | 5 ++-- spec/cli_spec.rb | 2 +- spec/local_source_spec.rb | 4 +-- spec/main_spec.rb | 54 +++++++++++++++++------------------ spec/spec_helper.rb | 4 +-- 8 files changed, 94 insertions(+), 91 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3398a11..439a53b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,7 @@ language: ruby +before_install: gem install bundler script: bundle exec rspec +rvm: + - 2.0.0 + - 2.1.0 + - 2.2.0 diff --git a/Gemfile.lock b/Gemfile.lock index 04d3478..94d41f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,40 +2,43 @@ PATH remote: . specs: s3sync (2.0.2) - aws-sdk - cmdparse + aws-sdk (< 2.2) + cmdparse (~> 3.0) GEM remote: https://rubygems.org/ specs: - aws-sdk (1.31.3) - json (~> 1.4) - nokogiri (>= 1.4.4) - uuidtools (~> 2.1) - bump (0.5.0) - cmdparse (2.0.5) + aws-sdk (2.1.36) + aws-sdk-resources (= 2.1.36) + aws-sdk-core (2.1.36) + jmespath (~> 1.0) + aws-sdk-resources (2.1.36) + aws-sdk-core (= 2.1.36) + bump (0.5.3) + cmdparse (3.0.1) diff-lcs (1.2.5) - docile (1.1.1) - json (1.8.1) - mini_portile (0.5.2) - multi_json (1.8.2) - nokogiri (1.6.1) - mini_portile (~> 0.5.0) - rake (10.1.1) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.7) - rspec-expectations (2.14.4) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.4) - simplecov (0.8.2) + docile (1.1.5) + jmespath (1.1.3) + json (1.8.3) + rake (10.4.2) + rspec (3.4.0) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-core (3.4.1) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) + simplecov (0.11.1) docile (~> 1.1.0) - multi_json - simplecov-html (~> 0.8.0) - simplecov-html (0.8.0) - uuidtools (2.1.4) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) PLATFORMS ruby diff --git a/lib/s3sync/cli.rb b/lib/s3sync/cli.rb index 31a02b3..243d402 100644 --- a/lib/s3sync/cli.rb +++ b/lib/s3sync/cli.rb @@ -25,7 +25,7 @@ require 's3sync/version' require 's3sync/exceptions' require 's3sync/sync' -require 'aws/s3' +require 'aws-sdk' require 'cmdparse' @@ -63,9 +63,9 @@ def usage u.join '' end - def execute(args) + def execute(*args) # Connecting to amazon - s3 = AWS::S3.new + s3 = AWS::S3::Client.new # From the command line key, file = args @@ -101,7 +101,7 @@ def parse_acl(opt) class ListBuckets < BaseCmd def initialize - super 'listbuckets', false, false, false + super 'listbuckets', takes_commands: false #, false, false @short_desc = "List all available buckets for your user" end @@ -117,11 +117,11 @@ class CreateBucket < BaseCmd attr_accessor :acl def initialize - super 'createbucket', false, false + super 'createbucket', takes_commands: false #, false @short_desc = "Create a new bucket under your user account" - self.options = CmdParse::OptionParserWrapper.new do |opt| + self.options do |opt| parse_acl(opt) end end @@ -147,13 +147,13 @@ class DeleteBucket < BaseCmd attr_accessor :force def initialize - super 'deletebucket', false, false + super 'deletebucket', takes_commands: false #, false @short_desc = "Remove a bucket from your account" @force = false - self.options = CmdParse::OptionParserWrapper.new do |opt| + self.options do |opt| opt.on("-f", "--force", "Clean the bucket then deletes it") {|f| @force = f } @@ -179,7 +179,7 @@ class List < BaseCmd attr_accessor :max_entries def initialize - super 'list', false, false + super 'list', takes_commands: false #, false @short_desc = "List items filed under a given bucket" @@ -189,7 +189,7 @@ def initialize @has_prefix = true - self.options = CmdParse::OptionParserWrapper.new do |opt| + self.options do |opt| opt.on("-m", "--max-entries=NUM", "Limit the number of entries to output") {|m| @max_entries = m } @@ -223,7 +223,7 @@ def run s3, bucket, key, file, args class Delete < BaseCmd def initialize - super 'delete', false, false + super 'delete', takes_commands: false #, false @short_desc = "Delete a key from a bucket" @@ -242,7 +242,7 @@ class Url < BaseCmd attr_accessor :secure def initialize - super 'url', false, false + super 'url', takes_commands: false #, false @short_desc = "Generates public urls or authenticated endpoints for the object" @description = "Notice that --method and --public are mutually exclusive" @@ -252,7 +252,7 @@ def initialize @expires_in = false @has_prefix = 'required' - self.options = CmdParse::OptionParserWrapper.new do |opt| + self.options do |opt| opt.on("-m", "--method=METHOD", "Options: #{AVAILABLE_METHODS.join ', '}") {|m| @method = m } @@ -305,7 +305,7 @@ def run s3, bucket, key, file, args class Put < BaseCmd def initialize - super 'put', false, false + super 'put', takes_commands: false #, false @short_desc = 'Upload a file to a bucket under a certain prefix' @has_prefix = true @@ -326,7 +326,7 @@ def run s3, bucket, key, file, args class Get < BaseCmd def initialize - super 'get', false, false + super 'get', takes_commands: false #, false @short_desc = "Retrieve an object and save to the specified file" @has_prefix = 'required' end @@ -359,7 +359,7 @@ class Sync < BaseCmd attr_accessor :acl def initialize - super 'sync', false, false + super 'sync', takes_commands: false #, false @short_desc = "Synchronize an S3 and a local folder" @s3 = nil @@ -368,7 +368,7 @@ def initialize @dry_run = false @verbose = false - self.options = CmdParse::OptionParserWrapper.new do |opt| + self.options do |opt| opt.on("-x EXPR", "--exclude=EXPR", "Skip copying files that matches this pattern. (Ruby REs)") {|v| @exclude = v } @@ -425,22 +425,16 @@ def run s3, bucket, key, file, args end def run conf - cmd = CmdParse::CommandParser.new true - cmd.program_name = File.basename $0 - cmd.program_version = S3Sync::VERSION + cmd = CmdParse::CommandParser.new handle_exceptions: true + cmd.main_options do |opt| + opt.program_name = File.basename $0 + opt.version = S3Sync::VERSION + end - cmd.options = CmdParse::OptionParserWrapper.new do |opt| + cmd.global_options do |opt| opt.separator "Global options:" end - cmd.main_command.short_desc = 'Tool belt for managing your S3 buckets' - cmd.main_command.description =< 2.0" + spec.add_dependency "aws-sdk", "< 2.2" + spec.add_dependency "cmdparse", "~> 3.0" # Development requirements spec.add_development_dependency "simplecov" diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 170a326..21bd95c 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -17,7 +17,7 @@ expect { # When I execute it with a mocked s3 instance command.run(s3, nil, nil, nil, nil) - }.to match_stdout('b1\nb2\n') + }.to output("b1\nb2\n").to_stdout end it "Should be able to create buckets" do diff --git a/spec/local_source_spec.rb b/spec/local_source_spec.rb index 0b08361..c6a33aa 100644 --- a/spec/local_source_spec.rb +++ b/spec/local_source_spec.rb @@ -19,7 +19,7 @@ # Then I see that the directory nodes contain both their parent paths and # their names - local.list_files.should be_eql({ + expect(local.list_files).to eql({ "file1.txt" => Node.new(fixture("directory2"), "file1.txt", 10), "file2.txt" => Node.new(fixture("directory2"), "file2.txt", 11), }) @@ -42,7 +42,7 @@ # Then I see that the directory nodes contain both their parent paths and # their names - local.list_files.should be_eql({ + expect(local.list_files).to eql({ "file1.txt" => Node.new(fixture("directory2"), "file1.txt", 10), "file2.txt" => Node.new(fixture("directory2"), "file2.txt", 11), "subd/sub1.txt" => Node.new(fixture("directory2"), "subd/sub1.txt", 11), diff --git a/spec/main_spec.rb b/spec/main_spec.rb index 5492cb6..0441dea 100644 --- a/spec/main_spec.rb +++ b/spec/main_spec.rb @@ -14,7 +14,7 @@ destination = "mybucket:pre" # This will yield S3 keys named pre/etc/... - SyncCommand.process_destination(source, destination).should be_eql ["/etc", ["pre/etc/", "mybucket"]] + expect(SyncCommand.process_destination(source, destination)).to eql(["/etc", ["pre/etc/", "mybucket"]]) end it "Put the contents of the local /etc dir into S3, rename dir" do @@ -22,7 +22,7 @@ destination = "mybucket:pre/etcbackup" # This will yield S3 keys named pre/etcbackup/... - SyncCommand.process_destination(source, destination).should be_eql ["/etc/", ["pre/etcbackup/", "mybucket"]] + expect(SyncCommand.process_destination(source, destination)).to eql(["/etc/", ["pre/etcbackup/", "mybucket"]]) end it "Put the contents of the local /tmp/sync/ in to the root of an S3 bucket" do @@ -30,7 +30,7 @@ destination = "mybucket:" # This will yield S3 keys named '...' (The root is just empty) - SyncCommand.process_destination(source, destination).should be_eql ["/tmp/sync/", ["", "mybucket"]] + expect(SyncCommand.process_destination(source, destination)).to eql(["/tmp/sync/", ["", "mybucket"]]) end it "Put contents of S3 \"directory\" etc into local dir" do @@ -38,7 +38,7 @@ destination = "/root/etcrestore" # This will yield local files at /root/etcrestore/... - SyncCommand.process_destination(source, destination).should be_eql [["pre/etc/", "mybucket"], "/root/etcrestore/"] + expect(SyncCommand.process_destination(source, destination)).to eql([["pre/etc/", "mybucket"], "/root/etcrestore/"]) end it "Put the contents of S3 \"directory\" etc into a local dir named etc" do @@ -46,7 +46,7 @@ destination = "/root" # This will yield local files at /root/etc/... - SyncCommand.process_destination(source, destination).should be_eql [["pre/etc", "mybucket"], "/root/etc/"] + expect(SyncCommand.process_destination(source, destination)).to eql([["pre/etc", "mybucket"], "/root/etc/"]) end it "Put S3 nodes under the key pre/etc/ to the local dir etcrestore" do @@ -54,7 +54,7 @@ destination = "/root/etcrestore" # This will yield local files at /root/etcrestore/... - SyncCommand.process_destination(source, destination).should be_eql [["pre/etc/", "mybucket"], "/root/etcrestore/"] + expect(SyncCommand.process_destination(source, destination)).to eql([["pre/etc/", "mybucket"], "/root/etcrestore/"]) end it "Put S3 nodes under an empty key (root) to the local dir /tmp/lib" do @@ -62,7 +62,7 @@ destination = "/tmp/lib" # This will yield local files at /root/etcrestore/... - SyncCommand.process_destination(source, destination).should be_eql [["", "mybucket"], "/tmp/lib/"] + expect(SyncCommand.process_destination(source, destination)).to eql([["", "mybucket"], "/tmp/lib/"]) end end @@ -71,7 +71,7 @@ source = "mybucket:pre/etc/" destination = "/root/etcrestore" - SyncCommand.process_file_destination(source, destination, file).should be_eql "/root/etcrestore/sub/path/blah.txt" + expect(SyncCommand.process_file_destination(source, destination, file)).to eql("/root/etcrestore/sub/path/blah.txt") end it "Put S3 files under an empty key (root) to the local dir /tmp/lib" do @@ -80,7 +80,7 @@ file = "myfile.rb" # This will yield local files at /tmp/lib/... - SyncCommand.process_file_destination(source, destination, file).should be_eql "/tmp/lib/myfile.rb" + expect(SyncCommand.process_file_destination(source, destination, file)).to eql("/tmp/lib/myfile.rb") end it "Returning locations based on the parsed destination" do @@ -91,8 +91,8 @@ src_location, dst_location = SyncCommand.parse_params [source, destination] # Then I see I got the locations with the right params - src_location.should be_eql S3Sync::Location.new("/etc") - dst_location.should be_eql S3Sync::Location.new("pre/etc/", "mybucket") + expect(src_location).to eql(S3Sync::Location.new("/etc")) + expect(dst_location).to eql(S3Sync::Location.new("pre/etc/", "mybucket")) end it "Location should be parsed when it is remote with no path" do @@ -103,14 +103,14 @@ src_location, dst_location = SyncCommand.parse_params [source, destination] # Then I see I got the locations with the right params - src_location.should be_eql S3Sync::Location.new("/etc") - dst_location.should be_eql S3Sync::Location.new("etc/", "mybucket") + expect(src_location).to eql(S3Sync::Location.new("/etc")) + expect(dst_location).to eql(S3Sync::Location.new("etc/", "mybucket")) end it "should be possible to detect if a location is remote" do - SyncCommand.remote_prefix?("bucket:prefix").should be_true - SyncCommand.remote_prefix?("path").should be_false - SyncCommand.remote_prefix?("C://blah").should be_false # We support windows, LOL + expect(SyncCommand.remote_prefix?("bucket:prefix")).to be(true) + expect(SyncCommand.remote_prefix?("path")).to be(false) + expect(SyncCommand.remote_prefix?("C://blah")).to be(false) # We support windows, LOL end end @@ -120,13 +120,13 @@ # Full test node = Node.new "path/to", "file1", 10 - node.path.should be_eql "file1" - node.full.should be_eql "path/to/file1" - node.size.should be_eql 10 + expect(node.path).to eql("file1") + expect(node.full).to eql("path/to/file1") + expect(node.size).to eql(10) # Alternative constructor scenarios node = Node.new "", "file1", 10 - node.path.should be_eql "file1" + expect(node.path).to eql("file1") end it "should be possible to compare two lists of files" do @@ -149,10 +149,10 @@ # Then I see that the three lists that I requested were returned with the # right content - same_in_both.should == [Node.new("", "file1", 10)] # Just testing our == operator - same_in_both.should be_eql [Node.new("", "file1", 10)] - to_be_added_to_list2.should be_eql [Node.new("", "file2", 12), Node.new("", "file3", 12)] - to_be_removed_from_list2.should be_eql [Node.new("", "file4", 22)] + expect(same_in_both).to eq([Node.new("", "file1", 10)]) # Just testing our == operator + expect(same_in_both).to eql([Node.new("", "file1", 10)]) + expect(to_be_added_to_list2).to eql([Node.new("", "file2", 12), Node.new("", "file3", 12)]) + expect(to_be_removed_from_list2).to eql([Node.new("", "file4", 22)]) end it 'can compare small files with an extra comparator' do @@ -177,8 +177,8 @@ # Then I see that the three lists that I requested were returned with the # right content - same_in_both.should == [Node.new("", "file1", 10), Node.new('', 'file5', large_file_size)] - to_be_added_to_list2.should be_eql [Node.new("", "file2", 22), Node.new("", "file3", 12)] - to_be_removed_from_list2.should be_eql [Node.new("", "file4", 22)] + expect(same_in_both).to eq([Node.new("", "file1", 10), Node.new('', 'file5', large_file_size)]) + expect(to_be_added_to_list2).to eql([Node.new("", "file2", 22), Node.new("", "file3", 12)]) + expect(to_be_removed_from_list2).to eql([Node.new("", "file4", 22)]) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a209d29..262e487 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,11 +41,11 @@ def rm path @capture.string.match check end - failure_message_for_should do + failure_message do "expected to #{description}" end - failure_message_for_should_not do + failure_message_when_negated do "expected not to #{description}" end