rdm 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Gemfile.lock +80 -0
  4. data/bin/rdm +78 -10
  5. data/example/.rdm/helpers/render_helper.rb +12 -0
  6. data/example/.rdm/templates/package/.gitignore +1 -0
  7. data/example/.rdm/templates/package/.rspec +2 -0
  8. data/example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb +3 -0
  9. data/example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>/.gitkeep +0 -0
  10. data/{lib/rdm/templates/package/package.rb.erb → example/.rdm/templates/package/Package.rb} +0 -0
  11. data/{lib/rdm/templates/package/bin/console_irb → example/.rdm/templates/package/bin/console} +0 -0
  12. data/example/.rdm/templates/package/spec/spec_helper.rb +10 -0
  13. data/example/.rdm/templates/repository/dao/<%=name%>_dao.rb +4 -0
  14. data/example/.rdm/templates/repository/mapper/<%=name%>_mapper.rb +2 -0
  15. data/example/.rdm/templates/repository/repository/<%=name%>_repository.rb +2 -0
  16. data/example/.rdm/templates/repository/views/users.html.erb +2 -0
  17. data/example/Gemfile.lock +50 -0
  18. data/example/Rdm.packages +1 -0
  19. data/example/tests/diff_run +0 -0
  20. data/example/tests/run +0 -0
  21. data/lib/rdm.rb +40 -8
  22. data/lib/rdm/cli/compile_package.rb +56 -0
  23. data/lib/rdm/cli/dependencies_controller.rb +30 -0
  24. data/lib/rdm/cli/diff_package.rb +21 -0
  25. data/lib/rdm/cli/gen_package.rb +24 -32
  26. data/lib/rdm/cli/init.rb +20 -27
  27. data/lib/rdm/cli/template_generator.rb +38 -0
  28. data/lib/rdm/errors.rb +37 -0
  29. data/lib/rdm/gen/init.rb +29 -44
  30. data/lib/rdm/gen/package.rb +24 -78
  31. data/lib/rdm/git/diff_command.rb +13 -0
  32. data/lib/rdm/git/diff_manager.rb +30 -0
  33. data/lib/rdm/git/repository_locator.rb +23 -0
  34. data/lib/rdm/handlers/dependencies_handler.rb +110 -0
  35. data/lib/rdm/handlers/diff_package_handler.rb +48 -0
  36. data/lib/rdm/handlers/template_handler.rb +118 -0
  37. data/lib/rdm/helpers/path_helper.rb +15 -0
  38. data/lib/rdm/package.rb +6 -0
  39. data/lib/rdm/package_importer.rb +1 -1
  40. data/lib/rdm/packages/compiler_service.rb +78 -0
  41. data/lib/rdm/packages/locator.rb +28 -0
  42. data/lib/rdm/settings.rb +14 -1
  43. data/lib/rdm/spec_runner.rb +5 -0
  44. data/lib/rdm/spec_runner/command_generator.rb +28 -0
  45. data/lib/rdm/spec_runner/command_params.rb +3 -0
  46. data/lib/rdm/spec_runner/package_fetcher.rb +13 -0
  47. data/lib/rdm/spec_runner/runner.rb +122 -0
  48. data/lib/rdm/spec_runner/view.rb +20 -0
  49. data/lib/rdm/templates/init/.rdm/helpers/render_helper.rb +12 -0
  50. data/lib/rdm/templates/init/{Gemfile.erb → Gemfile} +0 -0
  51. data/lib/rdm/templates/init/{Rdm.packages.erb → Rdm.packages} +0 -0
  52. data/lib/rdm/templates/init/{Readme.md.erb → Readme.md} +0 -0
  53. data/lib/rdm/templates/init/tests/diff_run +29 -0
  54. data/lib/rdm/templates/init/tests/run +7 -210
  55. data/lib/rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb +3 -0
  56. data/lib/rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>/.gitkeep +0 -0
  57. data/lib/rdm/templates/package/Package.rb +8 -0
  58. data/lib/rdm/templates/package/bin/console +16 -0
  59. data/lib/rdm/templates/template_detector.rb +32 -0
  60. data/lib/rdm/templates/template_renderer.rb +49 -0
  61. data/lib/rdm/utils/file_utils.rb +20 -0
  62. data/lib/rdm/utils/render_util.rb +24 -0
  63. data/lib/rdm/utils/string_utils.rb +16 -0
  64. data/lib/rdm/version.rb +1 -1
  65. data/rdm.gemspec +1 -1
  66. data/spec/helpers/example_project_helper.rb +217 -0
  67. data/spec/helpers/git_commands_helper.rb +13 -0
  68. data/spec/rdm/cli/compile_package_spec.rb +114 -0
  69. data/spec/rdm/cli/dependencies_controller_spec.rb +50 -0
  70. data/spec/rdm/cli/diff_package_spec.rb +5 -0
  71. data/spec/rdm/cli/gen_package_spec.rb +60 -86
  72. data/spec/rdm/cli/init_spec.rb +53 -70
  73. data/spec/rdm/gen/init_spec.rb +21 -38
  74. data/spec/rdm/gen/package_spec.rb +70 -51
  75. data/spec/rdm/git/diff_manager_spec.rb +81 -0
  76. data/spec/rdm/git/repository_locator_spec.rb +31 -0
  77. data/spec/rdm/handlers/dependencies_handler_spec.rb +84 -0
  78. data/spec/rdm/handlers/diff_package_handler_spec.rb +78 -0
  79. data/spec/rdm/handlers/template_handler_spec.rb +94 -0
  80. data/spec/rdm/helpers/path_helper_spec.rb +52 -0
  81. data/spec/rdm/package/compiler_service_spec.rb +124 -0
  82. data/spec/rdm/package/locator_spec.rb +31 -0
  83. data/spec/rdm/rdm_spec.rb +2 -2
  84. data/spec/rdm/spec_runner/runner_spec.rb +12 -0
  85. data/spec/rdm/templates/template_detector_spec.rb +39 -0
  86. data/spec/rdm/templates/template_renderer_spec.rb +42 -0
  87. data/spec/spec_helper.rb +31 -25
  88. metadata +84 -17
  89. data/lib/rdm/gen/concerns/template_handling.rb +0 -81
  90. data/lib/rdm/support/colorize.rb +0 -106
  91. data/lib/rdm/support/render.rb +0 -17
  92. data/lib/rdm/support/template.rb +0 -30
  93. data/lib/rdm/templates/package/main_module_file.rb.erb +0 -3
  94. data/spec/rdm/support/colorize_spec.rb +0 -24
  95. data/spec/rdm/support/template_spec.rb +0 -20
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rdm::CLI::DependenciesController do
4
+ include ExampleProjectHelper
5
+
6
+ subject { described_class }
7
+
8
+ before { initialize_example_project }
9
+ after { reset_example_project }
10
+
11
+ let(:stdout) { SpecLogger.new }
12
+
13
+ context ":run" do
14
+ it "returns array of dependencies names" do
15
+ subject.run(
16
+ package_name: 'web',
17
+ project_path: example_project_path,
18
+ stdout: stdout
19
+ )
20
+
21
+ expect(stdout.output).to include(
22
+ [
23
+ "web",
24
+ "└── core",
25
+ " └── repository"
26
+ ]
27
+ )
28
+ end
29
+
30
+ it "returns no dependencies message" do
31
+ subject.run(
32
+ package_name: 'repository',
33
+ project_path: example_project_path,
34
+ stdout: stdout
35
+ )
36
+
37
+ expect(stdout.output).to include("Package `repository` has no dependencies")
38
+ end
39
+
40
+ it "show error message if package_name not specified" do
41
+ subject.run(
42
+ package_name: '',
43
+ project_path: example_project_path,
44
+ stdout: stdout
45
+ )
46
+
47
+ expect(stdout.output).to include("Type package name, ex: rdm gen.deps repository")
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe Rdm::CLI::DiffPackage do
4
+
5
+ end
@@ -1,45 +1,25 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Rdm::CLI::GenPackage do
4
- include SetupHelper
4
+ include ExampleProjectHelper
5
5
 
