bard 1.9.6 → 2.0.0

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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -2
  3. data/CLAUDE.md +1 -1
  4. data/PLUGINS.md +31 -46
  5. data/bard.gemspec +2 -1
  6. data/features/ci.feature +1 -0
  7. data/features/data.feature +1 -0
  8. data/features/deploy.feature +1 -0
  9. data/features/deploy_git_workflow.feature +1 -0
  10. data/features/run.feature +1 -0
  11. data/features/step_definitions/bard_steps.rb +1 -0
  12. data/features/support/test_server.rb +3 -3
  13. data/lib/bard/cli.rb +9 -28
  14. data/lib/bard/command.rb +9 -88
  15. data/lib/bard/config.rb +38 -177
  16. data/lib/bard/copy.rb +28 -82
  17. data/lib/bard/plugins/data.rb +56 -0
  18. data/lib/bard/{ci → plugins/deploy/ci}/github_actions.rb +2 -2
  19. data/lib/bard/{ci → plugins/deploy/ci}/jenkins.rb +1 -1
  20. data/lib/bard/{ci → plugins/deploy/ci}/local.rb +1 -1
  21. data/lib/bard/{ci → plugins/deploy/ci}/runner.rb +3 -3
  22. data/lib/bard/{ci.rb → plugins/deploy/ci.rb} +1 -1
  23. data/lib/bard/plugins/deploy/ssh_strategy.rb +27 -0
  24. data/lib/bard/{deploy_strategy.rb → plugins/deploy/strategy.rb} +1 -4
  25. data/lib/bard/plugins/deploy.rb +240 -0
  26. data/lib/bard/{git.rb → plugins/git.rb} +6 -3
  27. data/lib/bard/{github.rb → plugins/github.rb} +2 -2
  28. data/lib/bard/{deploy_strategy/github_pages.rb → plugins/github_pages/strategy.rb} +3 -4
  29. data/lib/bard/plugins/github_pages.rb +11 -15
  30. data/lib/bard/plugins/hurt.rb +12 -4
  31. data/{install_files → lib/bard/plugins/install}/.github/dependabot.yml +2 -1
  32. data/{install_files → lib/bard/plugins/install}/.github/workflows/cache-ci.yml +1 -1
  33. data/{install_files → lib/bard/plugins/install}/.github/workflows/ci.yml +2 -2
  34. data/lib/bard/plugins/install.rb +7 -3
  35. data/lib/bard/plugins/open.rb +20 -0
  36. data/lib/bard/{ping.rb → plugins/ping/check.rb} +4 -4
  37. data/lib/bard/plugins/ping/target_methods.rb +23 -0
  38. data/lib/bard/plugins/ping.rb +8 -4
  39. data/lib/bard/plugins/run.rb +19 -0
  40. data/lib/bard/plugins/setup.rb +54 -0
  41. data/lib/bard/plugins/ssh/connection.rb +75 -0
  42. data/lib/bard/plugins/ssh/copy.rb +95 -0
  43. data/lib/bard/{ssh_server.rb → plugins/ssh/server.rb} +10 -42
  44. data/lib/bard/plugins/ssh/target_methods.rb +20 -0
  45. data/lib/bard/plugins/ssh.rb +10 -0
  46. data/lib/bard/plugins/url/target_methods.rb +23 -0
  47. data/lib/bard/plugins/url.rb +1 -0
  48. data/lib/bard/plugins/vim.rb +5 -4
  49. data/lib/bard/retryable.rb +25 -0
  50. data/lib/bard/target.rb +21 -230
  51. data/lib/bard/version.rb +1 -1
  52. data/lib/bard.rb +1 -3
  53. data/spec/acceptance/docker/Dockerfile +1 -1
  54. data/spec/bard/capability_spec.rb +8 -50
  55. data/spec/bard/ci/github_actions_spec.rb +1 -1
  56. data/spec/bard/ci/jenkins_spec.rb +1 -1
  57. data/spec/bard/ci/runner_spec.rb +3 -3
  58. data/spec/bard/ci_spec.rb +1 -1
  59. data/spec/bard/cli/ci_spec.rb +4 -23
  60. data/spec/bard/cli/data_spec.rb +7 -26
  61. data/spec/bard/cli/deploy_spec.rb +43 -40
  62. data/spec/bard/cli/hurt_spec.rb +2 -8
  63. data/spec/bard/cli/install_spec.rb +4 -10
  64. data/spec/bard/cli/master_key_spec.rb +5 -19
  65. data/spec/bard/cli/open_spec.rb +17 -35
  66. data/spec/bard/cli/ping_spec.rb +10 -25
  67. data/spec/bard/cli/run_spec.rb +10 -23
  68. data/spec/bard/cli/setup_spec.rb +10 -27
  69. data/spec/bard/cli/ssh_spec.rb +10 -25
  70. data/spec/bard/cli/stage_spec.rb +17 -32
  71. data/spec/bard/cli/vim_spec.rb +5 -11
  72. data/spec/bard/command_spec.rb +1 -10
  73. data/spec/bard/config_spec.rb +68 -116
  74. data/spec/bard/copy_spec.rb +54 -18
  75. data/spec/bard/deploy_strategy/ssh_spec.rb +65 -7
  76. data/spec/bard/deploy_strategy_spec.rb +1 -1
  77. data/spec/bard/dynamic_dsl_spec.rb +18 -98
  78. data/spec/bard/git_spec.rb +9 -5
  79. data/spec/bard/github_spec.rb +1 -1
  80. data/spec/bard/ping_spec.rb +5 -5
  81. data/spec/bard/ssh_copy_spec.rb +44 -0
  82. data/spec/bard/ssh_server_spec.rb +1 -98
  83. data/spec/bard/target_spec.rb +61 -108
  84. metadata +50 -124
  85. data/lib/bard/ci/retryable.rb +0 -27
  86. data/lib/bard/cli/ci.rb +0 -73
  87. data/lib/bard/cli/command.rb +0 -26
  88. data/lib/bard/cli/data.rb +0 -45
  89. data/lib/bard/cli/deploy.rb +0 -116
  90. data/lib/bard/cli/hurt.rb +0 -15
  91. data/lib/bard/cli/install.rb +0 -11
  92. data/lib/bard/cli/master_key.rb +0 -17
  93. data/lib/bard/cli/new.rb +0 -101
  94. data/lib/bard/cli/new_rails_template.rb +0 -197
  95. data/lib/bard/cli/open.rb +0 -18
  96. data/lib/bard/cli/ping.rb +0 -12
  97. data/lib/bard/cli/provision.rb +0 -34
  98. data/lib/bard/cli/run.rb +0 -26
  99. data/lib/bard/cli/setup.rb +0 -56
  100. data/lib/bard/cli/ssh.rb +0 -14
  101. data/lib/bard/cli/stage.rb +0 -35
  102. data/lib/bard/cli/vim.rb +0 -8
  103. data/lib/bard/default_config.rb +0 -35
  104. data/lib/bard/deploy_strategy/ssh.rb +0 -19
  105. data/lib/bard/deprecation.rb +0 -19
  106. data/lib/bard/github_pages.rb +0 -134
  107. data/lib/bard/plugin.rb +0 -100
  108. data/lib/bard/plugins/backup.rb +0 -19
  109. data/lib/bard/plugins/jenkins.rb +0 -6
  110. data/lib/bard/plugins/new.rb +0 -5
  111. data/lib/bard/plugins/provision.rb +0 -5
  112. data/lib/bard/provision/app.rb +0 -10
  113. data/lib/bard/provision/apt.rb +0 -16
  114. data/lib/bard/provision/authorizedkeys.rb +0 -25
  115. data/lib/bard/provision/data.rb +0 -27
  116. data/lib/bard/provision/deploy.rb +0 -10
  117. data/lib/bard/provision/http.rb +0 -16
  118. data/lib/bard/provision/logrotation.rb +0 -30
  119. data/lib/bard/provision/masterkey.rb +0 -18
  120. data/lib/bard/provision/mysql.rb +0 -22
  121. data/lib/bard/provision/passenger.rb +0 -37
  122. data/lib/bard/provision/repo.rb +0 -72
  123. data/lib/bard/provision/rvm.rb +0 -22
  124. data/lib/bard/provision/ssh.rb +0 -79
  125. data/lib/bard/provision/swapfile.rb +0 -23
  126. data/lib/bard/provision/user.rb +0 -42
  127. data/lib/bard/provision.rb +0 -16
  128. data/lib/bard/server.rb +0 -160
  129. data/spec/bard/cli/command_spec.rb +0 -50
  130. data/spec/bard/cli/new_spec.rb +0 -73
  131. data/spec/bard/cli/provision_spec.rb +0 -42
  132. data/spec/bard/deprecation_spec.rb +0 -281
  133. data/spec/bard/github_pages_spec.rb +0 -143
  134. data/spec/bard/plugin_spec.rb +0 -79
  135. data/spec/bard/provision/app_spec.rb +0 -33
  136. data/spec/bard/provision/apt_spec.rb +0 -39
  137. data/spec/bard/provision/authorizedkeys_spec.rb +0 -40
  138. data/spec/bard/provision/data_spec.rb +0 -54
  139. data/spec/bard/provision/deploy_spec.rb +0 -33
  140. data/spec/bard/provision/http_spec.rb +0 -57
  141. data/spec/bard/provision/logrotation_spec.rb +0 -34
  142. data/spec/bard/provision/masterkey_spec.rb +0 -63
  143. data/spec/bard/provision/mysql_spec.rb +0 -55
  144. data/spec/bard/provision/passenger_spec.rb +0 -81
  145. data/spec/bard/provision/repo_spec.rb +0 -208
  146. data/spec/bard/provision/rvm_spec.rb +0 -49
  147. data/spec/bard/provision/ssh_spec.rb +0 -242
  148. data/spec/bard/provision/swapfile_spec.rb +0 -33
  149. data/spec/bard/provision/user_spec.rb +0 -103
  150. data/spec/bard/provision_spec.rb +0 -28
  151. data/spec/bard/server_spec.rb +0 -127
  152. /data/lib/bard/{ci → plugins/deploy/ci}/state.rb +0 -0
  153. /data/{install_files → lib/bard/plugins/install}/apt_dependencies.rb +0 -0
  154. /data/{install_files → lib/bard/plugins/install}/ci +0 -0
  155. /data/{install_files → lib/bard/plugins/install}/setup +0 -0
  156. /data/{install_files → lib/bard/plugins/install}/specified_bundler.rb +0 -0
  157. /data/{install_files → lib/bard/plugins/install}/specified_ruby.rb +0 -0
