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
@@ -1,3 +1,3 @@
1
1
  module Methadone #:nodoc:
2
- VERSION = "1.9.5" #:nodoc:
2
+ VERSION = "2.0.0"
3
3
  end
@@ -20,12 +20,10 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency("bundler")
21
21
  s.add_development_dependency("rake")
22
22
  s.add_development_dependency("rdoc","~> 5.0")
23
- s.add_development_dependency("cucumber")
24
- s.add_development_dependency("aruba", "0.5.1")
25
23
  s.add_development_dependency("simplecov", "~> 0.5")
26
24
  s.add_development_dependency("clean_test")
27
- s.add_development_dependency("mocha", "0.13.2")
25
+ s.add_development_dependency("mocha")
28
26
  s.add_development_dependency("sdoc", "1.0.0.rc1")
29
- s.add_development_dependency("rspec", "~> 3")
30
- s.add_development_dependency("i18n", "= 0.6.1")
27
+ s.add_development_dependency("rspec") # needed for testing the generated tests
28
+ s.add_development_dependency("i18n")
31
29
  end
@@ -35,8 +35,6 @@ end
35
35
  <% else %>
36
36
  require 'rake/testtask'
37
37
  <% end %>
38
- require 'cucumber'
39
- require 'cucumber/rake/task'
40
38
  gem 'rdoc' # we need the installed RDoc gem, not the system one
41
39
  require 'rdoc/task'
42
40
 
@@ -50,25 +48,24 @@ RSpec::Core::RakeTask.new do |t|
50
48
  end
51
49
  <% else %>
52
50
  Rake::TestTask.new do |t|
53
- t.pattern = 'test/tc_*.rb'
51
+ t.pattern = 'test/unit/test_*.rb'
54
52
  end
55
- <% end %>
56
53
 
57
- CUKE_RESULTS = 'results.html'
58
- CLEAN << CUKE_RESULTS
59
- Cucumber::Rake::Task.new(:features) do |t|
60
- t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
61
- t.fork = false
54
+ Rake::TestTask.new("test:integration") do |t|
55
+ t.pattern = 'test/integration/test_*.rb'
62
56
  end
57
+ <% end %>
63
58
 
64
59
  Rake::RDocTask.new do |rd|
65
60
  <% if using_readme %>
66
61
  rd.main = "README.rdoc"
67
- <% end %>
68
62
  rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
63
+ <% else %>
64
+ rd.rdoc_files.include("lib/**/*.rb","bin/**/*")
65
+ <% end %>
69
66
  end
70
67
  <% if rspec %>
71
- task :default => [:spec,:features]
68
+ task :default => [:spec]
72
69
  <% else %>
73
- task :default => [:test,:features]
70
+ task :default => [:test,"test:integration"]
74
71
  <% end %>
@@ -39,5 +39,7 @@ class App
39
39
 
40
40
  use_log_level_option :toggle_debug_on_signal => 'USR1'
41
41
 
42
+ description "My awesome command line app!"
43
+
42
44
  go!
43
45
  end
@@ -1,4 +1,4 @@
1
- describe "TestSomething" do
1
+ RSpec.describe "TestSomething" do
2
2
  it "should be true" do
3
3
  expect(true).to eq(true)
4
4
  end