6
- before :all do
7
- Rdm::Gen::Package.disable_logger!
8
- end
6
+ subject { described_class }
9
7
 
10
- def generate_project!
11
- Rdm::Gen::Init.generate(
12
- current_dir: empty_project_dir
13
- )
14
- end
8
+ let(:stdout) { SpecLogger.new }
15
9
 
16
- def ensure_exists(file)
17
- expect(File.exists?(file)).to be true
18
- end
19
-
20
- def ensure_content(file, content)
21
- expect(File.read(file)).to match(content)
22
- end
10
+ before { initialize_example_project }
11
+ after { reset_example_project }
23
12
 
24
13
  context "run" do
25
- before :all do
26
- fresh_project
27
- end
28
-
29
- after :all do
30
- clean_tmp
31
- end
32
-
33
14
  it "generates package" do
34
- opts = {
15
+ subject.run(
35
16
  package_name: "database",
36
- current_dir: project_dir,
37
- path: "infrastructure/database" ,
38
- skip_tests: false
39
- }
40
- Rdm::CLI::GenPackage.run(opts)
17
+ current_path: example_project_path,
18
+ local_path: "infrastructure/database",
19
+ stdout: stdout
20
+ )
41
21
 
42
- FileUtils.cd(project_dir) do
22
+ FileUtils.cd(example_project_path) do
43
23
  ensure_exists("infrastructure/database/Package.rb")
