boxen 3.0.0.beta1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -1
  3. data/README.md +1 -1
  4. data/boxen.gemspec +13 -13
  5. data/lib/boxen/check.rb +39 -8
  6. data/lib/boxen/cli.rb +45 -19
  7. data/lib/boxen/config.rb +61 -43
  8. data/lib/boxen/flags.rb +282 -0
  9. data/lib/boxen/hook.rb +8 -15
  10. data/lib/boxen/hook/github_issue.rb +120 -0
  11. data/lib/boxen/hook/web.rb +56 -0
  12. data/lib/boxen/keychain.rb +1 -1
  13. data/lib/boxen/postflight/env.rb +1 -1
  14. data/lib/boxen/preflight.rb +7 -4
  15. data/lib/boxen/preflight/creds.rb +47 -8
  16. data/lib/boxen/preflight/identity.rb +0 -2
  17. data/lib/boxen/preflight/os.rb +6 -2
  18. data/lib/boxen/puppeteer.rb +121 -0
  19. data/lib/boxen/runner.rb +149 -0
  20. data/script/bootstrap +1 -1
  21. data/script/tests +0 -1
  22. data/test/boxen/test.rb +1 -1
  23. data/test/boxen_check_test.rb +55 -0
  24. data/test/boxen_cli_test.rb +31 -8
  25. data/test/boxen_config_test.rb +31 -1
  26. data/test/boxen_directories_test.rb +4 -4
  27. data/test/boxen_flags_test.rb +217 -0
  28. data/test/{postflight/boxen_postflight_github_issue_test.rb → boxen_hook_github_issue_test.rb} +82 -72
  29. data/test/{postflight/boxen_postflight_web_hook_test.rb → boxen_hook_web_test.rb} +11 -12
  30. data/test/{postflight/boxen_postflight_active_test.rb → boxen_postflight_active_test.rb} +3 -3
  31. data/test/{postflight/boxen_postflight_env_test.rb → boxen_postflight_env_test.rb} +0 -0
  32. data/test/boxen_preflight_creds_test.rb +177 -0
  33. data/test/{preflight/boxen_preflight_etc_my_cnf_test.rb → boxen_preflight_etc_my_cnf_test.rb} +1 -1
  34. data/test/{preflight/boxen_preflight_rvm_test.rb → boxen_preflight_rvm_test.rb} +1 -1
  35. data/test/boxen_puppeteer_test.rb +101 -0
  36. data/test/boxen_runner_test.rb +171 -0
  37. metadata +172 -251
  38. data/lib/boxen/command.rb +0 -142
  39. data/lib/boxen/command/help.rb +0 -40
  40. data/lib/boxen/command/preflight.rb +0 -38
  41. data/lib/boxen/command/project.rb +0 -49
  42. data/lib/boxen/command/project/install.rb +0 -33
  43. data/lib/boxen/command/run.rb +0 -199
  44. data/lib/boxen/command/service.rb +0 -61
  45. data/lib/boxen/command/service/disable.rb +0 -15
  46. data/lib/boxen/command/service/enable.rb +0 -15
  47. data/lib/boxen/command/service/restart.rb +0 -24
  48. data/lib/boxen/command/version.rb +0 -29
  49. data/lib/boxen/command_status.rb +0 -15
  50. data/lib/boxen/postflight/github_issue.rb +0 -124
  51. data/lib/boxen/postflight/hooks.rb +0 -16
  52. data/lib/boxen/postflight/web_hook.rb +0 -63
  53. data/lib/boxen/preflight/facts.rb +0 -36
  54. data/lib/boxen/preflight/homebrew.rb +0 -13
  55. data/lib/boxen/preflight/offline.rb +0 -33
  56. data/lib/boxen/preflight/update.rb +0 -109
  57. data/lib/boxen/util/logging.rb +0 -59
  58. data/lib/boxen/version.rb +0 -3
  59. data/lib/system_timer.rb +0 -13
  60. data/test/boxen_command_test.rb +0 -93
  61. data/test/boxen_hook_test.rb +0 -25
  62. data/test/command/help_test.rb +0 -49
  63. data/test/command/project/install_test.rb +0 -34
  64. data/test/command/project_test.rb +0 -32
  65. data/test/command/run_test.rb +0 -21
  66. data/test/command/service/disable_test.rb +0 -49
  67. data/test/command/service/enable_test.rb +0 -49
  68. data/test/command/service/restart_test.rb +0 -53
  69. data/test/command/service_test.rb +0 -55
  70. data/test/command/version_test.rb +0 -15
  71. data/test/preflight/boxen_preflight_creds_test.rb +0 -82
  72. data/test/preflight/boxen_preflight_homebrew_test.rb +0 -10
  73. data/test/system_timer.rb +0 -10