@@ -0,0 +1,11 @@
1
+ require "methadone/test/base_integration_test"
2
+
3
+ class TestSomething < Methadone::BaseIntegrationTest
4
+ def test_truth
5
+ stdout,stderr,results = run_app("<%= gemname %>","--help")
6
+ assert_banner(stdout, "<%= gemname %>", takes_options: true, takes_arguments: false)
7
+ assert_option(stdout,"-h", "--help")
8
+ assert_option(stdout,"--version")
9
+ assert_oneline_summary(stdout)
10
+ end
11
+ end
@@ -0,0 +1,60 @@
1
+ require "methadone/test/base_integration_test"
2
+ require "clean_test/test_case"
3
+
4
+ class BaseIntegrationTest < Methadone::BaseIntegrationTest
5
+ include Clean::Test::GivenWhenThen
6
+ include Clean::Test::TestThat
7
+ include Clean::Test::Any
8
+ def setup
9
+ root = (Pathname(__FILE__).dirname / ".." / "..").expand_path
10
+ ENV["PATH"] = (root / "bin").to_s + File::PATH_SEPARATOR + ENV["PATH"]
11
+ ENV["RUBYLIB"] = (root / "lib").to_s + File::PATH_SEPARATOR + ENV["RUBYLIB"]
12
+ @pwd = pwd
13
+ @tmdir = Dir.mktmpdir
14
+ chdir @tmdir
15
+ end
16
+
17
+ def teardown
18
+ chdir @pwd
19
+ rm_rf @tmdir
20
+ end
21
+
22
+ private
23
+
24
+ def methadone(args, allow_failure: false)
25
+ command = "methadone #{args}"
26
+ stdout, stderr, status = Open3.capture3(command)
27
+ if !status.success? && !allow_failure
28
+ raise "'#{command}' failed: #{status.inspect}\n\nSTDOUT:\n\n#{stdout}\n\nSTDERR:\n\n#{stderr}\nEND"
29
+ end
30
+ [ stdout, stderr, status ]
31
+ end
32
+
33
+ def run_app(gemname,args="")
34
+ run_in_gem(gemname, "bin/#{gemname}", args)
35
+ end
36
+
37
+ # Runs rake inside the app for an integration test, returning stdout and stderr as strings
38
+ def rake(gemname,args="")
39
+ run_in_gem(gemname, "rake", args)
40
+ end
41
+
42
+ # Runs an arbitrary command inside the gem, returning stdout and stderr as strings.
43
+ def run_in_gem(gemname, command, args)
44
+ stdout = nil
45
+ stderr = nil
46
+ original_rubylib = ENV["RUBYLIB"]
47
+ chdir gemname do
48
+ ENV["RUBYLIB"] = "lib" + File::PATH_SEPARATOR + original_rubylib
49
+ stdout, stderr, result = Open3.capture3("#{command} #{args}")
50
+ unless result.success?
51
+ raise "#{stdout}\n#{stderr}"
52
+ end
53
+ end
54
+ [ stdout, stderr ]
55
+ ensure
56
+ ENV["RUBYLIB"] = original_rubylib
57
+ end
58
+
59
+
60
+ end
@@ -0,0 +1,150 @@
1
+ require_relative "base_integration_test"
2
+
3
+ include FileUtils
4
+
5
+ class TestBootstrap < BaseIntegrationTest
6
+ test_that "bootstrapping a new app generates basic boilerplate" do
7
+ When { methadone "newgem" }
8
+ Then {
9
+ [
10
+ "bin/newgem",
11
+ "lib/newgem.rb",
12
+ "lib/newgem/version.rb",
13
+ "newgem.gemspec",
14
+ "README.rdoc",
15
+ "Rakefile",
16
+ ].each do |file|
17
+ assert File.exist?("newgem/#{file}"), "Expected newgem/#{file} to exist"
18
+ end
19
+ }
20
+ And {
21
+ assert_all_files_staged_in_git
22
+ }
23
+ When { @stdout, _ = run_app("newgem", "--help") }
24
+ Then {
25
+ assert_banner(@stdout, "newgem", takes_options: true, takes_arguments: false)
26
+ assert_standard_options(@stdout)
27
+ }
28
+ When { @stdout, _ = rake("newgem", "-T") }
29
+ Then {
30
+ assert_supports_basic_rake_tasks(@stdout)
31
+ }
32
+ When { @stdout, _ = rake("newgem", "") }
33
+ Then {
34
+ assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/,@stdout)
35
+ assert_match(/1 tests, 8 assertions, 0 failures, 0 errors/,@stdout) # integration test
36
+ }
37
+ And {
38
+ gemspec = File.read("newgem/newgem.gemspec")
39
+ refute_match(/TODO/,gemspec)
40
+ refute_match(/FIXME/,gemspec)
41
+ }
42
+ end
43
+
44
+ test_that "bootstrapping a new app with a dash in its name works" do
45
+ When { methadone "new-gem" }
46
+ Then {
47
+ [
48
+ "bin/new-gem",
49
+ "lib/new/gem.rb",
50
+ "lib/new/gem/version.rb",
51
+ "new-gem.gemspec",
52
+ "README.rdoc",
53
+ "Rakefile",
54
+ ].each do |file|
55
+ assert File.exist?("new-gem/#{file}"), "Expected new-gem/#{file} to exist: #{`ls -ltR new-gem`}}"
56
+ end
57
+ }
58
+ When { @stdout, _ = run_app("new-gem", "--help") }
59
+ Then {
60
+ assert_banner(@stdout, "new-gem", takes_options: true, takes_arguments: false)
61
+ assert_standard_options(@stdout)
62
+ }
63
+ When { @stdout, _ = rake("new-gem", "-T") }
64
+ Then {
65
+ assert_supports_basic_rake_tasks(@stdout)
66
+ }
67
+ When { @stdout, _ = rake("new-gem", "") }
68
+ Then {
69
+ assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/,@stdout)
70
+ assert_match(/1 tests, 8 assertions, 0 failures, 0 errors/,@stdout) # integration test
71
+ }
72
+ And {
73
+ gemspec = File.read("new-gem/new-gem.gemspec")
74
+ refute_match(/TODO/,gemspec)
75
+ refute_match(/FIXME/,gemspec)
76
+ }
77
+ end
78
+
79
+ test_that "won't overwrite an existing dir" do
80
+ Given { methadone "newgem" }
81
+ And {
82
+ File.open("newgem/new_file.txt","w") do |file|
83
+ file.puts "Creating a file to verify it doesn't get blown away"
84
+ end
85
+ }
86
+ When { @stdout, @stderr, @status = methadone "newgem", allow_failure: true }
87
+ Then {
88
+ assert File.exist?("newgem/new_file.txt")
89
+ }
90
+ And {
91
+ refute @status.success?
92
+ }
93
+ And {
94
+ assert_match(/#{Regexp.escape("error: newgem exists, use --force to override")}/,@stderr)
95
+ }
96
+ end
97
+
98
+ test_that "will overwrite an existing dir with --force" do
99
+ Given { methadone "newgem" }
100
+ And {
101
+ File.open("newgem/new_file.txt","w") do |file|
102
+ file.puts "Creating a file to verify it doesn't get blown away"
103
+ end
104
+ }
105
+ When { @stdout, @stderr, @status = methadone "newgem --force", allow_failure: true }
106
+ Then {
107
+ refute File.exist?("newgem/new_file.txt")
108
+ }
109
+ And {
110
+ assert @status.success?
111
+ }
112
+ end
113
+
114
+ test_that "must supply a gem name" do
115
+ When { _, @stderr, @status = methadone "", allow_failure: true }
116
+ Then {
117
+ refute @status.success?
118
+ }
119
+ And {
120
+ assert_match(/\'app_name\' is required/,@stderr)
121
+ }
122
+ end
123
+
124
+ def assert_standard_options(stdout)
125
+ assert_option(stdout,"--version")
126
+ assert_option(stdout,"--help")
127
+ assert_option(stdout,"--log-level")
128
+ end
129
+
130
+ def assert_supports_basic_rake_tasks(stdout)
131
+ [
132
+ :clean,
133
+ :clobber,
134
+ :clobber_rdoc,
135
+ :rdoc,
136
+ :release,
137
+ :rerdoc,
138
+ :test,
139
+ :install,
140
+ :build,
141
+ ].each do |rake_task|
142
+ assert_match(/rake #{rake_task}/,stdout)
143
+ end
144
+ end
145
+
146
+ def assert_all_files_staged_in_git
147
+ stdout, _, __ = run_in_gem("newgem", "git", "ls-files --others --deleted")
148
+ assert_match(/\A\Z/, stdout)
149
+ end
150
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "base_integration_test"
2
+
3
+ include FileUtils
4
+
5
+ class TestCli < BaseIntegrationTest
6
+ test_that "methadone CLI is properly documented" do
7
+ When { @stdout, _, __ = methadone "--help" }
8
+ Then {
9
+ assert_banner(@stdout, "methadone", takes_options: true, takes_arguments: { app_name: :required })
10
+ }
11
+ And {
12
+ assert_option(@stdout, "--force")
13
+ assert_option(@stdout, "--[no-]readme")
14
+ assert_option(@stdout, "-l", "--license")
15
+ assert_option(@stdout, "--log-level")
16
+ }
17
+ And {
18
+ assert_oneline_summary(@stdout)
19
+ }
20
+ end
21
+ end
@@ -0,0 +1,56 @@
1
+ require_relative "base_integration_test"
2
+
3
+ include FileUtils
4
+
5
+ class TestLicense < BaseIntegrationTest
6
+ test_that "omitting a license generates a warning" do
7
+ When { _, @stderr, __ = methadone "newgem" }
8
+ Then {
9
+ assert_match(/warning: your app has no license/,@stderr)
10
+ }
11
+ end
12
+
13
+ test_that "explicitly omitting a license does not generate a warning" do
14
+ When { _, @stderr, __ = methadone "newgem -l NONE" }
15
+ Then {
16
+ refute_match(/warning: your app has no license/,@stderr)
17
+ }
18
+ end
19
+
20
+ [
21
+ "apache",
22
+ "mit",
23
+ "gplv2",
24
+ "gplv3",
25
+ ].each do |license|
26
+ test_that "the #{license} license can be included" do
27
+ When { methadone "newgem -l #{license}" }
28
+ Then {
29
+ assert File.exist?("newgem/LICENSE.txt")
30
+ }
31
+ And {
32
+ assert_file("newgem/newgem.gemspec", contains: /#{license.upcase}/)
33
+ }
34
+ end
35
+ end
36
+
37
+ test_that "a custom license can be included" do
38
+ When { methadone "newgem -l custom" }
39
+ Then {
40
+ assert File.exist?("newgem/LICENSE.txt")
41
+ }
42
+ And {
43
+ assert_equal "", File.read("newgem/LICENSE.txt").strip
44
+ }
45
+ end
46
+
47
+ test_that "a non-custom non-supported license causes an error" do
48
+ When { _, @stderr, @result = methadone "newgem -l foobar", allow_failure: true }
49
+ Then {
50
+ refute @result.success?
51
+ }
52
+ And {
53
+ assert_match(/invalid argument: -l foobar/,@stderr)
54
+ }
55
+ end
56
+ end
@@ -0,0 +1,53 @@
1
+ require_relative "base_integration_test"
2
+ class TestReadme < BaseIntegrationTest
3
+ test_that "a reasonable README is created" do
4
+ When {
5
+ methadone "newgem --readme"
6
+ }
7
+ Then {
8
+ assert File.exist?("newgem/README.rdoc")
9
+ }
10
+ And {
11
+ readmes = Dir["newgem/README*"].to_a
12
+ assert_equal 1, readmes.size,"Found more than one README: #{readmes.inspect}"
13
+ }
14
+ And {
15
+ rakefile_contents = File.read("newgem/Rakefile")
16
+ assert_match(/README.rdoc/,rakefile_contents)
17
+ assert_match(/rd.main = ["']README.rdoc["']/,rakefile_contents)
18
+ }
19
+ And {
20
+ assert_file("newgem/README.rdoc",
21
+ contains: [
22
+ /newgem/,
23
+ /Author:: YOUR NAME \(YOUR EMAIL\)/,
24
+ /\* \{Source on Github\}\[LINK TO GITHUB\]/,
25
+ /RDoc\[LINK TO RDOC.INFO\]/,
26
+ /^== Install/,
27
+ /^== Examples/,
28
+ /^== Contributing/,
29
+ ])
30
+ }
31
+ end
32
+
33
+ test_that "a readme is created by default" do
34
+ When {
35
+ methadone "newgem"
36
+ }
37
+ Then {
38
+ assert File.exist?("newgem/README.rdoc")
39
+ }
40
+ end
41
+
42
+ test_that "we can omit a README" do
43
+ When {
44
+ methadone "--no-readme newgem"
45
+ }
46
+ Then {
47
+ refute File.exist?("newgem/README.rdoc")
48
+ }
49
+ And {
50
+ refute_match(/README/,File.read("newgem/Rakefile"))
51
+ }
52
+ end
53
+ end
@@ -0,0 +1,28 @@
1
+ require_relative "base_integration_test"
2
+
3
+ include FileUtils
4
+
5
+ class TestRSpec < BaseIntegrationTest
6
+ test_that "we can generate an app using RSpec instead of Test::Unit" do
7
+ When { methadone "--rspec newgem" }
8
+ Then {
9
+ refute Dir.exist?("newgem/test")
10
+ assert Dir.exist?("newgem/spec")
11
+ assert File.exist?("newgem/spec/something_spec.rb")
12
+ }
13
+ And {
14
+ assert_file("newgem/newgem.gemspec", contains: /add_development_dependency\(["']rspec["']/)
15
+ }
16
+ And {
17
+ stdout,_ = rake("newgem", "-T")
18
+ assert_match(/rake spec/,stdout)
19
+ refute_match(/rake testa/,stdout)
20
+ }
21
+ When {
22
+ @stdout, _ = rake("newgem","spec")
23
+ }
24
+ Then {
25
+ assert_match(/1 example,.*0 failures/,@stdout)
26
+ }
27
+ end
28
+ end