44
24
  ensure_exists("infrastructure/database/package/database.rb")
45
25
  ensure_exists("infrastructure/database/package/database/")
@@ -50,79 +30,73 @@ describe Rdm::CLI::GenPackage do
50
30
  ensure_content("infrastructure/database/package/database.rb", "module Database\n\nend\n")
51
31
  end
52
32
  end
53
- end
54
33
 
55
- context "run with errors" do
56
- before :all do
57
- clean_tmp
58
- end
34
+ it "has logged useful output" do
35
+ subject.run(
36
+ package_name: "database",
37
+ current_path: example_project_path,
38
+ local_path: "infrastructure/database",
39
+ stdout: stdout
40
+ )
59
41
 
60
- after :all do
61
- clean_tmp
42
+ expect(stdout.output).to include("Generated: infrastructure/database/Package.rb")
62
43
  end
44
+ end
63
45
 
46
+ context "run with errors" do
64
47
  it "fails when in wrong directory" do
65
- opts = {
48
+ subject.run(
66
49
  package_name: "database",
67
- current_dir: project_dir,
68
- path: "infrastructure/database" ,
69
- skip_tests: false
70
- }
71
-
72
- expect{
73
- Rdm::CLI::GenPackage.run(opts)
74
- }.to output(/Rdm.packages\ not\ found/).to_stdout
50
+ current_path: File.dirname(example_project_path),
51
+ local_path: "infrastructure/database",
52
+ stdout: stdout
53
+ )
54
+
55
+ expect(stdout.output).to include("Rdm.packages was not found. Run 'rdm init' to create it")
75
56
  end
76
57
 
77
58
  it "fails when package already created" do
78
- fresh_project
79
- opts = {
59
+ subject.run(
60
+ package_name: "database",
61
+ current_path: example_project_path,
62
+ local_path: "infrastructure/database",
63
+ stdout: stdout
64
+ )
65
+
66
+ subject.run(
80
67
  package_name: "database",
81
- current_dir: project_dir,
82
- path: "infrastructure/database" ,
83
- skip_tests: false
84
- }
85
- Rdm::CLI::GenPackage.run(opts)
86
-
87
- expect{
88
- Rdm::CLI::GenPackage.run(opts)
89
- }.to output(Regexp.new("Error. Directory infrastructure/database exists. Package was not generated")).to_stdout
90
- clean_tmp
68
+ current_path: example_project_path,
69
+ local_path: "infrastructure/database",
70
+ stdout: stdout
71
+ )
72
+ expect(stdout.output).to include("Error. Directory infrastructure/database exists. Package was not generated")
91
73
  end
92
74
 
93
75
  it "fails when package already created" do
94
- fresh_project
95
- opts = {
76
+ subject.run(
96
77
  package_name: "database",
97
- current_dir: project_dir,
98
- path: "infrastructure/database" ,
99
- skip_tests: false
100
- }
101
- Rdm::CLI::GenPackage.run(opts)
102
-
103
- FileUtils.rm_rf(File.join(project_dir, "infrastructure/database"))
104
-
105
- expect{
106
- Rdm::CLI::GenPackage.run(opts)
107
- }.to output(Regexp.new("Error. Package already exist. Package was not generated")).to_stdout
108
- clean_tmp
78
+ current_path: example_project_path,
79
+ local_path: "infrastructure/database",
80
+ stdout: stdout
81
+ )
82
+
83
+ subject.run(
84
+ package_name: "database",
85
+ current_path: example_project_path,
86
+ local_path: "database",
87
+ stdout: stdout
88
+ )
89
+ expect(stdout.output).to include("Error. Package already exist. Package was not generated")
109
90
  end