@@ -4,4 +4,4 @@
4
4
  cd "$(dirname $0)"/..
5
5
 
6
6
  rm -f .bundle/config
7
- bundle install --binstubs .bundle/bin --path .bundle --quiet
7
+ bundle install --binstubs bin --path .bundle --quiet
@@ -6,6 +6,5 @@ cd "$(dirname $0)"/..
6
6
  script/bootstrap &&
7
7
  ruby -rubygems -Ilib:test \
8
8
  -e 'require "bundler/setup"' \
9
- -e 'require "minitest/autorun"' \
10
9
  -e 'tests = ARGV.empty? ? Dir["test/**/*_test.rb"] : ARGV' \
11
10
  -e 'tests.each { |f| load f }' "$@"
@@ -2,6 +2,6 @@ require "minitest/autorun"
2
2
  require "mocha/setup"
3
3
 
4
4
  module Boxen
5
- class Test < MiniTest::Test
5
+ class Test < MiniTest::Unit::TestCase
6
6
  end
7
7
  end
@@ -0,0 +1,55 @@
1
+ require "boxen/test"
2
+ require "boxen/check"
3
+
4
+ class BoxenCheckTest < Boxen::Test
5
+ def test_initialize
6
+ check = Boxen::Check.new :config
7
+ assert_equal :config, check.config
8
+ end
9
+
10
+ def test_ok?
11
+ ex = assert_raises RuntimeError do
12
+ Boxen::Check.new(:config).ok?
13
+ end
14
+
15
+ assert_match "must implement", ex.message
16
+ end
17
+
18
+ def test_run
19
+ ex = assert_raises RuntimeError do
20
+ Boxen::Check.new(:config).run
21
+ end
22
+
23
+ assert_match "must implement", ex.message
24
+ end
25
+
26
+ def test_self_checks
27
+ subclass = Class.new Boxen::Check
28
+ Boxen::Check.const_set :TestCheck, subclass
29
+
30
+ assert Boxen::Check.checks(:config).any? { |c| subclass === c },
31
+ "an instance of TestCheck exists in checks"
32
+ end
33
+
34
+ def test_self_checks_subclasses
35
+ klass = Struct.new :config
36
+ Boxen::Check.const_set :TestBadCheck, klass
37
+
38
+ refute Boxen::Check.checks(:config).any? { |c| klass === c },
39
+ "checks are subclasses of Boxen::Check"
40
+ end
41
+
42
+ def test_self_run
43
+ willrun = mock do
44
+ expects(:ok?).returns false
45
+ expects(:run)
46
+ end
47
+
48
+ wontrun = mock do
49
+ expects(:ok?).returns true
50
+ end
51
+
52
+ Boxen::Check.expects(:checks).with(:config).returns [willrun, wontrun]
53
+ Boxen::Check.run :config
54
+ end
55
+ end
@@ -1,16 +1,39 @@
1
+ require "boxen/test"
1
2
  require "boxen/cli"
2
3
 
3
- require "boxen/command_status"
4
+ class BoxenCLITest < Boxen::Test
5
+ def setup
6
+ @config = Boxen::Config.new
7
+ @flags = Boxen::Flags.new
8
+ @cli = Boxen::CLI.new(@config, @flags)
9
+ end
10
+
11
+ def test_initialize
12
+ config = Boxen::Config.new
13
+ flags = Boxen::Flags.new
14
+
15
+ cli = Boxen::CLI.new config, flags
4
16
 
5
- describe Boxen::CLI do
17
+ assert_equal config, cli.config
18
+ assert_equal flags, cli.flags
6
19
 
