methadone 1.9.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +2 -5
  5. data/README.rdoc +75 -47
  6. data/Rakefile +25 -29
  7. data/bin/methadone +13 -5
  8. data/lib/methadone.rb +1 -1
  9. data/lib/methadone/cli_logger.rb +0 -1
  10. data/lib/methadone/cli_logging.rb +1 -1
  11. data/lib/methadone/cucumber.rb +4 -0
  12. data/lib/methadone/main.rb +4 -1
  13. data/lib/methadone/test/base_integration_test.rb +29 -0
  14. data/lib/methadone/test/integration_test_assertions.rb +63 -0
  15. data/lib/methadone/version.rb +1 -1
  16. data/methadone.gemspec +3 -5
  17. data/templates/full/Rakefile.erb +9 -12
  18. data/templates/full/bin/executable.erb +2 -0
  19. data/templates/rspec/spec/something_spec.rb.erb +1 -1
  20. data/templates/test_unit/test/integration/test_cli.rb.erb +11 -0
  21. data/templates/test_unit/test/{tc_something.rb.erb → unit/test_something.rb.erb} +0 -0
  22. data/test/integration/base_integration_test.rb +60 -0
  23. data/test/integration/test_bootstrap.rb +150 -0
  24. data/test/integration/test_cli.rb +21 -0
  25. data/test/integration/test_license.rb +56 -0
  26. data/test/integration/test_readme.rb +53 -0
  27. data/test/integration/test_rspec.rb +28 -0
  28. data/test/integration/test_version.rb +21 -0
  29. data/test/{base_test.rb → unit/base_test.rb} +0 -0
  30. data/test/{command_for_tests.sh → unit/command_for_tests.sh} +0 -0
  31. data/test/{execution_strategy → unit/execution_strategy}/test_base.rb +0 -0
  32. data/test/{execution_strategy → unit/execution_strategy}/test_jvm.rb +4 -4
  33. data/test/{execution_strategy → unit/execution_strategy}/test_mri.rb +0 -0
  34. data/test/{execution_strategy → unit/execution_strategy}/test_open_3.rb +5 -5
  35. data/test/{execution_strategy → unit/execution_strategy}/test_open_4.rb +5 -5
  36. data/test/{execution_strategy → unit/execution_strategy}/test_rbx_open_4.rb +0 -0
  37. data/test/unit/test/test_integration_test_assertions.rb +211 -0
  38. data/test/{test_cli_logger.rb → unit/test_cli_logger.rb} +17 -17
  39. data/test/{test_cli_logging.rb → unit/test_cli_logging.rb} +12 -12
  40. data/test/{test_exit_now.rb → unit/test_exit_now.rb} +4 -4
  41. data/test/{test_main.rb → unit/test_main.rb} +48 -48
  42. data/test/{test_sh.rb → unit/test_sh.rb} +37 -37
  43. metadata +61 -93
  44. data/features/bootstrap.feature +0 -153
  45. data/features/license.feature +0 -43
  46. data/features/readme.feature +0 -26
  47. data/features/rspec_support.feature +0 -27
  48. data/features/step_definitions/bootstrap_steps.rb +0 -47
  49. data/features/step_definitions/license_steps.rb +0 -30
  50. data/features/step_definitions/readme_steps.rb +0 -26
  51. data/features/step_definitions/version_steps.rb +0 -4
  52. data/features/support/env.rb +0 -26
  53. data/features/version.feature +0 -17
  54. data/templates/full/features/executable.feature.erb +0 -13
  55. data/templates/full/features/step_definitions/executable_steps.rb.erb +0 -1
  56. data/templates/full/features/support/env.rb.erb +0 -16
@@ -0,0 +1,21 @@
1
+ require_relative "base_integration_test"
2
+
3
+ include FileUtils
4
+
5
+ class TestVersion < BaseIntegrationTest
6
+ test_that "--help shows the gem version" do
7
+ Given { methadone "newgem" }
8
+ When { @stdout, _, = run_app "newgem", "--help" }
9
+ Then {
10
+ assert_match(/v\d+\.\d+\.\d+/, @stdout)
11
+ }
12
+ end
13
+
14
+ test_that "--version shows the gem version" do
15
+ Given { methadone "newgem" }
16
+ When { @stdout, _, = run_app "newgem", "--version" }
17
+ Then {
18
+ assert_match(/v\d+\.\d+\.\d+/, @stdout)
19
+ }
20
+ end
21
+ end
File without changes
@@ -53,9 +53,9 @@ module ExecutionStrategy
53
53
  @results = @strategy.run_command(@command)