110
91
 
111
92
  it "fails when empty package given" do
112
- fresh_project
113
- opts = {
93
+ subject.run(
114
94
  package_name: "",
115
- current_dir: project_dir,
116
- path: "infrastructure/database" ,
117
- skip_tests: false
118
- }
119
- begin
120
- expect{
121
- Rdm::CLI::GenPackage.run(opts)
122
- }.to output(Regexp.new("Package name was not specified!")).to_stdout
123
- rescue SystemExit
124
- clean_tmp
125
- end
95
+ current_path: example_project_path,
96
+ local_path: "infrastructure/database",
97
+ stdout: stdout
98
+ )
99
+ expect(stdout.output).to include("Package name was not specified!")
126
100
  end
127
101
  end
128
102
 
@@ -1,97 +1,80 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Rdm::CLI::Init do
4
- include SetupHelper
4
+ include ExampleProjectHelper
5
5
 
6
- before :all do
7
- Rdm::Gen::Init.disable_logger!
8
- end
6
+ subject { described_class }
7
+ let(:stdout) { SpecLogger.new }
9
8
 
10
- def ensure_exists(file)
11
- expect(File.exists?(file)).to be true
12
- end
13
9
 
14
- def ensure_content(file, content)
15
- expect(File.read(file)).to match(content)
16
- end
10
+ before { initialize_example_project(skip_rdm_init: true) }
11
+ after { reset_example_project }
17
12
 
18
13
  context "run" do
19
- before :all do
20
- fresh_empty_project
21
- end
22
-
23
- after :all do
24
- clean_tmp
25
- end
26
-
27
14
  it "generates package" do
28
- opts = {
29
- current_dir: empty_project_dir,
30
- console: "irb",
31
- test: "rspec"
32
- }
33
- Rdm::CLI::Init.run(opts)
34
-
35
- FileUtils.cd(empty_project_dir) do
15
+ subject.run(
16
+ current_path: example_project_path,
17
+ console: "irb",
18
+ test: "rspec",
19
+ stdout: stdout
20
+ )
21
+
22
+ FileUtils.cd(example_project_path) do
36
23
  ensure_exists("Rdm.packages")
37
24
  ensure_exists("Gemfile")
38
25
  ensure_exists("Readme.md")
39
26
  ensure_exists("tests/run")
27
+ ensure_exists("tests/diff_run")
40
28
  end
41
29
  end
42
- end
43
-
44
- context "run with errors" do
45
- before :all do
46
- clean_tmp
47
- end
48
30
 
49
- after :all do
50
- clean_tmp
31
+ it "output list of generated files" do
32
+ subject.run(
33
+ current_path: example_project_path,
34
+ console: "irb",
35
+ test: "rspec",
36
+ stdout: stdout
37
+ )
38
+ expect(stdout.output).to include('Generated: Rdm.packages')
51
39
  end
40
+ end
52
41
 
42
+ context "run with errors" do
53
43
  it "fails when in wrong directory" do
54
- opts = {
55
- current_dir: empty_project_dir + "/not-there",
56
- console: "irb",
57
- test: "rspec"
58
- }
59
-
60
- expect{
61
- Rdm::CLI::Init.run(opts)
62
- }.to output(Regexp.new("Please run on empty directory")).to_stdout
44
+ subject.run(
45
+ current_path: example_project_path + "/not-there",
46
+ console: "irb",
47
+ test: "rspec",
48
+ stdout: stdout
49
+ )
50
+ expect(stdout.output).to include("/tmp/example/not-there doesn't exist. Initialize new rdm project with existing directory")
63
51
  end
64
52
 
65
53
  it "fails when project already initialized" do