7
- it "is a fancy way of reinvoking commands at this time" do
8
- config = mock("config")
9
- Boxen::Config.expects(:load).returns(config)
10
- Boxen::Command.expects(:invoke).with("foo", config).
11
- returns(Boxen::CommandStatus.new(0))
20
+ assert_equal config, cli.runner.config
21
+ assert_equal flags, cli.runner.flags
22
+ end
12
23
 
13
- Boxen::CLI.run("foo")
24
+ def test_run
25
+ @cli.runner.expects(:run)
26
+ @cli.run
14
27
  end
15
28
 
29
+ def test_help
30
+ $stdout.stubs(:write)
31
+
32
+ flags = Boxen::Flags.new('--help')
33
+ cli = Boxen::CLI.new(@config, flags)
34
+ cli.runner.expects(:run).never
35
+ assert_raises SystemExit do
36
+ cli.run
37
+ end
38
+ end
16
39
  end
@@ -7,6 +7,13 @@ class BoxenConfigTest < Boxen::Test
7
7
  @config.repodir = "test/fixtures/repo"
8
8
  end
9
9
 
10
+ def test_debug?
11
+ refute @config.debug?
12
+
13
+ @config.debug = true
14
+ assert @config.debug?
15
+ end
16
+
10
17
  def test_email
11
18
  assert_nil @config.email
12
19
 
@@ -89,6 +96,27 @@ class BoxenConfigTest < Boxen::Test
89
96
  assert_equal "foo", @config.name
90
97
  end
91
98
 
99
+ def test_pretend?
100
+ refute @config.pretend?
101
+
102
+ @config.pretend = true
103
+ assert @config.pretend?
104
+ end
105
+
106
+ def test_profile?
107
+ refute @config.profile?
108
+
109
+ @config.profile = true
110
+ assert @config.profile?
111
+ end
112
+
113
+ def test_future_parser?
114
+ refute @config.future_parser?
115
+
116
+ @config.future_parser = true
117
+ assert @config.future_parser?
118
+ end
119
+
92
120
  def test_projects
93
121
  files = Dir["#{@config.repodir}/modules/projects/manifests/*.pp"]
94
122
  assert_equal files.size, @config.projects.size
@@ -296,6 +324,8 @@ class BoxenConfigTest < Boxen::Test
296
324
  end
297
325
 
298
326
  def test_token
327
+ assert_nil @config.token
328
+
299
329
  @config.token = "foo"
300
330
  assert_equal "foo", @config.token
301
331
  end
@@ -352,7 +382,7 @@ class BoxenConfigTest < Boxen::Test
352
382
  ENV["BOXEN_S3_BUCKET"] = val
353
383
  end
354
384
 
355
- def test_s3bucket_env_var
385
+ def test_s3host_env_var
356
386
  val = ENV["BOXEN_S3_BUCKET"]
357
387
 
358
388
  ENV["BOXEN_S3_BUCKET"] = "my-bucket"
@@ -12,25 +12,25 @@ class BoxenPreflightDirectoriesTest < Boxen::Test
12
12
  end
13
13
 
14
14
  def test_not_okay_if_homedir_group_wrong
15
- directories = Boxen::Preflight::Directories.new(@config, :command)
15
+ directories = Boxen::Preflight::Directories.new(@config)
16
16
  directories.stubs(:homedir_group).returns(false)
17
17
  refute directories.ok?
18
18
  end
19
19
 
20
20
  def test_not_okay_if_homedir_owner_wrong
21
- directories = Boxen::Preflight::Directories.new(@config, :command)
21
+ directories = Boxen::Preflight::Directories.new(@config)
22
22
  directories.stubs(:homedir_owner).returns(false)
23
23
  refute directories.ok?
24
24
  end
25
25
 
26
26
  def test_not_okay_unless_homedir_exists
27
- directories = Boxen::Preflight::Directories.new(@config, :command)
27
+ directories = Boxen::Preflight::Directories.new(@config)
28
28
  directories.stubs(:homedir_directory_exists?).returns(false)
29
29
  refute directories.ok?
30
30
  end
31
31
 
32
32
  def test_okay_if_allchecks_fine