@@ -1,28 +1,11 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/deploy"
4
- require "thor"
5
3
 
6
- class TestDeployCLI < Thor
7
- include Bard::CLI::Deploy
8
-
9
- attr_reader :config, :options
10
-
11
- def initialize
12
- super
13
- @config = {}
14
- @options = {}
15
- end
16
-
17
- def project_name
18
- "test_project"
19
- end
20
- end
21
-
22
- describe Bard::CLI::Deploy do
23
- let(:production_server) { double("production", run!: true, github_pages: false, path: "/var/www/test_project") }
4
+ describe "bard deploy" do
5
+ let(:deploy_strategy) { double("deploy_strategy", deploy: true) }
6
+ let(:production_server) { double("production", run!: true, path: "/var/www/test_project", deploy_strategy: :ssh, deploy_strategy_instance: deploy_strategy) }
24
7
  let(:config) { { production: production_server } }
25
- let(:cli) { TestDeployCLI.new }
8
+ let(:cli) { Bard::CLI.new }
26
9
 
27
10
  before do
28
11
  allow(config).to receive(:ci).and_return(nil)
@@ -33,12 +16,14 @@ describe Bard::CLI::Deploy do
33
16
  allow(cli).to receive(:run!)
34
17
  allow(cli).to receive(:invoke)
