crazy-yard 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +19 -0
  3. data/README.md +438 -0
  4. data/bin/ey +9 -0
  5. data/lib/engineyard.rb +9 -0
  6. data/lib/engineyard/cli.rb +816 -0
  7. data/lib/engineyard/cli/api.rb +98 -0
  8. data/lib/engineyard/cli/recipes.rb +129 -0
  9. data/lib/engineyard/cli/ui.rb +275 -0
  10. data/lib/engineyard/cli/web.rb +85 -0
  11. data/lib/engineyard/config.rb +158 -0
  12. data/lib/engineyard/deploy_config.rb +65 -0
  13. data/lib/engineyard/deploy_config/ref.rb +56 -0
  14. data/lib/engineyard/error.rb +82 -0
  15. data/lib/engineyard/eyrc.rb +59 -0
  16. data/lib/engineyard/repo.rb +105 -0
  17. data/lib/engineyard/serverside_runner.rb +159 -0
  18. data/lib/engineyard/templates.rb +6 -0
  19. data/lib/engineyard/templates/ey.yml.erb +196 -0
  20. data/lib/engineyard/templates/ey_yml.rb +119 -0
  21. data/lib/engineyard/thor.rb +215 -0
  22. data/lib/engineyard/version.rb +4 -0
  23. data/lib/vendor/thor/Gemfile +15 -0
  24. data/lib/vendor/thor/LICENSE.md +20 -0
  25. data/lib/vendor/thor/README.md +35 -0
  26. data/lib/vendor/thor/lib/thor.rb +473 -0
  27. data/lib/vendor/thor/lib/thor/actions.rb +318 -0
  28. data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  29. data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
  30. data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
  31. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
  32. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +314 -0
  33. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
  34. data/lib/vendor/thor/lib/thor/base.rb +652 -0
  35. data/lib/vendor/thor/lib/thor/command.rb +136 -0
  36. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
  37. data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  38. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  39. data/lib/vendor/thor/lib/thor/error.rb +28 -0
  40. data/lib/vendor/thor/lib/thor/group.rb +282 -0
  41. data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
  42. data/lib/vendor/thor/lib/thor/parser.rb +4 -0
  43. data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
  44. data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
  45. data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
  46. data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
  47. data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
  48. data/lib/vendor/thor/lib/thor/runner.rb +322 -0
  49. data/lib/vendor/thor/lib/thor/shell.rb +88 -0
  50. data/lib/vendor/thor/lib/thor/shell/basic.rb +393 -0
  51. data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
  52. data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
  53. data/lib/vendor/thor/lib/thor/util.rb +270 -0
  54. data/lib/vendor/thor/lib/thor/version.rb +3 -0
  55. data/lib/vendor/thor/thor.gemspec +24 -0
  56. data/spec/engineyard/cli/api_spec.rb +50 -0
  57. data/spec/engineyard/cli_spec.rb +28 -0
  58. data/spec/engineyard/config_spec.rb +61 -0
  59. data/spec/engineyard/deploy_config_spec.rb +194 -0
  60. data/spec/engineyard/eyrc_spec.rb +76 -0
  61. data/spec/engineyard/repo_spec.rb +83 -0
  62. data/spec/engineyard_spec.rb +7 -0
  63. data/spec/ey/console_spec.rb +57 -0
  64. data/spec/ey/deploy_spec.rb +435 -0
  65. data/spec/ey/ey_spec.rb +23 -0
  66. data/spec/ey/init_spec.rb +123 -0
  67. data/spec/ey/list_environments_spec.rb +120 -0
  68. data/spec/ey/login_spec.rb +33 -0
  69. data/spec/ey/logout_spec.rb +24 -0
  70. data/spec/ey/logs_spec.rb +36 -0
  71. data/spec/ey/rebuild_spec.rb +18 -0
  72. data/spec/ey/recipes/apply_spec.rb +29 -0
  73. data/spec/ey/recipes/download_spec.rb +43 -0
  74. data/spec/ey/recipes/upload_spec.rb +99 -0
  75. data/spec/ey/rollback_spec.rb +73 -0
  76. data/spec/ey/scp_spec.rb +176 -0
  77. data/spec/ey/servers_spec.rb +209 -0
  78. data/spec/ey/ssh_spec.rb +273 -0
  79. data/spec/ey/status_spec.rb +45 -0
  80. data/spec/ey/timeout_deploy_spec.rb +18 -0
  81. data/spec/ey/web/disable_spec.rb +21 -0
  82. data/spec/ey/web/enable_spec.rb +26 -0
  83. data/spec/ey/web/restart_spec.rb +21 -0
  84. data/spec/ey/whoami_spec.rb +30 -0
  85. data/spec/spec_helper.rb +84 -0
  86. data/spec/support/bundled_ey +7 -0
  87. data/spec/support/fixture_recipes.tgz +0 -0
  88. data/spec/support/git_repos.rb +115 -0
  89. data/spec/support/helpers.rb +330 -0
  90. data/spec/support/matchers.rb +16 -0
  91. data/spec/support/ruby_ext.rb +13 -0
  92. data/spec/support/shared_behavior.rb +278 -0
  93. metadata +411 -0