33
- directories = Boxen::Preflight::Directories.new(@config, :command)
33
+ directories = Boxen::Preflight::Directories.new(@config)
34
34
  directories.stubs(:homedir_directory_exists?).returns(true)
35
35
  directories.stubs(:homedir_owner).returns("foobar")
36
36
  directories.stubs(:homedir_group).returns("staff")
@@ -0,0 +1,217 @@
1
+ require "boxen/test"
2
+ require "boxen/flags"
3
+
4
+ class BoxenFlagsTest < Boxen::Test
5
+ def test_apply
6
+ config = mock do
7
+ expects(:debug=).with true
8
+
9
+ stubs(:fde?).returns true
10
+ expects(:fde=).with false
11
+
12
+ expects(:homedir=).with "homedir"
13
+ expects(:logfile=).with "logfile"
14
+ expects(:login=).with "login"
15
+ expects(:token=).with "token"
16
+ expects(:pretend=).with true
17
+ expects(:profile=).with true
18
+ expects(:future_parser=).with true
19
+ expects(:report=).with true
20
+ expects(:graph=).with true
21
+ expects(:srcdir=).with "srcdir"
22
+ expects(:stealth=).with true
23
+ expects(:user=).with "user"
24
+ expects(:color=).with true
25
+ end
26
+
27
+ # Do our best to frob every switch.
28
+
29
+ flags = Boxen::Flags.new "--debug", "--help", "--login", "login",
30
+ "--no-fde", "--no-pull", "--no-issue", "--noop",
31
+ "--pretend", "--profile", "--future-parser", "--report", "--graph", "--projects",
32
+ "--user", "user", "--homedir", "homedir", "--srcdir", "srcdir",
33
+ "--logfile", "logfile", "--token", "token"
34
+
35
+ assert_same config, flags.apply(config)
36
+ end
37
+
38
+ def test_args
39
+ config = flags "--debug", "foo"
40
+ assert_equal %w(foo), config.args
41
+ end
42
+
43
+ def test_debug
44
+ refute flags.debug?
45
+ assert flags("--debug").debug?
46
+ end
47
+
48
+ def test_env?
49
+ refute flags.env?
50
+ assert flags("--env").env?
51
+ end
52
+
53
+ def test_help
54
+ refute flags.help?
55
+
56
+ %w(--help -h -?).each do |flag|
57
+ assert flags(flag).help?
58
+ end
59
+ end
60
+
61
+ def test_disable_services?
62
+ refute flags.disable_services?
63
+ assert flags("--disable-services").disable_services?
64
+ end
65
+
66
+ def test_enable_services?
67
+ refute flags.enable_services?
68
+ assert flags("--enable-services").enable_services?
69
+ end
70
+
71
+ def test_list_services?
72
+ refute flags.list_services?
73
+ assert flags("--list-services").list_services?
74
+ end
75
+
76
+ def test_homedir
77
+ assert_nil flags.homedir
78
+ assert_equal "foo", flags("--homedir", "foo").homedir
79
+ end
80
+
81
+ def test_initialize_bad_option
82
+ ex = assert_raises Boxen::Error do
83
+ flags "--bad-option"
84
+ end
85
+
86
+ assert_match "invalid option", ex.message
87
+ assert_match "--bad-option", ex.message
88
+ end
89
+
90
+ def test_initialize_dups
91
+ args = %w(foo)
92
+ config = flags args
93
+
94
+ assert_equal args, config.args
95
+ refute_same args, config.args
96
+ end
97
+
98
+ def test_initialize_empty
99
+ config = flags
100
+ assert_equal [], config.args
101
+ end
102
+
103
+ def test_initialize_flattens
104
+ config = flags "foo", ["bar"]
105
+ assert_equal %w(foo bar), config.args
106
+ end
107
+
108
+ def test_initialize_nils
109
+ config = flags "foo", nil, "bar"
110
+ assert_equal %w(foo bar), config.args
111
+ end
112
+
113
+ def test_initialize_strings
114
+ config = flags :foo, [:bar]
115
+ assert_equal %w(foo bar), config.args
116
+ end
117
+
118
+ def test_logfile
119
+ assert_nil flags.logfile
120
+ assert_equal "foo", flags("--logfile", "foo").logfile
121
+ end
122
+
123
+ def test_login
124
+ assert_nil flags.login
125
+ assert_equal "jbarnette", flags("--login", "jbarnette").login
126
+ end
127
+
128
+ def test_no_fde
129
+ assert flags.fde?
130
+ refute flags("--no-fde").fde?
131
+ end
132
+
133
+ def test_no_pull_is_a_noop
134
+ flags "--no-pull"
135
+ end
136
+
137
+ def test_parse
138
+ config = flags
139
+ config.parse "--debug", "foo"
140
+
141
+ assert config.debug?
142
+ assert_equal %w(foo), config.args
143
+ end
144
+
145
+ def test_token
146
+ assert_nil flags.token
147
+ assert_equal "foo", flags("--token", "foo").token
148
+ end
149
+
150
+ def test_token_missing_value
151
+ ex = assert_raises Boxen::Error do
152
+ flags "--token"
153
+ end
154
+
155
+ assert_match "missing argument", ex.message
156
+ end
157
+
158
+ def test_pretend
159
+ refute flags.pretend?
160
+ assert flags("--noop").pretend?
161
+ assert flags("--pretend").pretend?
162
+ end
163
+
164
+ def test_profile
165
+ refute flags.profile?
166
+ assert flags("--profile").profile?
167
+ end
168
+
169
+ def test_future_parser
170
+ refute flags.future_parser?
171
+ assert flags("--future-parser").future_parser?
172
+ end
173
+
174
+ def test_report
175
+ refute flags.report?
176
+ assert flags("--report").report?
177
+ end
178
+
179
+ def test_graph
180
+ refute flags.graph?
181
+ assert flags("--graph").graph?
182
+ end
183
+
184
+ def test_projects
185
+ refute flags.projects?
186
+ assert flags("--projects").projects?
187
+ end
188
+
189
+ def test_srcdir
190
+ assert_nil flags.srcdir
191
+ assert_equal "foo", flags("--srcdir", "foo").srcdir
192
+ end
193
+
194
+ def test_stealth
195
+ refute flags.stealth?
196
+ assert flags("--no-issue").stealth?
197
+ assert flags("--stealth").stealth?
198
+ end
199
+
200
+ def test_user
201
+ assert_equal "jbarnette", flags("--user", "jbarnette").user
202
+ end
203
+
204
+ def test_user_missing_value
205
+ ex = assert_raises Boxen::Error do
206
+ flags "--user"
207
+ end
208
+
209
+ assert_match "missing argument", ex.message
210
+ end
211
+
212
+ # Create an instance of Boxen::Flags with optional `args`.
213
+
214
+ def flags(*args)
215
+ Boxen::Flags.new *args
216
+ end
217
+ end
@@ -1,54 +1,57 @@
1
- require 'boxen/test'
2
- require 'boxen/postflight'
3
- require 'boxen/postflight/github_issue'
1
+ require "boxen/test"
2
+ require "boxen/hook/github_issue"
4
3
 