35
18
  allow(cli).to receive(:ping)
19
+ allow(cli).to receive(:project_name).and_return("test_project")
36
20
  allow(cli).to receive(:green).and_return("")
37
21
  allow(cli).to receive(:red).and_return("")
38
22
  allow(cli).to receive(:yellow).and_return("")
39
23
  allow(Bard::Git).to receive(:current_branch).and_return("feature-branch")
40
24
  allow(Bard::Git).to receive(:up_to_date_with_remote?).and_return(true)
41
25
  allow(Bard::Git).to receive(:fast_forward_merge?).and_return(true)
26
+ allow(Bard::Git).to receive(:in_linked_worktree?).and_return(false)
42
27
  allow(cli).to receive(:`).and_return("")
43
28
  end
44
29
 
@@ -59,8 +44,7 @@ describe Bard::CLI::Deploy do
59
44
 
60
45
  expect(cli).not_to receive(:run!).with(/git push/)
61
46
  expect(cli).to receive(:invoke).with(:ci, ["master"], {})
62
- expect(production_server).to receive(:run!).with("git pull origin master && bin/setup")
63
- expect(cli).to receive(:puts) # "Deploy Succeeded"
47
+ expect(deploy_strategy).to receive(:deploy)
64
48
  expect(cli).to receive(:ping).with(:production)
65
49
 
66
50
  cli.deploy
@@ -73,7 +57,7 @@ describe Bard::CLI::Deploy do
73
57
 
74
58
  expect(cli).to receive(:run!).with("git push origin master:master")
75
59
  expect(cli).to receive(:invoke).with(:ci, ["master"], {})
76
- expect(production_server).to receive(:run!).with("git pull origin master && bin/setup")
60
+ expect(deploy_strategy).to receive(:deploy)
77
61
 
78
62
  cli.deploy
79
63
  end
@@ -84,7 +68,7 @@ describe Bard::CLI::Deploy do
84
68
  allow(cli).to receive(:options).and_return({ "skip-ci" => true, target: "production" })
85
69
 
86
70
  expect(cli).not_to receive(:invoke).with(:ci, anything, anything)
87
- expect(production_server).to receive(:run!).with("git pull origin master && bin/setup")
71
+ expect(deploy_strategy).to receive(:deploy)
88
72
 
89
73
  cli.deploy
90
74
  end
@@ -95,7 +79,7 @@ describe Bard::CLI::Deploy do
95
79
  allow(config).to receive(:ci).and_return(false)
96
80
 
97
81
  expect(cli).not_to receive(:invoke).with(:ci, anything, anything)
98
- expect(production_server).to receive(:run!).with("git pull origin master && bin/setup")
82
+ expect(deploy_strategy).to receive(:deploy)
99
83
 
100
84
  cli.deploy
101
85
  end
@@ -114,7 +98,7 @@ describe Bard::CLI::Deploy do
114
98
  expect(cli).to receive(:run!).with("git push -f origin feature-branch:feature-branch")
115
99
  expect(cli).to receive(:invoke).with(:ci, ["feature-branch"], {})
116
100
  expect(cli).to receive(:run!).with("git push origin feature-branch:master")
117
- expect(production_server).to receive(:run!).with("git pull origin master && bin/setup")
101
+ expect(deploy_strategy).to receive(:deploy)
118
102
 
119
103
  cli.deploy
120
104
  end
@@ -129,6 +113,27 @@ describe Bard::CLI::Deploy do
129
113
  end
130
114
  end
131
115
 
116
+ context "when run from a linked worktree" do
117
+ before do
118
+ allow(Bard::Git).to receive(:in_linked_worktree?).and_return(true)
119
+ allow(cli).to receive(:`).with("git rev-parse --git-common-dir").and_return("/main/checkout/.git\n")
120
+ allow(Dir).to receive(:pwd).and_return("/main/checkout/tmp/worktrees/feature-branch")
121
+ allow(Dir).to receive(:chdir).with("/main/checkout")
122
+ end
123
+
124
+ it "skips writes to local master, removes the worktree, and reports where to cd back" do
125
+ expect(cli).not_to receive(:run!).with("git fetch origin master:master")
126
+ expect(cli).not_to receive(:run!).with("git checkout master")
127
+ expect(cli).to receive(:run!).with("git fetch origin master")
128
+ expect(Dir).to receive(:chdir).with("/main/checkout")
129
+ expect(cli).to receive(:run!).with("git worktree remove /main/checkout/tmp/worktrees/feature-branch")
130
+ expect(cli).to receive(:run!).with("git branch -D feature-branch")
131
+ expect(cli).to receive(:puts).with("Worktree removed. Run: cd /main/checkout")
132
+
133
+ cli.deploy
134
+ end
135
+ end
136
+
132
137
  context "when rebase is needed" do