@@ -0,0 +1,3 @@
1
+ class Thor
2
+ VERSION = "0.18.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+ require 'thor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.add_development_dependency 'bundler', '~> 1.0'
8
+ spec.authors = ['Yehuda Katz', 'José Valim']
9
+ spec.description = %q{A scripting framework that replaces rake, sake and rubigen}
10
+ spec.email = 'ruby-thor@googlegroups.com'
11
+ spec.executables = %w(thor)
12
+ spec.files = %w(.document CHANGELOG.md LICENSE.md README.md Thorfile thor.gemspec)
13
+ spec.files += Dir.glob("bin/**/*")
14
+ spec.files += Dir.glob("lib/**/*.rb")
15
+ spec.files += Dir.glob("spec/**/*")
16
+ spec.homepage = 'http://whatisthor.com/'
17
+ spec.licenses = ['MIT']
18
+ spec.name = 'thor'
19
+ spec.require_paths = ['lib']
20
+ spec.required_rubygems_version = '>= 1.3.6'
21
+ spec.summary = spec.description
22
+ spec.test_files = Dir.glob("spec/**/*")
23
+ spec.version = Thor::VERSION
24
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'engineyard/cli'
3
+
4
+ describe EY::CLI::API do
5
+ it "gets the api token from ~/.eyrc if possible" do
6
+ write_eyrc({"api_token" => "asdf"})
7
+ expect(EY::CLI::API.new('http://fake.local', EY::CLI::UI.new).token).to eq("asdf")
8
+ clean_eyrc
9
+ end
10
+
11
+ it "uses the token specified token over the ENV token if passed" do
12
+ ENV['ENGINEYARD_API_TOKEN'] = 'envtoken'
13
+ expect(EY::CLI::API.new('http://fake.local', EY::CLI::UI.new, 'specifiedtoken').token).to eq('specifiedtoken')
14
+ ENV.delete('ENGINEYARD_API_TOKEN')
15
+ end
16
+
17
+ it "uses the token from $ENGINEYARD_API_TOKEN if set" do
18
+ ENV['ENGINEYARD_API_TOKEN'] = 'envtoken'
19
+ expect(EY::CLI::API.new('http://fake.local', EY::CLI::UI.new).token).to eq('envtoken')
20
+ ENV.delete('ENGINEYARD_API_TOKEN')
21
+ end
22
+
23
+ context "without saved api token" do
24
+ before(:each) do
25
+ clean_eyrc
26
+ FakeWeb.register_uri(:post, "http://fake.local/api/v2/authenticate", :body => %|{"api_token": "asdf"}|, :content_type => 'application/json')
27
+
28
+ EY::CLI::UI::Prompter.enable_mock!
29
+ EY::CLI::UI::Prompter.add_answer "my@email.example.com"
30
+ EY::CLI::UI::Prompter.add_answer "secret"
31
+
32
+ capture_stdout do
33
+ @api = EY::CLI::API.new('http://fake.local', EY::CLI::UI.new)
34
+ end
35
+ end
36
+
37
+ it "asks you for your credentials" do
38
+ expect(EY::CLI::UI::Prompter.questions).to eq(["Email: ","Password: "])
39
+ end
40
+
41
+ it "gets the api token" do
42
+ expect(@api.token).to eq("asdf")
43
+ end
44
+
45
+ it "saves the api token to ~/.eyrc" do
46
+ expect(read_eyrc).to eq({"api_token" => "asdf"})
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'engineyard/cli'
3
+
4
+ describe EY::CLI do
5
+
6
+ it "provides help" do
7
+ out = capture_stdout do
8
+ EY::CLI.start(["help"])
9
+ end
10
+
11
+ expect(out).to include("ey deploy")
12
+ expect(out).to include("ey ssh")
13
+ expect(out).to include("ey web enable")
14
+ end
15
+
16
+ it "delegates help" do
17
+ out = capture_stdout do
18
+ EY::CLI.start(%w[help web enable])
19
+ end
20
+
21
+ expect(out).to match(/remove the maintenance page/i)
22
+ end
23
+
24
+ it "provides error classes" do
25
+ expect(EY::DeployArgumentError).to be
26
+ end
27
+
28
+ end # EY::CLI
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'uri'
3
+
4
+ describe EY::Config do
5
+ describe "environments" do
6
+ after { File.unlink('ey.yml') if File.exist?('ey.yml') }
7
+
8
+ it "get loaded from the config file" do
9
+ write_yaml({"environments" => {"production" => {"default" => true}}}, 'ey.yml')
10
+ expect(EY::Config.new.environments["production"]["default"]).to be_truthy
11
+ end
12
+
13
+ it "are present when the config file has no environments key" do
14
+ write_yaml({}, 'ey.yml')
15
+ expect(EY::Config.new.environments).to eq({})
16
+ end
17
+
18
+ it "rases an error when yaml produces an unexpected result" do
19
+ File.open('ey.yml', "w") {|f| f << "this isn't a hash" }
20
+ expect { EY::Config.new }.to raise_error(RuntimeError, "ey.yml load error: Expected a Hash but a String was returned.")
21
+ end
22
+
23
+ it "doesnt crash on nil environment" do
24
+ write_yaml({"environments" => {"production" => nil}}, 'ey.yml')
25
+ expect(EY::Config.new.default_environment).to be_nil
26
+ end
27
+ end
28
+
29
+ describe "endpoint" do
30
+ it "defaults to production Engine Yard Cloud" do
31
+ expect(EY::Config.new.endpoint).to eq(EY::Config.new.default_endpoint)
32
+ end
33
+
34
+ it "loads the endpoint from $CLOUD_URL" do
35
+ ENV['CLOUD_URL'] = "http://fake.local/"
36
+ expect(EY::Config.new.endpoint).to eq('http://fake.local/')
37
+ ENV.delete('CLOUD_URL')
38
+ end
39
+ end
40
+
41
+ describe "files" do
42
+ it "looks for config/ey.yml" do
43
+ FileUtils.mkdir_p('config')
44
+
45
+ write_yaml({"environments" => {"staging" => {"default" => true}}}, "ey.yml")
46
+ write_yaml({"environments" => {"production" => {"default" => true}}}, "config/ey.yml")
47
+ expect(EY::Config.new.default_environment).to eq("production")
48
+
49
+ File.unlink('config/ey.yml') if File.exist?('config/ey.yml')
50
+ File.unlink('ey.yml') if File.exist?('ey.yml')
51
+ end
52
+
53
+ it "looks for ey.yml" do
54
+ write_yaml({"environments" => {"staging" => {"default" => true}}}, "ey.yml")
55
+
56
+ expect(EY::Config.new.default_environment).to eq("staging")
57
+
58
+ File.unlink('ey.yml') if File.exist?('ey.yml')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,194 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ describe EY::DeployConfig do
5
+ let(:tempfile) { @tempfile = Tempfile.new('ey.yml') }
6
+ let(:parent) { EY::Config.new(tempfile.path) }
7
+ let(:ui) { EY::CLI::UI.new }
8
+ let(:repo) { double('repo') }
9
+ let(:env) { env_config(nil) }
10
+
11
+ after { @tempfile.unlink if @tempfile }
12
+
13
+ def env_config(opts, config = parent)
14
+ EY::Config::EnvironmentConfig.new(opts, 'envname', config)
15
+ end
16
+
17
+ def deploy_config(cli_opts, ec = env)
18
+ EY::DeployConfig.new(cli_opts, ec, repo, ui)
19
+ end
20
+
21
+ context "inside a repository" do
22
+ context "with no ey.yml file" do
23
+ let(:env) { env_config(nil, EY::Config.new('noexisto.yml')) }
24
+
25
+ it "tells you to initialize a new repository with ey init" do
26
+ dc = deploy_config({}, env)
27
+ expect { dc.migrate }.to raise_error(EY::Error, /Please initialize this application with the following command:/)
28
+ end
29
+ end
30
+
31
+ context "with the migrate cli option" do
32
+ it "returns default command when true" do
33
+ dc = deploy_config({'migrate' => true})
34
+ expect(dc.migrate).to be_truthy
35
+ expect { dc.migrate_command }.to raise_error(EY::Error, /'migration_command' not found/)
36
+ end
37
+
38
+ it "returns false when nil" do
39
+ dc = deploy_config({'migrate' => nil})
40
+ expect(dc.migrate).to be_falsey
41
+ expect(dc.migrate_command).to be_nil
42
+ end
43
+
44
+ it "return the custom migration command when is a string" do
45
+ dc = deploy_config({'migrate' => 'foo migrate'})
46
+ expect(dc.migrate).to be_truthy
47
+ expect(dc.migrate_command).to eq('foo migrate')
48
+ end
49
+ end
50
+
51
+ context "with the migrate option in the global configuration" do
52
+ it "return the migration command when the option is true" do
53
+ env = env_config('migrate' => true, 'migration_command' => 'bar migrate')
54
+ dc = deploy_config({}, env)
55
+ expect(dc.migrate).to be_truthy
56
+ expect(dc.migrate_command).to eq('bar migrate')
57
+ end
58
+
59
+ it "return the false when migrate is false" do
60
+ env = env_config('migrate' => false, 'migration_command' => 'bar migrate')
61
+ dc = deploy_config({}, env)
62
+ expect(dc.migrate).to be_falsey
63
+ expect(dc.migrate_command).to be_nil
64
+ end
65
+
66
+ it "tells you to run ey init" do
67
+ env = env_config('migrate' => true)
68
+ dc = deploy_config({}, env)
69
+ expect(dc.migrate).to be_truthy
70
+ expect { dc.migrate_command }.to raise_error(EY::Error, /'migration_command' not found/)
71
+ end
72
+
73
+ it "return the ey.yml migration_command when command line option --migrate is passed" do
74
+ env = env_config('migrate' => false, 'migration_command' => 'bar migrate')
75
+ dc = deploy_config({'migrate' => true}, env)
76
+ expect(dc.migrate).to be_truthy
77
+ expect(dc.migrate_command).to eq('bar migrate')
78
+ end
79
+ end
80
+
81
+ describe "ref" do
82
+ it "returns the passed ref" do
83
+ expect(deploy_config({'ref' => 'master'}).ref).to eq('master')
84
+ end
85
+
86
+ it "returns the passed force_ref" do
87
+ expect(deploy_config({'force_ref' => 'force'}).ref).to eq('force')
88
+ end
89
+
90
+ it "returns the ref if force_ref is true" do
91
+ expect(deploy_config({'ref' => 'master', 'force_ref' => true}).ref).to eq('master')
92
+ end
93
+
94
+ it "overrides the ref if force_ref is set to a string" do
95
+ expect(deploy_config({'ref' => 'master', 'force_ref' => 'force'}).ref).to eq('force')
96
+ end
97
+
98
+ context "with a default branch" do
99
+ let(:env) { env_config('branch' => 'default') }
100
+
101
+ it "uses the configured default if ref is not passed" do
102
+ out = capture_stdout do
103
+ expect(deploy_config({}).ref).to eq('default')
104
+ end
105
+ expect(out).to match(/Using default branch "default" from ey.yml/)
106
+ end
107
+
108
+ it "raises if a default is set and --ref is passed on the cli (and they don't match)" do
109
+ expect { deploy_config({'ref' => 'master'}).ref }.to raise_error(EY::BranchMismatchError)
110
+ end
111
+
112
+ it "returns the default if a default is set and --ref is the same" do
113
+ expect(deploy_config({'ref' => 'default'}).ref).to eq('default')
114
+ end
115
+
116
+ it "returns the ref if force_ref is set" do
117
+ out = capture_stdout do
118
+ expect(deploy_config({'ref' => 'master', 'force_ref' => true}).ref).to eq('master')
119
+ end
120
+ expect(out).to match(/Default ref overridden with "master"/)
121
+ end
122
+
123
+ it "returns the ref if force_ref is a branch" do
124
+ out = capture_stdout do
125
+ expect(deploy_config({'force_ref' => 'master'}).ref).to eq('master')
126
+ end
127
+ expect(out).to match(/Default ref overridden with "master"/)
128
+ end
129
+ end
130
+
131
+ context "no options, no default" do
132
+ it "uses the repo's current branch" do
133
+ expect(repo).to receive(:current_branch).and_return('current')
134
+ out = capture_stdout do
135
+ expect(deploy_config({}).ref).to eq('current')
136
+ end
137
+ expect(out).to match(/Using current HEAD branch "current"/)
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ context "when outside of a repo" do
144
+ describe "migrate" do
145
+ it "returns the default migration command when migrate is true" do
146
+ dc = deploy_config({'app' => 'app', 'migrate' => true})
147
+ expect(dc.migrate).to be_truthy
148
+ expect(dc.migrate_command).to eq('rake db:migrate --trace')
149
+ end
150
+
151
+ it "returns false when nil" do
152
+ dc = deploy_config({'app' => 'app', 'migrate' => nil})
153
+ expect(dc.migrate).to be_falsey
154
+ expect(dc.migrate_command).to be_nil
155
+ end
156
+
157
+ it "return the custom migration command when is a string" do
158
+ dc = deploy_config({'app' => 'app', 'migrate' => 'foo migrate'})
159
+ expect(dc.migrate).to be_truthy
160
+ expect(dc.migrate_command).to eq('foo migrate')
161
+ end
162
+
163
+ it "raises if migrate is not passed" do
164
+ expect { deploy_config({'app' => 'app'}).migrate }.to raise_error(EY::RefAndMigrateRequiredOutsideRepo)
165
+ end
166
+ end
167
+
168
+ describe "ref" do
169
+ it "returns the passed ref" do
170
+ dc = deploy_config({'app' => 'app', 'ref' => 'master'})
171
+ expect(dc.ref).to eq('master')
172
+ end
173
+
174
+ it "returns the passed force_ref" do
175
+ dc = deploy_config({'app' => 'app', 'force_ref' => 'force'})
176
+ expect(dc.ref).to eq('force')
177
+ end
178
+
179
+ it "returns the ref if force_ref is true" do
180
+ dc = deploy_config({'app' => 'app', 'ref' => 'master', 'force_ref' => true})
181
+ expect(dc.ref).to eq('master')
182
+ end
183
+
184
+ it "overrides the ref if force_ref is set to a string" do
185
+ dc = deploy_config({'app' => 'app', 'ref' => 'master', 'force_ref' => 'force'})
186
+ expect(dc.ref).to eq('force')
187
+ end
188
+
189
+ it "raises if ref is not passed" do
190
+ expect { deploy_config({'app' => 'app'}).ref }.to raise_error(EY::RefAndMigrateRequiredOutsideRepo)
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+ require 'engineyard/eyrc'
3
+
4
+ describe EY::EYRC do
5
+ before { clean_eyrc }
6
+
7
+ describe ".load" do
8
+ it "looks for .eyrc in $EYRC if set" do
9
+ expect(EY::EYRC.load.path).to eq(Pathname.new(ENV['EYRC']))
10
+ end
11
+
12
+ it "looks for .eyrc in $HOME/.eyrc by default" do
13
+ ENV.delete('EYRC')
14
+ expect(EY::EYRC.load.path).to eq(Pathname.new("#{ENV['HOME']}/.eyrc"))
15
+ end
16
+ end
17
+
18
+ describe ".new" do
19
+ it "looks for eyrc in any passed file location" do
20
+ expect(EY::EYRC.new('/tmp/neweyrc').path).to eq(Pathname.new('/tmp/neweyrc'))
21
+ end
22
+ end
23
+
24
+ context "with a non-existing .eyrc file" do
25
+ it "has nil api_token" do
26
+ expect(File.exists?("/tmp/nonexistant")).to be_falsey
27
+ eyrc = EY::EYRC.new('/tmp/nonexistant')
28
+ expect(eyrc.exist?).to be_falsey
29
+ expect(eyrc.api_token).to be_nil
30
+ end
31
+ end
32
+
33
+ context "saving api token" do
34
+ before do
35
+ EY::EYRC.load.api_token = 'abcd'
36
+ end
37
+
38
+ it "exists" do
39
+ expect(EY::EYRC.load.exist?).to be_truthy
40
+ end
41
+
42
+ it "recalls the api_token" do
43
+ expect(EY::EYRC.load.api_token).to eq('abcd')
44
+ end
45
+
46
+ it "deletes the api_token" do
47
+ EY::EYRC.load.delete_api_token
48
+ expect(EY::EYRC.load.api_token).to be_nil
49
+ end
50
+
51
+ it "writes the api_token to api_token: .eyrc" do
52
+ expect(read_yaml(ENV['EYRC'])).to eq({"api_token" => "abcd"})
53
+ end
54
+ end
55
+
56
+ context "file contains other random info" do
57
+ before do
58
+ # contains legacy endpoint behavior, no longer supported, but we won't be destructive.
59
+ write_yaml({"api_token" => "1234", "http://localhost/" => {"api_token" => "5678"}}, ENV['EYRC'])
60
+ EY::EYRC.load.api_token = 'abcd' # overwrites 1234
61
+ end
62
+
63
+ it "recalls the api_token" do
64
+ expect(EY::EYRC.load.api_token).to eq('abcd')
65
+ end
66
+
67
+ it "deletes the api token safely on logout" do
68
+ EY::EYRC.load.delete_api_token
69
+ expect(read_yaml(ENV['EYRC'])).to eq({"http://localhost/" => {"api_token" => "5678"}})
70
+ end
71
+
72
+ it "maintains other random info in the file" do
73
+ expect(read_yaml(ENV['EYRC'])).to eq({"api_token" => "abcd", "http://localhost/" => {"api_token" => "5678"}})
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe EY::Repo do
4
+ let(:path) { p = TMPDIR.join('ey-test'); p.mkpath; p }
5
+
6
+ before(:each) do
7
+ Dir.chdir(path) { `git init -q` }
8
+ ENV['GIT_DIR'] = path.join('.git').to_s
9
+ end
10
+
11
+ after(:each) do
12
+ path.rmtree
13
+ ENV.delete('GIT_DIR')
14
+ end
15
+
16
+ def set_head(head)
17
+ path.join('.git','HEAD').open('w') {|f| f.write(head) }
18
+ end
19
+
20
+ def set_url(url, remote)
21
+ `git remote add #{remote} #{url}`
22
+ end
23
+
24
+ describe ".new" do
25
+ it "creates a working repo object in a repo" do
26
+ expect(EY::Repo.new.remotes).to be_empty
27
+ end
28
+
29
+ it "doesn't raise if created outside a repository until trying to do something" do
30
+ ENV['GIT_DIR'] = nil
31
+ Dir.chdir('/tmp') do
32
+ repo = EY::Repo.new
33
+ expect { repo.remotes }.to raise_error(EY::Repo::NotAGitRepository)
34
+ end
35
+ end
36
+ end
37
+
38
+ describe ".exist?" do
39
+ it "is true when env vars are set to a repo" do
40
+ expect(EY::Repo).to be_exist
41
+ end
42
+
43
+ it "is true when pwd is a repo" do
44
+ Dir.chdir(File.dirname(ENV['GIT_DIR'])) do
45
+ ENV['GIT_DIR'] = nil
46
+ expect(EY::Repo).to be_exist
47
+ end
48
+ end
49
+
50
+ it "is false when outside of any repo" do
51
+ ENV['GIT_DIR'] = nil
52
+ Dir.chdir('/tmp') do
53
+ expect(EY::Repo).not_to be_exist
54
+ end
55
+ end
56
+ end
57
+
58
+ context "in a repository dir" do
59
+
60
+ before(:each) do
61
+ @repo = EY::Repo.new
62
+ end
63
+
64
+ describe "current_branch method" do
65
+ it "returns the name of the current branch" do
66
+ set_head "ref: refs/heads/master"
67
+ expect(@repo.current_branch).to eq("master")
68
+ end
69
+
70
+ it "returns nil if there is no current branch" do
71
+ set_head "20bf478ab6a91ec5771130aa4c8cfd3d150c4146"
72
+ expect(@repo.current_branch).to be_nil
73
+ end
74
+ end # current_branch
75
+
76
+ describe "#fail_on_no_remotes!" do
77
+ it "raises when there are no remotes" do
78
+ expect { @repo.fail_on_no_remotes! }.to raise_error(EY::Repo::NoRemotesError)
79
+ end
80
+ end
81
+
82
+ end
83
+ end