5
4
  class Boxen::Config
6
5
  attr_writer :api
7
6
  end
8
7
 
9
- class Boxen::Postflight::GithubIssue < Boxen::Postflight
10
- attr_writer :checkout
11
- end
12
-
13
- class BoxenPostflightGithubIssueTest < Boxen::Test
8
+ class BoxenHookGitHubIssueTest < Boxen::Test
14
9
  def setup
15
10
  @config = Boxen::Config.new
16
11
  @checkout = Boxen::Checkout.new(@config)
17
- @command = stub 'command', :success? => true
18
- @check = Boxen::Postflight::GithubIssue.new @config, @command
19
- @check.checkout = @checkout
12
+ @puppet = mock 'puppeteer'
13
+ @result = stub 'result', :success? => true
14
+ @hook = Boxen::Hook::GitHubIssue.new @config, @checkout, @puppet, @result
20
15
  end
21
16
 
22
17
  def test_enabled
23
18
  original = ENV['BOXEN_ISSUES_ENABLED']
24
19
 
25
20
  ENV['BOXEN_ISSUES_ENABLED'] = nil
26
- refute @check.enabled?
21
+ refute @hook.enabled?
27
22
 
28
23
  ENV['BOXEN_ISSUES_ENABLED'] = 'duh'
29
- assert @check.enabled?
24
+ assert @hook.enabled?
30
25
 
31
26
  ENV['BOXEN_ISSUES_ENABLED'] = original
32
27
  end
33
28
 
34
- def test_ok
35
- @check.stubs(:enabled?).returns(false)
29
+ def test_perform
30
+ @hook.stubs(:enabled?).returns(false)
31
+ @config.stubs(:stealth?).returns(true)
32
+ @config.stubs(:pretend?).returns(true)
36
33
  @checkout.stubs(:master?).returns(false)
37
34
  @config.stubs(:login).returns(nil)
38
35
 
39
- assert @check.ok?
36
+ refute @hook.perform?
37
+
38
+ @hook.stubs(:enabled?).returns(true)
39
+ refute @hook.perform?
40
40
 
41
- @check.stubs(:enabled?).returns(true)
42
- assert @check.ok?
41
+ @config.stubs(:stealth?).returns(false)
42
+ refute @hook.perform?
43
+
44
+ @config.stubs(:pretend?).returns(false)
45
+ refute @hook.perform?
43
46
 
44
47
  @checkout.stubs(:master?).returns(true)
45
- assert @check.ok?
48
+ refute @hook.perform?
46
49
 
47
50
  @config.stubs(:login).returns('')
48
- assert @check.ok?
51
+ refute @hook.perform?
49
52
 
50
53
  @config.stubs(:login).returns('somelogin')
51
- refute @check.ok?
54
+ assert @hook.perform?
52
55
  end
53
56
 
54
57
  def test_compare_url
@@ -57,7 +60,7 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
57
60
  @checkout.expects(:sha).returns(sha)
58
61
 
59
62
  expected = "https://github.com/#{repo}/compare/#{sha}...master"
60
- assert_equal expected, @check.compare_url
63
+ assert_equal expected, @hook.compare_url
61
64
  end
62
65
 
63
66
  def test_compare_url_ghurl
@@ -67,102 +70,108 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
67
70
  @checkout.expects(:sha).returns(sha)
68
71
 
69
72
  expected = "https://git.foo.com/#{repo}/compare/#{sha}...master"
70
- assert_equal expected, @check.compare_url
73
+ assert_equal expected, @hook.compare_url
71
74
  end
72
75
 
73
76
  def test_hostname
74
- Socket.expects(:gethostname).returns("whatevs.local")
75
- assert_equal "whatevs.local", @check.hostname
77
+ @hook.expects(:"`").with("hostname").returns "whatevs.local\n"
78
+ assert_equal "whatevs.local", @hook.hostname
76
79
  end
77
80
 
78
81
  def test_initialize
79
- check = Boxen::Postflight::GithubIssue.new :config, :command
80
- assert_equal :config, check.config
81
- assert_equal :command, check.command
82
+ hook = Boxen::Hook::GitHubIssue.new :config, :checkout, :puppet, :result
83
+ assert_equal :config, hook.config
84
+ assert_equal :checkout, hook.checkout
85
+ assert_equal :puppet, hook.puppet
86
+ assert_equal :result, hook.result
82
87
  end
83
88
 
84
89
  def test_os
85
- @check.expects(:"`").with("sw_vers -productVersion").returns "11.1.1\n"
86
- assert_equal "11.1.1", @check.os
90
+ @hook.expects(:"`").with("sw_vers -productVersion").returns "11.1.1\n"
91
+ assert_equal "11.1.1", @hook.os
87
92
  end
88
93
 
89
94
  def test_shell
90
95
  val = ENV['SHELL']
91
96
 
92
97
  ENV['SHELL'] = '/bin/crush'
93
- assert_equal "/bin/crush", @check.shell
98
+ assert_equal "/bin/crush", @hook.shell
94
99
 
95
100
  ENV['SHELL'] = val
96
101
  end
97
102
 
98
103
  def test_record_failure
99
- @check.stubs(:issues?).returns(true)
104
+ @hook.stubs(:issues?).returns(true)
100
105
 