133
138
  it "attempts rebase before proceeding" do
134
139
  allow(Bard::Git).to receive(:fast_forward_merge?).and_return(false)
@@ -150,7 +155,7 @@ describe Bard::CLI::Deploy do
150
155
 
151
156
  it "skips CI step" do
152
157
  expect(cli).not_to receive(:invoke).with(:ci, anything, anything)
153
- expect(production_server).to receive(:run!).with("git pull origin master && bin/setup")
158
+ expect(deploy_strategy).to receive(:deploy)
154
159
 
155
160
  cli.deploy
156
161
  end
@@ -167,31 +172,29 @@ describe Bard::CLI::Deploy do
167
172
  end
168
173
 
169
174
  context "with clone option" do
170
- it "clones repository and sets up application" do
175
+ it "deploys with clone option to strategy" do
171
176
  allow(cli).to receive(:options).and_return({ clone: true, target: "production" })
172
177
 
173
- expect(production_server).to receive(:run!).with("git clone git@github.com:botandrosedesign/test_project /var/www/test_project", home: true)
174
- expect(cli).to receive(:invoke).with(:master_key, [], from: "local", to: :production)
175
- expect(production_server).to receive(:run!).with("bin/setup && bard setup")
178
+ expect(deploy_strategy).to receive(:deploy).with(clone: "test_project")
176
179
 
177
180
  cli.deploy
178
181
  end
179
182
  end
180
183
 
181
184
  context "with github pages" do
182
- it "deploys to github pages" do
183
- allow(production_server).to receive(:github_pages).and_return(true)
184
- github_pages = double("github_pages")
185
- allow(Bard::GithubPages).to receive(:new).and_return(github_pages)
185
+ let(:deploy_strategy) { double("github_pages_strategy") }
186
+ let(:production_server) { double("production", run!: true, path: "/var/www/test_project", deploy_strategy: :github_pages, deploy_strategy_instance: deploy_strategy) }
186
187
 
187
- expect(github_pages).to receive(:deploy).with(production_server)
188
+ it "deploys using deploy strategy" do
189
+ expect(deploy_strategy).to receive(:deploy)
188
190
 
189
191
  cli.deploy
190
192
  end
191
193
  end
192
194
 
193
195
  context "with custom deployment target" do
194
- let(:staging_server) { double("staging", run!: true, github_pages: false) }
196
+ let(:staging_strategy) { double("staging_strategy", deploy: true) }
197
+ let(:staging_server) { double("staging", run!: true, deploy_strategy: :ssh, deploy_strategy_instance: staging_strategy) }
195
198
 
196
199
  before do
197
200
  allow(config).to receive(:[]).with(:staging).and_return(staging_server)
@@ -199,7 +202,7 @@ describe Bard::CLI::Deploy do
199
202
  end
200
203
 
201
204
  it "deploys to specified target" do
202
- expect(staging_server).to receive(:run!).with("git pull origin master && bin/setup")
205
+ expect(staging_strategy).to receive(:deploy)
203
206
  expect(cli).to receive(:ping).with(:staging)
204
207
 
205
208
  cli.deploy
@@ -237,4 +240,4 @@ describe Bard::CLI::Deploy do
237
240
  end
238
241
  end
239
242
  end
240
- end
243
+ end
@@ -1,14 +1,8 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/hurt"
4
- require "thor"
5
3
 
6
- class TestHurtCLI < Thor
7
- Bard::CLI::Hurt.setup(self)
8
- end
9
-
10
- describe Bard::CLI::Hurt do
11
- let(:cli) { TestHurtCLI.new }
4
+ describe "bard hurt" do
5
+ let(:cli) { Bard::CLI.new }
12
6
 
13
7
  before do
14
8
  allow(cli).to receive(:puts)
@@ -1,14 +1,8 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/install"
4
- require "thor"
5
3
 
6
- class TestInstallCLI < Thor
7
- Bard::CLI::Install.setup(self)
8
- end
9
-
10
- describe Bard::CLI::Install do
11
- let(:cli) { TestInstallCLI.new }
4
+ describe "bard install" do
5
+ let(:cli) { Bard::CLI.new }
12
6
 
13
7
  describe "#install" do
14
8
  it "should have an install command" do
@@ -16,8 +10,8 @@ describe Bard::CLI::Install do
16
10
  end
17
11
 
18
12
  it "should copy install files to bin directory" do
19
- expect_any_instance_of(Bard::CLI::Install).to receive(:system).with(/cp -R .*install_files\/\* bin\//)
20
- expect_any_instance_of(Bard::CLI::Install).to receive(:system).with(/cp -R .*install_files\/\.github \.\//)
13
+ expect(cli).to receive(:system).with(/cp -R .*plugins\/install\/\* bin\//)
14
+ expect(cli).to receive(:system).with(/cp -R .*plugins\/install\/\.github \.\//)
21
15
 
22
16
  cli.install
23
17
  end
@@ -1,25 +1,11 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/master_key"
4
- require "thor"
5
3
 
6
- class TestMasterKeyCLI < Thor
7
- include Bard::CLI::MasterKey
8
-
9
- attr_reader :config, :options
10
-
11
- def initialize
12
- super
13
- @config = {}
14
- @options = {}
15
- end
16
- end
17
-
18
- describe Bard::CLI::MasterKey do
4
+ describe "bard master_key" do
19
5
  let(:from_server) { double("production") }
20
6
  let(:to_server) { double("local") }
21
7
  let(:config) { { production: from_server, local: to_server } }
22
- let(:cli) { TestMasterKeyCLI.new }
8
+ let(:cli) { Bard::CLI.new }
23
9
 
24
10
  before do
25
11
  allow(cli).to receive(:config).and_return(config)
@@ -34,7 +20,7 @@ describe Bard::CLI::MasterKey do
34
20
  allow(config).to receive(:[]).with("production").and_return(from_server)
35
21
  allow(config).to receive(:[]).with("local").and_return(to_server)
36
22
  allow(cli).to receive(:options).and_return({ from: "production", to: "local" })
37
- expect(from_server).to receive(:copy_file).with("config/master.key", to: to_server)
23
+ expect(Bard::Copy).to receive(:file).with("config/master.key", from: from_server, to: to_server)
38
24
 
39
25
  cli.master_key
40
26
  end
@@ -44,9 +30,9 @@ describe Bard::CLI::MasterKey do
44
30
  allow(config).to receive(:[]).with("production").and_return(staging_server)
45
31
  allow(config).to receive(:[]).with("local").and_return(to_server)
46
32
  allow(cli).to receive(:options).and_return({ from: "production", to: "local" })
47
- expect(staging_server).to receive(:copy_file).with("config/master.key", to: to_server)
33
+ expect(Bard::Copy).to receive(:file).with("config/master.key", from: staging_server, to: to_server)
48
34
 
49
35
  cli.master_key
50
36
  end
51
37
  end
52
- end
38
+ end
@@ -1,31 +1,15 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/open"
4
- require "thor"
5
3
 
6
- class TestOpenCLI < Thor
7
- Bard::CLI::Open.setup(self)
8
-
9
- attr_reader :config
10
-
11
- def initialize
12
- super
13
- @config = {}
14
- end
15
-
16
- def project_name
17
- "test_project"
18
- end
19
- end
20
-
21
- describe Bard::CLI::Open do
22
- let(:server) { double("server", ping: ["https://example.com"]) }
23
- let(:config) { { production: server } }
24
- let(:cli) { TestOpenCLI.new }
4
+ describe "bard open" do
5
+ let(:target) { double("target", url: "https://example.com", require_capability!: nil) }
6
+ let(:config) { { production: target } }
7
+ let(:cli) { Bard::CLI.new }
25
8
 
26
9
  before do
27
10
  allow(cli).to receive(:config).and_return(config)
28
- allow_any_instance_of(Bard::CLI::Open).to receive(:exec)
11
+ allow(cli).to receive(:project_name).and_return("test_project")
12
+ allow(cli).to receive(:exec)
29
13
  end
30
14
 
31
15
  describe "#open" do
@@ -33,37 +17,35 @@ describe Bard::CLI::Open do
33
17
  expect(cli).to respond_to(:open)
34
18
  end
35
19
 
36
- it "should open production server URL by default" do
37
- expect_any_instance_of(Bard::CLI::Open).to receive(:exec).with("xdg-open https://example.com")
20
+ it "should open production target URL by default" do
21
+ expect(cli).to receive(:exec).with("xdg-open https://example.com")
38
22
 
39
23
  cli.open
40
24
  end
41
25
 
42
- it "should open specified server URL" do
43
- staging_server = double("staging", ping: ["https://staging.example.com"])
26
+ it "should open specified target URL" do
27
+ staging_server = double("staging", url: "https://staging.example.com", require_capability!: nil)
44
28
  allow(config).to receive(:[]).with(:staging).and_return(staging_server)
45
29
 
46
- expect_any_instance_of(Bard::CLI::Open).to receive(:exec).with("xdg-open https://staging.example.com")
30
+ expect(cli).to receive(:exec).with("xdg-open https://staging.example.com")
47
31
 
48
32
  cli.open(:staging)
49
33
  end
50
34
 
51
- it "should open CI URL when server is ci" do
52
- expect_any_instance_of(Bard::CLI::Open).to receive(:exec).with("xdg-open https://github.com/botandrosedesign/test_project/actions/workflows/ci.yml")
35
+ it "should open CI URL when target is ci" do
36
+ expect(cli).to receive(:exec).with("xdg-open https://github.com/botandrosedesign/test_project/actions/workflows/ci.yml")
53
37
 
54
38
  cli.open(:ci)
55
39
  end
56
40
  end
57
41
 
58
42
  describe "#open_url" do
59
- it "returns CI URL for ci server" do
60
- command = Bard::CLI::Open.new(cli)
61
- expect(command.send(:open_url, :ci)).to eq("https://github.com/botandrosedesign/test_project/actions/workflows/ci.yml")
43
+ it "returns CI URL for ci target" do
44
+ expect(cli.open_url(:ci)).to eq("https://github.com/botandrosedesign/test_project/actions/workflows/ci.yml")
62
45
  end
63
46
 
64
- it "returns server ping URL for other servers" do
65
- command = Bard::CLI::Open.new(cli)
66
- expect(command.send(:open_url, :production)).to eq("https://example.com")
47
+ it "returns target url for other targets" do
48
+ expect(cli.open_url(:production)).to eq("https://example.com")
67
49
  end
68
50
  end
69
51
  end
@@ -1,37 +1,22 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/ping"
4
3
  require "thor"
5
4
 
6
- class TestPingCLI < Thor
7
- Bard::CLI::Ping.setup(self)
8
-
9
- attr_reader :config
10
-
11
- def initialize
12
- super
13
- @config = {}
14
- end
15
- end
16
-
17
- describe Bard::CLI::Ping do
18
- let(:server) { double("server", ping: ["https://example.com"]) }
19
- let(:config) { { production: server } }
20
- let(:cli) { TestPingCLI.new }
5
+ describe "bard ping" do
6
+ let(:target) { double("target", ping: ["https://example.com"]) }
7
+ let(:config) { double("config", targets: { production: target }) }
8
+ let(:cli) { Bard::CLI.new }
21
9
 
22
10
  before do
23
11
  allow(cli).to receive(:config).and_return(config)
24
- allow_any_instance_of(Bard::CLI::Ping).to receive(:puts)
25
- allow_any_instance_of(Bard::CLI::Ping).to receive(:exit)
12
+ allow(config).to receive(:[]).with(:production).and_return(target)
13
+ allow(cli).to receive(:puts)
14
+ allow(cli).to receive(:exit)
26
15
  end
27
16
 
28
17
  describe "#ping" do
29
- it "should have a ping command" do
30
- expect(cli).to respond_to(:ping)
31
- end
32
-
33
- it "should call Bard::Ping with the server" do
34
- expect(Bard::Ping).to receive(:call).and_return([])
18
+ it "should call Bard::Ping with the target" do
19
+ expect(Bard::Ping).to receive(:call).with(target).and_return([])
35
20
 
36
21
  cli.ping
37
22
  end
@@ -39,7 +24,7 @@ describe Bard::CLI::Ping do
39
24
  it "should print down URLs when they exist" do
40
25
  down_urls = ["https://down.example.com"]
41
26
  allow(Bard::Ping).to receive(:call).and_return(down_urls)
42
- expect_any_instance_of(Bard::CLI::Ping).to receive(:puts).with("https://down.example.com is down!")
27
+ expect(cli).to receive(:puts).with("https://down.example.com is down!")
43
28
 
44
29
  cli.ping
45
30
  end
@@ -1,23 +1,10 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/run"
4
- require "thor"
5
3
 
6
- class TestRunCLI < Thor
7
- include Bard::CLI::Run
8
-
9
- attr_reader :config
10
-
11
- def initialize
12
- super
13
- @config = {}
14
- end
15
- end
16
-
17
- describe Bard::CLI::Run do
18
- let(:server) { double("server") }
19
- let(:config) { { production: server } }
20
- let(:cli) { TestRunCLI.new }
4
+ describe "bard run" do
5
+ let(:target) { double("target") }
6
+ let(:config) { { production: target } }
7
+ let(:cli) { Bard::CLI.new }
21
8
 
22
9
  before do
23
10
  allow(cli).to receive(:config).and_return(config)
@@ -33,14 +20,14 @@ describe Bard::CLI::Run do
33
20
  expect(cli).to respond_to(:run)
34
21
  end
35
22
 
36
- it "should run command on production server" do
37
- expect(server).to receive(:run!).with("ls -la", verbose: true, home: nil)
23
+ it "should run command on production target" do
24
+ expect(target).to receive(:run!).with("ls -la", verbose: true, home: nil)
38
25
 
39
26
  cli.run("ls", "-la")
40
27
  end
41
28
 
42
29
  it "should run command on specified target" do
43
- staging_server = double("staging_server")
30
+ staging_server = double("staging_target")
44
31
  allow(cli).to receive(:config).and_return(config.merge(staging: staging_server))
45
32
  allow(cli).to receive(:options).and_return({ target: "staging" })
46
33
 
@@ -52,14 +39,14 @@ describe Bard::CLI::Run do
52
39
  it "should pass home option to target" do
53
40
  allow(cli).to receive(:options).and_return({ target: "production", home: true })
54
41
 
55
- expect(server).to receive(:run!).with("ls -la", verbose: true, home: true)
42
+ expect(target).to receive(:run!).with("ls -la", verbose: true, home: true)
56
43
 
57
44
  cli.run("ls", "-la")
58
45
  end
59
46
 
60
47
  it "should handle command errors" do
61
48
  error = Bard::Command::Error.new("Command failed")
62
- allow(server).to receive(:run!).and_raise(error)
49
+ allow(target).to receive(:run!).and_raise(error)
63
50
 
64
51
  expect(cli).to receive(:puts).with(/Running command failed/)
65
52
  expect(cli).to receive(:exit).with(1)
@@ -67,4 +54,4 @@ describe Bard::CLI::Run do
67
54
  cli.run("failing-command")
68
55
  end
69
56
  end
70
- end
57
+ end
@@ -1,27 +1,11 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/setup"
4
- require "thor"
5
3
 
6
- class TestSetupCLI < Thor
7
- include Bard::CLI::Setup
8
-
9
- attr_reader :config
10
-
11
- def initialize
12
- super
13
- @config = {}
14
- end
15
-
16
- def project_name
17
- "test_project"
18
- end
19
- end
20
-
21
- describe Bard::CLI::Setup do
22
- let(:cli) { TestSetupCLI.new }
4
+ describe "bard setup" do
5
+ let(:cli) { Bard::CLI.new }
23
6
 
24
7
  before do
8
+ allow(cli).to receive(:project_name).and_return("test_project")
25
9
  allow(Dir).to receive(:pwd).and_return("/home/user/project")
26
10
  allow(File).to receive(:exist?).and_return(false)
27
11
  allow(cli).to receive(:system)
@@ -32,9 +16,8 @@ describe Bard::CLI::Setup do
32
16
  expect(cli).to respond_to(:setup)
33
17
  end
34
18
 
35
- it "should create nginx common config" do
36
- expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/snippets\/common\.conf/)
37
- expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project/)
19
+ it "should create nginx reverse proxy config" do
20
+ expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project.*proxy_pass http:\/\/puma/m)
38
21
  expect(cli).to receive(:system).with(/sudo ln -sf/)
39
22
  expect(cli).to receive(:system).with("sudo service nginx restart")
40
23
 
@@ -43,7 +26,7 @@ describe Bard::CLI::Setup do
43
26
  end
44
27
 
45
28
  describe "#nginx_server_name" do
46
- let(:production_server) { double("production", ping: ["https://example.com"]) }
29
+ let(:production_server) { double("production", url: "https://example.com") }
47
30
 
48
31
  before do
49
32
  allow(cli).to receive(:config).and_return({ production: production_server })
@@ -53,7 +36,7 @@ describe Bard::CLI::Setup do
53
36
  before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("production") }