54
54
  }
55
55
  Then {
56
- @results[0].should == @stdout
57
- @results[1].should == @stderr
58
- @results[2].exitstatus.should == @exitstatus
56
+ @results[0].should be == @stdout
57
+ @results[1].should be == @stderr
58
+ @results[2].exitstatus.should be == @exitstatus
59
59
  }
60
60
  end
61
61
 
@@ -65,7 +65,7 @@ module ExecutionStrategy
65
65
  @klass = @strategy.exception_meaning_command_not_found
66
66
  }
67
67
  Then {
68
- @klass.should == NativeException
68
+ @klass.should be == NativeException
69
69
  }
70
70
  end
71
71
 
@@ -23,8 +23,8 @@ module ExecutionStrategy
23
23
  @results = @strategy.run_command(@command)
24
24
  }
25
25
  Then {
26
- @results[0].should == @stdout
27
- @results[1].should == @stderr
26
+ @results[0].should be == @stdout
27
+ @results[1].should be == @stderr
28
28
  @results[2].should be @status
29
29
  }
30
30
  end
@@ -46,8 +46,8 @@ module ExecutionStrategy
46
46
  @results = @strategy.run_command(@command)
47
47
  }
48
48
  Then {
49
- @results[0].should == @stdout
50
- @results[1].should == @stderr
49
+ @results[0].should be == @stdout
50
+ @results[1].should be == @stderr
51
51
  @results[2].should be @status
52
52
  }
53
53
  end
@@ -58,7 +58,7 @@ module ExecutionStrategy
58
58
  @klass = @strategy.exception_meaning_command_not_found
59
59
  }
60
60
  Then {
61
- @klass.should == Errno::ENOENT
61
+ @klass.should be == Errno::ENOENT
62
62
  }
63
63
  end
64
64
 
@@ -33,8 +33,8 @@ module ExecutionStrategy
33
33
  @results = @strategy.run_command(@command)
34
34
  }
35
35
  Then {
36
- @results[0].should == @stdout
37
- @results[1].should == @stderr
36
+ @results[0].should be == @stdout
37
+ @results[1].should be == @stderr
38
38
  @results[2].should be @status
39
39
  }
40
40
  end
@@ -62,8 +62,8 @@ module ExecutionStrategy
62
62
  @results = @strategy.run_command(@command)
63
63
  }
64
64
  Then {
65
- @results[0].should == @stdout
66
- @results[1].should == @stderr
65
+ @results[0].should be == @stdout
66
+ @results[1].should be == @stderr
67
67
  @results[2].should be @status
68
68
  }
69
69
  end
@@ -74,7 +74,7 @@ module ExecutionStrategy
74
74
  @klass = @strategy.exception_meaning_command_not_found
75
75
  }
76
76
  Then {
77
- @klass.should == Errno::ENOENT
77
+ @klass.should be == Errno::ENOENT
78
78
  }
79
79
  end
80
80
 
