travis_github_deployer 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,7 +34,7 @@ class TravisGithubDeployer
34
34
  end
35
35
 
36
36
  def files_to_deploy
37
- @files_to_deploy
37
+ @files_to_deploy ||= {}
38
38
  end
39
39
 
40
40
  ## Deployment
@@ -58,7 +58,22 @@ class TravisGithubDeployer
58
58
  def load_configuration
59
59
  configuration = YAML.load_file(".travis_github_deployer.yml")
60
60
  @destination_repository = configuration["destination_repository"]
61
- @files_to_deploy = configuration["files_to_deploy"]
61
+ prepare_files_to_deploy(configuration["files_to_deploy"])
62
+ end
63
+
64
+ def prepare_files_to_deploy files_hash
65
+ files_hash.each { |source_file_from_configuration, destination_file|
66
+
67
+ source_files = Dir.glob(source_file_from_configuration)
68
+
69
+ if source_files.empty?
70
+ raise StandardError.new("File: '#{source_file_from_configuration}' found in the configuration didn't exist. Deploy failed.")
71
+ end
72
+
73
+ source_files.each { |source_file|
74
+ files_to_deploy[source_file] = destination_file
75
+ }
76
+ }
62
77
  end
63
78
 
64
79
  def command_line_arguments(arguments)
@@ -108,7 +123,7 @@ class TravisGithubDeployer
108
123
  files_to_deploy.each { |source_location, destination_location|
109
124
  source = Pathname.new(source_location)
110
125
  destination = Pathname.new(destination_repository_dir)
111
- destination += destination_location.empty? ? source_location : destination_location
126
+ destination += destination_location
112
127
  FileUtils.copy(source, destination)
113
128
  }
114
129
 
@@ -121,10 +136,4 @@ class TravisGithubDeployer
121
136
  git.commit("File deployed with Travis Github Deployer")
122
137
  git.push
123
138
  end
124
-
125
- end
126
-
127
-
128
- if __FILE__ == $0 then
129
- GithubPagesDeployer.new.deploy
130
139
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module TravisGithubDeployerVersion
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
@@ -54,7 +54,6 @@ describe "simple ruby interface around git command line" do
54
54
  subject.git("something")
55
55
  end
56
56
 
57
-
58
57
  it "Should be able to do a successful command" do
59
58
  subject.should_not_receive(:puts)
60
59
  subject.git('version').should start_with("git version")
@@ -65,6 +64,4 @@ describe "simple ruby interface around git command line" do
65
64
  subject.git('error')
66
65
  }.to raise_error(StandardError, "Git command: 'error' failed. Message: : git: 'error' is not a git command. See 'git --help'.\n\nDid you mean this?\n rerere\n")
67
66
  end
68
-
69
-
70
- end
67
+ end
@@ -8,6 +8,7 @@ describe "travis github deployer" do
8
8
  before(:each) do
9
9
  @git = mock
10
10
  GitCommandLine.should_receive(:new).and_return(@git)
11
+ subject
11
12
  end
12
13
 
13
14
  it "can deploy to an destination repository" do
@@ -83,19 +84,17 @@ describe "travis github deployer" do
83
84
  context "Prepare the changes that need to be made commit" do
84
85
 
85
86
  it "should be able to copy a file from the root of the source repository to the root of the destination reportistory" do
86
- subject.should_receive(:destination_repository_dir).and_return("destdir")
87
87
  subject.should_receive(:files_to_deploy).and_return( { "sourcefile" => ""})
88
- FileUtils.should_receive(:copy).with(Pathname.new("sourcefile"), Pathname.new("destdir/sourcefile"))
88
+ FileUtils.should_receive(:copy).with(Pathname.new("sourcefile"), Pathname.new("travis_github_deployer_repository"))
89
89
  subject.copy_files_in_destination_repository
90
90
  end
91
91
 
92
92
  it "Should be able to copy multiple files" do
93
- subject.should_receive(:destination_repository_dir).exactly(2).times.and_return("destdir")
94
93
  subject.should_receive(:files_to_deploy).and_return({ "dir/onefile" => "destonefile", "twofile" => "dir/desttwofile"})
95
- FileUtils.should_receive(:copy).with(Pathname.new("dir/onefile"), Pathname.new("destdir/destonefile"))
96
- FileUtils.should_receive(:copy).with(Pathname.new("twofile"), Pathname.new("destdir/dir/desttwofile"))
94
+ FileUtils.should_receive(:copy).with(Pathname.new("dir/onefile"), Pathname.new("travis_github_deployer_repository/destonefile"))
95
+ FileUtils.should_receive(:copy).with(Pathname.new("twofile"), Pathname.new("travis_github_deployer_repository/dir/desttwofile"))
97
96
  subject.copy_files_in_destination_repository
98
- end
97
+ end
99
98
  end
100
99
 
101
100
  context "Actually committing the files" do
@@ -120,13 +119,29 @@ describe "travis github deployer" do
120
119
  }
121
120
 
122
121
  YAML.should_receive(:load_file).with(".travis_github_deployer.yml").and_return(configuration)
122
+ subject.should_receive(:prepare_files_to_deploy).with({"source_dir/source_file" => "destination_dir/destination_file"})
123
123
  subject.load_configuration
124
124
 
125
125
  subject.destination_repository.should== "https://github.com/cpputest/cpputest.github.io.git"
126
- subject.files_to_deploy.should== { "source_dir/source_file" => "destination_dir/destination_file" }
127
126
 
128
127
  end
129
128
 
129
+ it "can have files with wildcards in the configuration" do
130
+ wild_card_files = { "source_dir/*" => "destination_dir" }
131
+ Dir.should_receive(:glob).with("source_dir/*").and_return(["file1", "file2"])
132
+
133
+ subject.prepare_files_to_deploy(wild_card_files)
134
+ subject.files_to_deploy.should== { "file1" => "destination_dir", "file2" => "destination_dir" }
135
+ end
136
+
137
+ it "raises an error when one of the source files doesn't exists" do
138
+ Dir.should_receive(:glob).with("not_exists").and_return([])
139
+ expect {
140
+ subject.prepare_files_to_deploy( { "not_exists" => "" })
141
+ }.to raise_error(StandardError, "File: 'not_exists' found in the configuration didn't exist. Deploy failed.")
142
+ end
143
+
144
+
130
145
  it "isn't verbose by default" do
131
146
  subject.command_line_arguments([""])
132
147
  subject.verbose.should == false
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: travis_github_deployer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bas Vodde
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-07-16 00:00:00 Z
13
+ date: 2013-07-19 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake