File: assertions.rb

package info (click to toggle)
capistrano 3.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 820 kB
  • sloc: ruby: 5,351; makefile: 5
file content (162 lines) | stat: -rw-r--r-- 5,058 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
require "shellwords"

Then(/^references in the remote repo are listed$/) do
  expect(@output).to include("refs/heads/master")
end

Then(/^git wrapper permissions are 0700$/) do
  permissions_test = %Q([ $(stat -c "%a" #{TestApp.git_wrapper_path_glob}) == "700" ])
  expect { run_remote_ssh_command(permissions_test) }.not_to raise_error
end

Then(/^the shared path is created$/) do
  run_remote_ssh_command(test_dir_exists(TestApp.shared_path))
end

Then(/^the releases path is created$/) do
  run_remote_ssh_command(test_dir_exists(TestApp.releases_path))
end

Then(/^(\d+) valid releases are kept/) do |num|
  test = %Q([ $(ls -g #{TestApp.releases_path} | grep -E '[0-9]{14}' | wc -l) == "#{num}" ])
  expect { run_remote_ssh_command(test) }.not_to raise_error
end

Then(/^the invalid (.+) release is ignored$/) do |filename|
  test = "ls -g #{TestApp.releases_path} | grep #{filename}"
  expect { run_remote_ssh_command(test) }.not_to raise_error
end

Then(/^directories in :linked_dirs are created in shared$/) do
  TestApp.linked_dirs.each do |dir|
    run_remote_ssh_command(test_dir_exists(TestApp.shared_path.join(dir)))
  end
end

Then(/^directories referenced in :linked_files are created in shared$/) do
  dirs = TestApp.linked_files.map { |path| TestApp.shared_path.join(path).dirname }
  dirs.each do |dir|
    run_remote_ssh_command(test_dir_exists(dir))
  end
end

Then(/^the repo is cloned$/) do
  run_remote_ssh_command(test_dir_exists(TestApp.repo_path))
end

Then(/^the release is created$/) do
  stdout, _stderr = run_remote_ssh_command("ls #{TestApp.releases_path}")

  expect(stdout.strip).to match(/\A#{Time.now.utc.strftime("%Y%m%d")}\d{6}\Z/)
end

Then(/^the REVISION file is created in the release$/) do
  stdout, _stderr = run_remote_ssh_command("cat #{@release_paths[0]}/REVISION")

  expect(stdout.strip).to match(/\h{40}/)
end

Then(/^the REVISION_TIME file is created in the release$/) do
  stdout, _stderr = run_remote_ssh_command("cat #{@release_paths[0]}/REVISION_TIME")

  expect(stdout.strip).to match(/\d{10}/)
end

Then(/^file symlinks are created in the new release$/) do
  TestApp.linked_files.each do |file|
    run_remote_ssh_command(test_symlink_exists(TestApp.current_path.join(file)))
  end
end

Then(/^directory symlinks are created in the new release$/) do
  pending
  TestApp.linked_dirs.each do |dir|
    run_remote_ssh_command(test_symlink_exists(TestApp.release_path.join(dir)))
  end
end

Then(/^the current directory will be a symlink to the release$/) do
  run_remote_ssh_command(exists?("e", TestApp.current_path))
end

Then(/^the deploy\.rb file is created$/) do
  file = TestApp.test_app_path.join("config/deploy.rb")
  expect(File.exist?(file)).to be true
end

Then(/^the default stage files are created$/) do
  staging = TestApp.test_app_path.join("config/deploy/staging.rb")
  production = TestApp.test_app_path.join("config/deploy/production.rb")
  expect(File.exist?(staging)).to be true
  expect(File.exist?(production)).to be true
end

Then(/^the tasks folder is created$/) do
  path = TestApp.test_app_path.join("lib/capistrano/tasks")
  expect(Dir.exist?(path)).to be true
end

Then(/^the specified stage files are created$/) do
  qa = TestApp.test_app_path.join("config/deploy/qa.rb")
  production = TestApp.test_app_path.join("config/deploy/production.rb")
  expect(File.exist?(qa)).to be true
  expect(File.exist?(production)).to be true
end

Then(/^it creates the file with the remote_task prerequisite$/) do
  TestApp.linked_files.each do |file|
    run_remote_ssh_command(test_file_exists(TestApp.shared_path.join(file)))
  end
end

Then(/^it will not recreate the file$/) do
  #
end

Then(/^the task is successful$/) do
  expect(@success).to be true
end

Then(/^the task fails$/) do
  expect(@success).to be_falsey
end

Then(/^the failure task will run$/) do
  failed = TestApp.shared_path.join("failed")
  run_remote_ssh_command(test_file_exists(failed))
end

Then(/^the failure task will not run$/) do
  failed = TestApp.shared_path.join("failed")
  expect { run_remote_ssh_command(test_file_exists(failed)) }
    .to raise_error(RemoteSSHHelpers::RemoteSSHCommandError)
end

When(/^an error is raised$/) do
  error = TestApp.shared_path.join("fail")
  run_remote_ssh_command(test_file_exists(error))
end

Then(/contains "([^"]*)" in the output/) do |expected|
  expect(@output).to include(expected)
end

Then(/the output matches "([^"]*)" followed by "([^"]*)"/) do |expected, followedby|
  expect(@output).to match(/#{expected}.*#{followedby}/m)
end

Then(/doesn't contain "([^"]*)" in the output/) do |expected|
  expect(@output).not_to include(expected)
end

Then(/the current symlink points to the previous release/) do
  previous_release_path = @release_paths[-2]

  run_remote_ssh_command(symlinked?(TestApp.current_path, previous_release_path))
end

Then(/^the current symlink points to that specific release$/) do
  specific_release_path = TestApp.releases_path.join(@rollback_release)

  run_remote_ssh_command(symlinked?(TestApp.current_path, specific_release_path))
end