@@ -0,0 +1,211 @@
1
+ require 'base_test'
2
+ require 'methadone'
3
+ require 'methadone/test/integration_test_assertions'
4
+ require 'fileutils'
5
+ require 'tmpdir'
6
+
7
+ class TestIntegrationTestAssertions < BaseTest
8
+ include Methadone::IntegrationTestAssertions
9
+ include FileUtils
10
+
11
+ def setup
12
+ @pwd = pwd
13
+ @tmpdir = Dir.mktmpdir
14
+ chdir @tmpdir
15
+ end
16
+
17
+ def teardown
18
+ chdir @pwd
19
+ rm_rf @tmpdir
20
+ end
21
+
22
+ test_that "assert_file works with one regexp" do
23
+ Given { some_file }
24
+ When {
25
+ @code = ->() { assert_file("some_file.txt", contains: /foo/) }
26
+ }
27
+ Then { refute_raises(&@code) }
28
+ end
29
+
30
+ test_that "assert_file works with many regexps" do
31
+ Given { some_file }
32
+ When {
33
+ @code = ->() { assert_file("some_file.txt", contains: [ /foo/, /bar/ ]) }
34
+ }
35
+ Then { refute_raises(&@code) }
36
+ end
37
+
38
+ test_that "assert_file fails if any regexp fails to match" do
39
+ Given { some_file }
40
+ When {
41
+ @code = ->() { assert_file("some_file.txt", contains: [ /foo/, /baz/ ]) }
42
+ }
43
+ Then { assert_raises(&@code) }
44
+ end
45
+
46
+ test_that "assert_banner without takes_options passes for a banner with the bin name and no '[options]'" do
47
+ Given {
48
+ @bin_name = "foobar"
49
+ @stdout = "Usage: foobar"
50
+ }
51
+ When {
52
+ @code = ->() { assert_banner(@stdout,@bin_name,takes_options: false) }
53
+ }
54
+ Then { refute_raises(&@code) }
55
+ end
56
+
57
+ test_that "assert_banner without takes_options fails for a banner with the bin name and '[options]'" do
58
+ Given {
59
+ @bin_name = "foobar"
60
+ @stdout = "Usage: foobar [options]"
61
+ }
62
+ When {
63
+ @code = ->() { assert_banner(@stdout,@bin_name,takes_options: false) }
64
+ }
65
+ Then { assert_raises(&@code) }
66
+ end
67
+
68
+ test_that "assert_banner with takes_options passes for a banner with the bin name and '[options]'" do
69
+ Given {
70
+ @bin_name = "foobar"
71
+ @stdout = "Usage: foobar [options]\nOptions\n --help"
72
+ }
73
+ When {
74
+ @code = ->() { assert_banner(@stdout,@bin_name,takes_options: true) }
75
+ }
76
+ Then { refute_raises(&@code) }
77
+ end
78
+
79
+ test_that "assert_banner with takes_options fails for a banner with the bin name but no '[options]'" do
80
+ Given {
81
+ @bin_name = "foobar"
82
+ @stdout = "Usage: foobar\nOptions\n --help"
83
+ }
84
+ When {
85
+ @code = ->() { assert_banner(@stdout,@bin_name,takes_options: true) }
86
+ }
87
+ Then { assert_raises(&@code) }
88
+ end
89
+
90
+ test_that "assert_banner with takes_options and takes_arguments passes for a banner with the bin name, '[options]' and the arg list" do
91
+ Given {
92
+ @bin_name = "foobar"
93
+ @stdout = "Usage: foobar [options] some_arg [some_other_arg]\nOptions\n --help"
94
+ }
95
+ When {
96
+ @code = ->() {
97
+ assert_banner(@stdout,
98
+ @bin_name,
99
+ takes_options: true,
100
+ takes_arguments: { some_arg: :required, some_other_arg: :optional }
101
+ )
102
+ }
103
+ }
104
+ Then { refute_raises(&@code) }
105
+ end
106
+
107
+ test_that "assert_banner with takes_options and takes_arguments failes for a banner with the bin name, '[options]' and no arg list" do
108
+ Given {
109
+ @bin_name = "foobar"
110
+ @stdout = "Usage: foobar [options]\nOptions\n --help"
111
+ }
112
+ When {
113
+ @code = ->() {
114
+ assert_banner(@stdout,
115
+ @bin_name,
116
+ takes_options: true,
117
+ takes_arguments: { some_arg: :required, some_other_arg: :optional }
118
+ )
119
+ }
120
+ }
121
+ Then { assert_raises(&@code) }
122
+ end
123
+
124
+ test_that "assert_options with one option passes when stdout contains that option" do
125
+ Given { @stdout = some_options }
126
+ When { @code = ->() { assert_option(@stdout,"--help") } }
127
+ Then { refute_raises(&@code) }
128
+ end
129
+
130
+ test_that "assert_options with many option passes when stdout contains that option" do
131
+ Given { @stdout = some_options }
132
+ When { @code = ->() { assert_option(@stdout,"-h", "--help") } }
133
+ Then { refute_raises(&@code) }
134
+ end
135
+
136
+ test_that "assert_options fails when stdout does not the option" do
137
+ Given { @stdout = some_options }
138
+ When { @code = ->() { assert_option(@stdout,"--bleorg") } }
139
+ Then { assert_raises(&@code) }
140
+ end
141
+
142
+ test_that "assert_oneline_summary passes when the stdout has at least three lines, the second of which is blank and the third of which has some words in it" do
143
+ Given {
144
+ @stdout = [
145
+ "Usage: foobar",
146
+ "",
147
+ "The awesome app of awesome",
148
+ ].join("\n")
149
+ }
150
+ When { @code = ->() { assert_oneline_summary(@stdout) } }
151
+ Then { refute_raises(&@code) }
152
+ end
153
+
154
+ test_that "assert_oneline_summary fails when the stdout has at least three lines, the second of which is blank and the third of which has only one word in it" do
155
+ Given {
156
+ @stdout = [
157
+ "Usage: foobar",
158
+ "",
159
+ "awesome",
160
+ ].join("\n")
161
+ }
162
+ When { @code = ->() { assert_oneline_summary(@stdout) } }
163
+ Then { assert_raises(&@code) }
164
+ end
165
+
166
+ test_that "assert_oneline_summary fails when the stdout has at least three lines, the second of which is not blank and the third of which has words in it" do
167
+ Given {
168
+ @stdout = [
169
+ "Usage: foobar",
170
+ "foo",
171
+ "awesome app of awesome",
172
+ ].join("\n")
173
+ }
174
+ When { @code = ->() { assert_oneline_summary(@stdout) } }
175
+ Then { assert_raises(&@code) }
176
+ end
177
+
178
+ test_that "assert_oneline_summary fails when the stdout has less than three lines" do
179
+ Given {
180
+ @stdout = [
181
+ "Usage: foobar",
182
+ "awesome app of awesome",
183
+ ].join("\n")
184
+ }
185
+ When { @code = ->() { assert_oneline_summary(@stdout) } }
186
+ Then { assert_raises(&@code) }
187
+ end
188
+
189
+ private
190
+
191
+ def some_options
192
+ [
193
+ "-h, --help Get Help",
194
+ "--version Show the version",
195
+ "--[no-]output Print output",
196
+ ].join("\n")
197
+ end
198
+
199
+ def refute_raises(&block)
200
+ block.()
201
+ rescue Exception => ex
202
+ assert false, "Expected block NOT to raise, but got a #{ex.class}/#{ex.message}"
203
+ end
204
+
205
+ def some_file
206
+ File.open("some_file.txt","w") do |file|
207
+ file.puts "foo"
208
+ file.puts "bar"
209
+ end
210
+ end
211
+ end
@@ -37,8 +37,8 @@ class TestCLILogger < BaseTest
37
37
  When log_all_levels
38
38
 
39
39
  Then {
40
- $stdout.string.should == "debug\ninfo\n"
41
- $stderr.string.should == "warn\nerror\nfatal\n"
40
+ $stdout.string.should be == "debug\ninfo\n"
41
+ $stderr.string.should be == "warn\nerror\nfatal\n"
42
42
  }
43
43
  end
44
44
 
@@ -58,8 +58,8 @@ class TestCLILogger < BaseTest
58
58
  When log_all_levels
59
59
 
60
60
  Then {
61
- $stdout.string.should == ""
62
- $stderr.string.should == "error\nfatal\n"
61
+ $stdout.string.should be == ""
62
+ $stderr.string.should be == "error\nfatal\n"
63
63
  }
64
64
  end
65
65
 
@@ -69,7 +69,7 @@ class TestCLILogger < BaseTest
69
69
 
70
70
  Then stdout_should_have_everything
71
71
  And {
72
- $stderr.string.should == "warn\nerror\nfatal\n"
72
+ $stderr.string.should be == "warn\nerror\nfatal\n"
73
73
  }
74
74
  end
75
75
 
@@ -80,7 +80,7 @@ class TestCLILogger < BaseTest
80
80
 
81
81
  Then stdout_should_have_everything
82
82
  And {
83
- $stderr.string.should == "fatal\n"
83
+ $stderr.string.should be == "fatal\n"
84
84
  }
85
85
  end
86
86
 
@@ -97,8 +97,8 @@ class TestCLILogger < BaseTest
97
97
  When log_all_levels
98
98
 
99
99
  Then {
100
- @out.string.should == "debug\ninfo\nwarn\nerror\nfatal\n"
101
- @err.string.should == "warn\nerror\nfatal\n"
100
+ @out.string.should be == "debug\ninfo\nwarn\nerror\nfatal\n"
101
+ @err.string.should be == "warn\nerror\nfatal\n"
102
102
  }
103
103
  end
104
104
 
@@ -108,8 +108,8 @@ class TestCLILogger < BaseTest
108
108
  When log_all_levels
109
109
 
110
110
  Then {
111
- $stdout.string.should == "fatal\n"
112
- $stderr.string.should == "warn\nerror\nfatal\n"
111
+ $stdout.string.should be == "fatal\n"
112
+ $stderr.string.should be == "warn\nerror\nfatal\n"
113
113
  }
114
114
  end
115
115
 
@@ -126,8 +126,8 @@ class TestCLILogger < BaseTest
126
126
  }
127
127
 
128
128
  Then {
129
- $stdout.string.should match /the time.*DEBUG.*debug/
130
- $stderr.string.should match /the time.*ERROR.*error/
129
+ $stdout.string.should match(/the time.*DEBUG.*debug/)
130
+ $stderr.string.should match(/the time.*ERROR.*error/)
131
131
  }
132
132
  end
133
133
 
@@ -137,8 +137,8 @@ class TestCLILogger < BaseTest
137
137
  @logger << "foo"
138
138
  }
139
139
  Then {
140
- $stdout.string.should == "foo"
141
- $stderr.string.should == ""
140
+ $stdout.string.should be == "foo"
141
+ $stderr.string.should be == ""
142
142
  }
143
143
  end
144
144
 
@@ -154,8 +154,8 @@ class TestCLILogger < BaseTest
154
154
  @logger.error("error")
155
155
  }
156
156
  Then {
157
- $stdout.string.should == "debug\nerror\n"
158
- $stderr.string.should == "ERROR_LOGGER: error\n"
157
+ $stdout.string.should be == "debug\nerror\n"
158
+ $stderr.string.should be == "ERROR_LOGGER: error\n"
159
159
  }
160
160
  end
161
161
 
@@ -211,7 +211,7 @@ class TestCLILogger < BaseTest
211
211
 
212
212
  def stdout_should_have_everything
213
213
  proc do
214
- $stdout.string.should == "debug\ninfo\nwarn\nerror\nfatal\n"
214
+ $stdout.string.should be == "debug\ninfo\nwarn\nerror\nfatal\n"
215
215
  end
216
216
  end
217
217
 
@@ -32,8 +32,8 @@ class TestCLILogging < BaseTest
32
32
  }
33
33
 
34
34
  Then {
35
- $stdout.string.should == "debug\ninfo\nwarn\nerror\nfatal\n"
36
- $stderr.string.should == "warn\nerror\nfatal\n"
35
+ $stdout.string.should be == "debug\ninfo\nwarn\nerror\nfatal\n"
36
+ $stderr.string.should be == "warn\nerror\nfatal\n"
37
37
  }
38
38
  end
39
39
 
@@ -43,7 +43,7 @@ class TestCLILogging < BaseTest
43
43
  @second = MyOtherClassThatLogsToStdout.new
44
44
  }
45
45
  Then {
46
- @first.logger_id.should == @second.logger_id
46
+ @first.logger_id.should be == @second.logger_id
47
47
  }
48
48
  end
49
49
 
@@ -59,8 +59,8 @@ class TestCLILogging < BaseTest
59
59
  end
60
60
  }
61
61
  Then {
62
- @logger_id.should_not == @second.logger_id
63
- @first.logger_id.should == @second.logger_id
62
+ @logger_id.should_not be == @second.logger_id
63
+ @first.logger_id.should be == @second.logger_id
64
64
  }
65
65
  end
66
66
 
@@ -76,8 +76,8 @@ class TestCLILogging < BaseTest
76
76
  end
77
77
  }
78
78
  Then {
79
- @logger_id.should_not == @second.logger_id
80
- @first.logger_id.should == @second.logger_id
79
+ @logger_id.should_not be == @second.logger_id
80
+ @first.logger_id.should be == @second.logger_id
81
81
  }
82
82
  end
83
83
 
@@ -104,7 +104,7 @@ class TestCLILogging < BaseTest
104
104
  @app.use_option(@level)
105
105
  }
106
106
  Then {
107
- @app.logger.level.should == @level
107
+ @app.logger.level.should be == @level
108
108
  }
109
109
  end
110
110
 
@@ -120,7 +120,7 @@ class TestCLILogging < BaseTest
120
120
  @app.change_logger(@other_logger)
121
121
  }
122
122
  Then {
123
- @other_logger.level.should == @level
123
+ @other_logger.level.should be == @level
124
124
  }
125
125
  end
126
126
 
@@ -136,7 +136,7 @@ class TestCLILogging < BaseTest
136
136
  send_signal_and_wait_a_moment('USR2')
137
137
  }
138
138
  Then {
139
- @app.logger.level.should == Logger::DEBUG
139
+ @app.logger.level.should be == Logger::DEBUG
140
140
  }
141
141
  end
142
142
 
@@ -153,7 +153,7 @@ class TestCLILogging < BaseTest
153
153
  @app.change_logger(@other_logger)
154
154
  }
155
155
  Then {
156
- @other_logger.level.should == Logger::DEBUG
156
+ @other_logger.level.should be == Logger::DEBUG
157
157
  }
158
158
  end
159
159
 
@@ -169,7 +169,7 @@ class TestCLILogging < BaseTest
169
169
  send_signal_and_wait_a_moment('USR2')
170
170
  }
171
171
  Then {
172
- @app.logger.level.should == Logger::INFO
172
+ @app.logger.level.should be == Logger::INFO
173
173
  }
174
174
  end
175
175