101
106
  details = 'Everything went wrong.'
102
- @check.stubs(:failure_details).returns(details)
107
+ @hook.stubs(:failure_details).returns(details)
103
108
 
104
109
  @config.reponame = repo = 'some/repo'
105
110
  @config.user = user = 'hapless'
106
111
 
107
- @check.failure_label = label = 'boom'
112
+ @hook.failure_label = label = 'boom'
108
113
 
109
114
  @config.api = api = mock('api')
110
115
  api.expects(:create_issue).with(repo, "Failed for #{user}", details, :labels => [label])
111
116
 
112
- @check.record_failure
117
+ @hook.record_failure
113
118
  end
114
119
 
115
120
  def test_record_failure_no_issues
116
- @check.stubs(:issues?).returns(false)
121
+ @hook.stubs(:issues?).returns(false)
117
122
 
118
123
  @config.api = api = mock('api')
119
124
  api.expects(:create_issue).never
120
125
 
121
- @check.record_failure
126
+ @hook.record_failure
122
127
  end
123
128
 
124
129
  def test_failure_label
125
130
  default = 'failure'
126
- assert_equal default, @check.failure_label
131
+ assert_equal default, @hook.failure_label
127
132
 
128
- @check.failure_label = label = 'oops'
129
- assert_equal label, @check.failure_label
133
+ @hook.failure_label = label = 'oops'
134
+ assert_equal label, @hook.failure_label
130
135
 
131
- @check.failure_label = nil
132
- assert_equal default, @check.failure_label
136
+ @hook.failure_label = nil
137
+ assert_equal default, @hook.failure_label
133
138
  end
134
139
 
135
140
  def test_ongoing_label
136
141
  default = 'ongoing'
137
- assert_equal default, @check.ongoing_label
142
+ assert_equal default, @hook.ongoing_label
138
143
 
139
- @check.ongoing_label = label = 'checkit'
140
- assert_equal label, @check.ongoing_label
144
+ @hook.ongoing_label = label = 'checkit'
145
+ assert_equal label, @hook.ongoing_label
141
146
 
142
- @check.ongoing_label = nil
143
- assert_equal default, @check.ongoing_label
147
+ @hook.ongoing_label = nil
148
+ assert_equal default, @hook.ongoing_label
144
149
  end
145
150
 
146
151
  def test_failure_details
147
152
  sha = 'decafbad'
148
153
  @checkout.stubs(:sha).returns(sha)
149
154
  hostname = 'cools.local'
150
- @check.stubs(:hostname).returns(hostname)
155
+ @hook.stubs(:hostname).returns(hostname)
151
156
  shell = '/bin/ksh'
152
- @check.stubs(:shell).returns(shell)
157
+ @hook.stubs(:shell).returns(shell)
153
158
  os = '11.1.1'
154
- @check.stubs(:os).returns(os)
159
+ @hook.stubs(:os).returns(os)
155
160
  log = "so\nmany\nthings\nto\nreport"
156
- @check.stubs(:logfile).returns(log)
161
+ @hook.stubs(:log).returns(log)
157
162
 
158
- @config.reponame = 'some/repo'
159
- compare = @check.compare_url
163
+ @config.reponame = repo = 'some/repo'
164
+ compare = @hook.compare_url
160
165
  changes = 'so many changes'
161
166
  @checkout.stubs(:changes).returns(changes)
162
167
 
168
+ commands = %w[/path/to/puppet apply stuff_and_things]
169
+ @puppet.stubs(:command).returns(commands)
170
+ command = commands.join(' ')
171
+
163
172
  @config.logfile = logfile = '/path/to/logfile.txt'
164
173
 
165
- details = @check.failure_details
174
+ details = @hook.failure_details
166
175
 
167
176
  assert_match sha, details
168
177
  assert_match hostname, details
@@ -170,17 +179,18 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
170
179
  assert_match os, details
171
180
  assert_match compare, details
172
181
  assert_match changes, details
182
+ assert_match command, details
173
183
  assert_match logfile, details
174
184
  assert_match log, details
175
185
  end
176
186
 
177
- def test_logfile
187
+ def test_log
178
188
  @config.logfile = logfile = '/path/to/logfile.txt'