66
- fresh_empty_project
67
- opts = {
68
- current_dir: empty_project_dir,
69
- console: "irb",
70
- test: "rspec"
71
- }
72
- Rdm::CLI::Init.run(opts)
73
-
74
- expect{
75
- Rdm::CLI::Init.run(opts)
76
- }.to output(Regexp.new("Error. Project was already initialized")).to_stdout
77
- clean_tmp
54
+ subject.run(
55
+ current_path: example_project_path,
56
+ console: "irb",
57
+ test: "rspec",
58
+ stdout: stdout
59
+ )
60
+
61
+ subject.run(
62
+ current_path: example_project_path,
63
+ console: "irb",
64
+ test: "rspec",
65
+ stdout: stdout
66
+ )
67
+ expect(stdout.output).to include("Error. Project was already initialized")
78
68
  end
79
69
 
80
- it "fails with wrong current_dir and exits" do
81
- opts = {
82
- current_dir: "",
83
- console: "irb",
84
- test: "rspec"
85
- }
86
-
87
- a = 0
88
- begin
89
- a = 1
90
- Rdm::CLI::Init.run(opts)
91
- a = 2
92
- rescue SystemExit
93
- expect(a).to eq(1)
94
- end
70
+ it "fails with wrong current_path and exits" do
71
+ subject.run(
72
+ current_path: "",
73
+ console: "irb",
74
+ test: "rspec",
75
+ stdout: stdout
76
+ )
77
+ expect(stdout.output).to include("Error. Project folder not specified. Type path to rdm project, ex: 'rdm init .'")
95
78
  end
96
79
  end
97
80
  end
@@ -1,35 +1,18 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Rdm::Gen::Init do
4
- include SetupHelper
4
+ include ExampleProjectHelper
5
5
 
6
- def generate_project!
7
- Rdm::Gen::Init.generate(
8
- current_dir: empty_project_dir
9
- )
10
- end
11
-
12
- def ensure_exists(file)
13
- expect(File.exists?(file)).to be true
14
- end
6
+ subject { described_class }
15
7
 
16
- def ensure_content(file, content)
17
- expect(File.read(file)).to match(content)
18
- end
8
+ before { initialize_example_project(skip_rdm_init: true) }
9
+ after { reset_example_project }
19
10
 
20
11
  context "sample project" do
21
- before :all do
22
- Rdm::Gen::Init.disable_logger!
23
- fresh_empty_project
24
- generate_project!
25
- end
26
-
27
- after :all do
28
- clean_tmp
29
- end
30
-
31
12
  it "has generated correct files" do
32
- FileUtils.cd(empty_project_dir) do
13
+ subject.generate(current_path: example_project_path)
14
+
15
+ FileUtils.cd(example_project_path) do
33
16
  ensure_exists("Rdm.packages")
34
17
  ensure_exists("Gemfile")
35
18
  ensure_exists("Readme.md")
@@ -37,26 +20,26 @@ describe Rdm::Gen::Init do
37
20
  end
38
21
  end
39
22
 
40
- it "has logged useful output" do
41
- Rdm::Gen::Init.enable_logger!
42
- expect {
43
- fresh_empty_project
44
- generate_project!
45
- }.to output(/Generated: Rdm.packages/).to_stdout
46
- Rdm::Gen::Init.disable_logger!
23
+ it "has generated package templates" do
24
+ subject.generate(current_path: example_project_path)
25
+
26
+ FileUtils.cd(example_project_path) do
27
+ ensure_exists(".rdm/templates/package/Package.rb")
28
+ ensure_exists(".rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb")
29
+ ensure_exists(".rdm/templates/package/.rspec")
30
+ ensure_exists(".rdm/templates/package/.gitignore")
31
+ ensure_exists(".rdm/templates/package/spec/spec_helper.rb")
32
+ ensure_exists(".rdm/templates/package/bin/console")
33
+ end
47
34
  end
48
35
  end
49
36
 
50
37
  context "prevents double execution" do
51
- after :all do
52
- clean_tmp
53
- end
54
-
55
38
  it "raises on second project generation" do
56
- fresh_empty_project
57
- generate_project!
39
+ subject.generate(current_path: example_project_path)
40
+
58
41
  expect {
59
- generate_project!
42
+ subject.generate(current_path: example_project_path)
60
43
  }.to raise_error(Rdm::Errors::ProjectAlreadyInitialized)
61
44
  end
62
45
  end