54
37
 
55
38
  it "returns production server names with wildcard" do
56
- expect(cli.send(:nginx_server_name)).to eq("*.example.com _")
39
+ expect(cli.nginx_server_name).to eq("*.example.com _")
57
40
  end
58
41
  end
59
42
 
@@ -61,7 +44,7 @@ describe Bard::CLI::Setup do
61
44
  before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("staging") }
62
45
 
63
46
  it "returns staging server name" do
64
- expect(cli.send(:nginx_server_name)).to eq("test_project.botandrose.com")
47
+ expect(cli.nginx_server_name).to eq("test_project.botandrose.com")
65
48
  end
66
49
  end
67
50
 
@@ -69,8 +52,8 @@ describe Bard::CLI::Setup do
69
52
  before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("development") }
70
53
 
71
54
  it "returns localhost server name" do
72
- expect(cli.send(:nginx_server_name)).to eq("test_project.localhost")
55
+ expect(cli.nginx_server_name).to eq("test_project.localhost")
73
56
  end
74
57
  end
75
58
  end
76
- end
59
+ end
@@ -1,27 +1,14 @@
1
1
  require "spec_helper"
2
2
  require "bard/cli"
3
- require "bard/cli/ssh"
4
- require "thor"
5
3
 
6
- class TestSSHCLI < Thor
7
- include Bard::CLI::SSH
8
-
9
- attr_reader :config, :options
10
-
11
- def initialize
12
- super
13
- @config = {}
14
- @options = {}
15
- end
16
- end
17
-
18
- describe Bard::CLI::SSH do
19
- let(:server) { double("server") }
20
- let(:config) { { production: server } }
21
- let(:cli) { TestSSHCLI.new }
4
+ describe "bard ssh" do
5
+ let(:target) { double("target") }
6
+ let(:config) { { production: target } }
7
+ let(:cli) { Bard::CLI.new }
22
8
 
23
9
  before do
24
10
  allow(cli).to receive(:config).and_return(config)
11
+ allow(cli).to receive(:options).and_return({ home: false })
25
12
  end
26
13
 
27
14
  describe "#ssh" do
@@ -29,27 +16,25 @@ describe Bard::CLI::SSH do
29
16
  expect(cli).to respond_to(:ssh)
30
17
  end
31
18
 
32
- it "should execute shell on production server by default" do
33
- allow(cli).to receive(:options).and_return({ home: false })
34
- expect(server).to receive(:exec!).with("exec $SHELL -l", home: false)
19
+ it "should execute shell on production target by default" do
20
+ expect(target).to receive(:exec!).with("exec $SHELL -l", home: false)
35
21
 
36
22
  cli.ssh
37
23
  end
38
24
 
39
25
  it "should execute shell with home option when specified" do
40
26
  allow(cli).to receive(:options).and_return({ home: true })
41
- expect(server).to receive(:exec!).with("exec $SHELL -l", home: true)
27
+ expect(target).to receive(:exec!).with("exec $SHELL -l", home: true)
42
28
 
43
29
  cli.ssh
44
30
  end
45
31
 
46
- it "should connect to specified server" do
32
+ it "should connect to specified target" do
47
33
  staging_server = double("staging")
48
34
  allow(config).to receive(:[]).with(:staging).and_return(staging_server)
49
- allow(cli).to receive(:options).and_return({ home: false })
50
35
  expect(staging_server).to receive(:exec!).with("exec $SHELL -l", home: false)
51
36
 
52
37
  cli.ssh(:staging)
53
38
  end
54
39
  end
55
- end
40
+ end