179
189
 
180
190
  log = 'a bunch of log data'
181
191
  File.expects(:read).with(logfile).returns(log)
182
192
 
183
- assert_equal log, @check.logfile
193
+ assert_equal log, @hook.log
184
194
  end
185
195
 
186
196
 
@@ -192,12 +202,12 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
192
202
  Label = Struct.new(:name)
193
203
 
194
204
  def test_close_failures
195
- @check.stubs(:issues?).returns(true)
205
+ @hook.stubs(:issues?).returns(true)
196
206
 
197
207
  @config.reponame = repo = 'some/repo'
198
208
 
199
209
  issues = Array.new(3) { |i| Issue.new(i*2 + 2) }
200
- @check.stubs(:failures).returns(issues)
210
+ @hook.stubs(:failures).returns(issues)
201
211
 
202
212
  sha = 'decafbad'
203
213
  @checkout.stubs(:sha).returns(sha)
@@ -208,29 +218,29 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
208
218
  api.expects(:close_issue).with(repo, issue.number)
209
219
  end
210
220
 
211
- @check.close_failures
221
+ @hook.close_failures
212
222
  end
213
223
 
214
224
  def test_close_failures_no_issues
215
- @check.stubs(:issues?).returns(false)
225
+ @hook.stubs(:issues?).returns(false)
216
226
 
217
- @check.expects(:failures).never
227
+ @hook.expects(:failures).never
218
228
 
219
229
  @config.api = api = mock('api')
220
230
  api.expects(:add_comment).never
221
231
  api.expects(:close_issue).never
222
232
 
223
- @check.close_failures
233
+ @hook.close_failures
224
234
  end
225
235
 
226
236
  def test_failures
227
- @check.stubs(:issues?).returns(true)
237
+ @hook.stubs(:issues?).returns(true)
228
238
 
229
239
  @config.reponame = repo = 'some/repo'
230
240
  @config.login = user = 'hapless'
231
241
 
232
- @check.failure_label = fail_label = 'ouch'
233
- @check.ongoing_label = goon_label = 'goon'
242
+ @hook.failure_label = fail_label = 'ouch'
243
+ @hook.ongoing_label = goon_label = 'goon'
234
244
 
235
245
  fail_l = Label.new(fail_label)
236
246
  goon_l = Label.new(goon_label)
@@ -247,16 +257,16 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
247
257
  @config.api = api = mock('api')
248
258
  api.expects(:list_issues).with(repo, :state => 'open', :labels => fail_label, :creator => user).returns(issues)
249
259
 
250
- assert_equal issues.values_at(0,1,3), @check.failures
260
+ assert_equal issues.values_at(0,1,3), @hook.failures
251
261
  end
252
262
 
253
263
  def test_failures_no_issues
254
- @check.stubs(:issues?).returns(false)
264
+ @hook.stubs(:issues?).returns(false)
255
265
 
256
266
  @config.api = api = mock('api')
257
267
  api.expects(:list_issues).never
258
268
 
259
- assert_equal [], @check.failures
269
+ assert_equal [], @hook.failures
260
270
  end
261
271
 
262
272
  RepoInfo = Struct.new(:has_issues)
@@ -267,18 +277,18 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
267
277
 
268
278
  @config.api = api = mock('api')
269
279
  api.stubs(:repository).with(repo).returns(repo_info)
270
- assert @check.issues?
280
+ assert @hook.issues?
271
281
 
272
282
  repo_info = RepoInfo.new(false)
273
283
  api.stubs(:repository).with(repo).returns(repo_info)
274
- refute @check.issues?
284
+ refute @hook.issues?
275
285
 
276
286
  @config.stubs(:reponame) # to ensure the returned value is nil
277
287
  api.stubs(:repository).returns(RepoInfo.new(true))
278
- refute @check.issues?
288
+ refute @hook.issues?
279
289
 
280
290
  @config.stubs(:reponame).returns('boxen/our-boxen') # our main public repo
281
291
  api.stubs(:repository).returns(RepoInfo.new(true))
282
- refute @check.issues?
292
+ refute @hook.issues?
283
293
  end
284
294
  end