create-ruby-app 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/CLAUDE.md +74 -0
  4. data/CODE_REVIEW.md +1659 -0
  5. data/LICENSE +13 -21
  6. data/README.md +5 -5
  7. data/REFACTORING_PLAN.md +543 -0
  8. data/bin/create-ruby-app +1 -3
  9. data/lib/create_ruby_app/actions/create_directories.rb +10 -2
  10. data/lib/create_ruby_app/actions/generate_files.rb +7 -4
  11. data/lib/create_ruby_app/actions/install_gems.rb +10 -2
  12. data/lib/create_ruby_app/actions/make_script_executable.rb +10 -2
  13. data/lib/create_ruby_app/actions/set_ruby_implementation.rb +52 -0
  14. data/lib/create_ruby_app/app.rb +9 -8
  15. data/lib/create_ruby_app/cli.rb +58 -41
  16. data/lib/create_ruby_app/templates/Gemfile.erb +1 -3
  17. data/lib/create_ruby_app/templates/lib_file.erb +0 -2
  18. data/lib/create_ruby_app/templates/script_file.erb +0 -2
  19. data/lib/create_ruby_app/templates/spec_helper.erb +0 -2
  20. data/lib/create_ruby_app/version.rb +1 -3
  21. data/lib/create_ruby_app.rb +1 -3
  22. data/spec/integration/app_creation_spec.rb +170 -0
  23. data/spec/lib/create_ruby_app/actions/create_directories_spec.rb +1 -3
  24. data/spec/lib/create_ruby_app/actions/generate_files_spec.rb +13 -20
  25. data/spec/lib/create_ruby_app/actions/install_gems_spec.rb +1 -3
  26. data/spec/lib/create_ruby_app/actions/make_script_executable_spec.rb +1 -3
  27. data/spec/lib/create_ruby_app/actions/set_ruby_implementation_spec.rb +194 -0
  28. data/spec/lib/create_ruby_app/app_spec.rb +4 -4
  29. data/spec/lib/create_ruby_app/cli_spec.rb +112 -0
  30. data/spec/spec_helper.rb +6 -2
  31. metadata +52 -20
  32. data/lib/create_ruby_app/actions/null_action.rb +0 -9
@@ -0,0 +1,194 @@
1
+ require_relative "../../../spec_helper"
2
+
3
+ RSpec.describe CreateRubyApp::Actions::SetRubyImplementation do
4
+ describe ".call" do
5
+ let(:action) { described_class }
6
+
7
+ context "when a Ruby version is provided" do
8
+ let(:app) do
9
+ instance_double(CreateRubyApp::App, name: "foo", version: "ruby-3.4.5")
10
+ end
11
+
12
+ it "returns the specific version provided" do
13
+ expect(action.call(app).version).to eq("ruby-3.4.5")
14
+ end
15
+ end
16
+
17
+ context "when no version if provided, but an `mruby` implementation is found" do
18
+ let(:app) do
19
+ instance_double(CreateRubyApp::App, name: "mruby_app", version: nil)
20
+ end
21
+
22
+ it "returns the local version" do
23
+ %w[ruby truffleruby jruby rubinius].each do |ruby_implementation|
24
+ allow(Open3).to receive(:capture3).with(
25
+ "#{ruby_implementation} -v"
26
+ ).and_return(
27
+ ["", "", instance_double(Process::Status, success?: false)]
28
+ )
29
+ end
30
+
31
+ allow(Open3).to receive(:capture3).with("mruby -v").and_return(
32
+ ["mruby 3.3.0", "", instance_double(Process::Status, success?: true)]
33
+ )
34
+
35
+ allow(app).to receive(:version=) do |version|
36
+ allow(app).to receive(:version).and_return(version)
37
+ end
38
+
39
+ expect(action.call(app).version).to eq("mruby-3.3.0")
40
+ expect(app).to have_received(:version=).with("mruby-3.3.0")
41
+
42
+ expect(Open3).to have_received(:capture3).with("mruby -v")
43
+ end
44
+ end
45
+
46
+ context "when no version if provided, but a `jruby` implementation is found" do
47
+ let(:app) do
48
+ instance_double(CreateRubyApp::App, name: "jruby_app", version: nil)
49
+ end
50
+
51
+ it "returns the local version" do
52
+ %w[ruby truffleruby mruby rubinius].each do |ruby_implementation|
53
+ allow(Open3).to receive(:capture3).with(
54
+ "#{ruby_implementation} -v"
55
+ ).and_return(
56
+ ["", "", instance_double(Process::Status, success?: false)]
57
+ )
58
+ end
59
+
60
+ allow(Open3).to receive(:capture3).with("jruby -v").and_return([
61
+ "jruby 9.4.14.0", "", instance_double(
62
+ Process::Status, success?: true
63
+ )
64
+ ])
65
+
66
+ allow(app).to receive(:version=) do |version|
67
+ allow(app).to receive(:version).and_return(version)
68
+ end
69
+
70
+ expect(action.call(app).version).to eq("jruby-9.4.14.0")
71
+ expect(app).to have_received(:version=).with("jruby-9.4.14.0")
72
+
73
+ expect(Open3).to have_received(:capture3).with("jruby -v")
74
+ end
75
+ end
76
+
77
+ context "when no version if provided, but a `rubinius` implementation is found" do
78
+ let(:app) do
79
+ instance_double(CreateRubyApp::App, name: "rubinius_app", version: nil)
80
+ end
81
+
82
+ it "returns the local version" do
83
+ %w[ruby truffleruby jruby mruby].each do |ruby_implementation|
84
+ allow(Open3).to receive(:capture3).with(
85
+ "#{ruby_implementation} -v"
86
+ ).and_return(
87
+ ["", "", instance_double(Process::Status, success?: false)]
88
+ )
89
+ end
90
+
91
+ allow(Open3).to receive(:capture3).with("rubinius -v").and_return(
92
+ ["rubinius 5.0", "", instance_double(Process::Status, success?: true)]
93
+ )
94
+
95
+ allow(app).to receive(:version=) do |version|
96
+ allow(app).to receive(:version).and_return(version)
97
+ end
98
+
99
+ expect(action.call(app).version).to eq("rubinius-5.0")
100
+ expect(app).to have_received(:version=).with("rubinius-5.0")
101
+
102
+ expect(Open3).to have_received(:capture3).with("rubinius -v")
103
+ end
104
+ end
105
+
106
+ context "when no version if provided, but a `ruby` implementation is found" do
107
+ let(:app) do
108
+ instance_double(CreateRubyApp::App, name: "ruby_app", version: nil)
109
+ end
110
+
111
+ it "returns the local version" do
112
+ %w[truffleruby jruby mruby rubinius].each do |ruby_implementation|
113
+ allow(Open3).to receive(:capture3).with(
114
+ "#{ruby_implementation} -v"
115
+ ).and_return(
116
+ ["", "", instance_double(Process::Status, success?: false)]
117
+ )
118
+ end
119
+
120
+ allow(Open3).to receive(:capture3).with("ruby -v").and_return(
121
+ ["ruby 3.4.6", "", instance_double(Process::Status, success?: true)]
122
+ )
123
+
124
+ allow(app).to receive(:version=) do |version|
125
+ allow(app).to receive(:version).and_return(version)
126
+ end
127
+
128
+ expect(action.call(app).version).to eq("ruby-3.4.6")
129
+ expect(app).to have_received(:version=).with("ruby-3.4.6")
130
+
131
+ expect(Open3).to have_received(:capture3).with("ruby -v")
132
+ end
133
+ end
134
+
135
+ context "when no version if provided, but a `truffleruby` implementation is found" do
136
+ let(:app) do
137
+ instance_double(
138
+ CreateRubyApp::App,
139
+ name: "truffleruby_app",
140
+ version: nil
141
+ )
142
+ end
143
+
144
+ it "returns the local version" do
145
+ %w[ruby jruby mruby rubinius].each do |ruby_implementation|
146
+ allow(Open3).to receive(:capture3).with(
147
+ "#{ruby_implementation} -v"
148
+ ).and_return(
149
+ ["", "", instance_double(Process::Status, success?: false)]
150
+ )
151
+ end
152
+
153
+ allow(Open3).to receive(:capture3).with("truffleruby -v").and_return([
154
+ "truffleruby 25.0.0",
155
+ "",
156
+ instance_double(
157
+ Process::Status, success?: true
158
+ )
159
+ ])
160
+
161
+ allow(app).to receive(:version=) do |version|
162
+ allow(app).to receive(:version).and_return(version)
163
+ end
164
+
165
+ expect(action.call(app).version).to eq("truffleruby-25.0.0")
166
+ expect(app).to have_received(:version=).with("truffleruby-25.0.0")
167
+
168
+ expect(Open3).to have_received(:capture3).with("truffleruby -v")
169
+ end
170
+ end
171
+
172
+ context "when no implementation of Ruby is found or provided" do
173
+ let(:app) do
174
+ instance_double(CreateRubyApp::App, name: "bar", version: nil)
175
+ end
176
+
177
+ it "throws an error" do
178
+ %w[ruby truffleruby jruby mruby rubinius].each do |ruby_implementation|
179
+ allow(Open3).to receive(:capture3).with(
180
+ "#{ruby_implementation} -v"
181
+ ).and_return(
182
+ ["", "", instance_double(Process::Status, success?: false)]
183
+ )
184
+ end
185
+
186
+ expect do
187
+ action.call(app)
188
+ end.to raise_error(
189
+ "No version of Ruby is found or provided"
190
+ )
191
+ end
192
+ end
193
+ end
194
+ end
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative "../../spec_helper"
4
2
 
5
3
  RSpec.describe CreateRubyApp::App do
6
4
  describe "#classify_name" do
7
5
  context "when the name of the app contains underscores" do
8
- let(:app) { described_class.new(name: "foo_bar_baz") }
6
+ let(:app) do
7
+ described_class.new(name: "foo_bar_baz", version: "ruby-3.2.9")
8
+ end
9
9
 
10
10
  it "removes the underscores and capitalizes each word" do
11
11
  expect(app.classify_name).to eq("FooBarBaz")
@@ -13,7 +13,7 @@ RSpec.describe CreateRubyApp::App do
13
13
  end
14
14
 
15
15
  context "when the name of the app contains no underscores" do
16
- let(:app) { described_class.new(name: "foobar") }
16
+ let(:app) { described_class.new(name: "foobar", version: "ruby-3.5.0") }
17
17
 
18
18
  it "capitalizes the name" do
19
19
  expect(app.classify_name).to eq("Foobar")
@@ -0,0 +1,112 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe CreateRubyApp::Commands do
4
+ describe CreateRubyApp::Commands::Version do
5
+ let(:command) { described_class.new }
6
+
7
+ it "outputs the current version" do
8
+ expect { command.call }.to output("1.3.0\n").to_stdout
9
+ end
10
+ end
11
+
12
+ describe CreateRubyApp::Commands::New do
13
+ let(:command) { described_class.new }
14
+ let(:app) { instance_double(CreateRubyApp::App) }
15
+
16
+ before do
17
+ allow(CreateRubyApp::App).to receive(:new).and_return(app)
18
+ allow(app).to receive(:run!)
19
+ end
20
+
21
+ it "creates and runs an app with the given name" do
22
+ command.call(name: "test_app")
23
+
24
+ expect(CreateRubyApp::App).to have_received(:new).with(
25
+ name: "test_app",
26
+ gems: [],
27
+ version: nil
28
+ )
29
+ expect(app).to have_received(:run!)
30
+ end
31
+
32
+ it "replaces dashes with underscores in the app name" do
33
+ command.call(name: "test-app")
34
+
35
+ expect(CreateRubyApp::App).to have_received(:new).with(
36
+ name: "test_app",
37
+ gems: [],
38
+ version: nil
39
+ )
40
+ end
41
+
42
+ it "accepts the `-r` flag for setting the Ruby version option" do
43
+ command.call(name: "test_app", ruby: "ruby-3.4.5")
44
+
45
+ expect(CreateRubyApp::App).to have_received(:new).with(
46
+ name: "test_app",
47
+ gems: [],
48
+ version: "ruby-3.4.5"
49
+ )
50
+ end
51
+
52
+ it "parses the `-g` flags for gems correctly" do
53
+ command.call(name: "test_app", gems: "rspec,pry,sinatra")
54
+
55
+ expect(CreateRubyApp::App).to have_received(:new).with(
56
+ name: "test_app",
57
+ gems: %w[rspec pry sinatra],
58
+ version: nil
59
+ )
60
+ end
61
+
62
+ it "handles empty gems string" do
63
+ command.call(name: "test_app", gems: "")
64
+
65
+ expect(CreateRubyApp::App).to have_received(:new).with(
66
+ name: "test_app",
67
+ gems: [],
68
+ version: nil
69
+ )
70
+ end
71
+
72
+ it "handles gems with spaces and empty entries" do
73
+ command.call(name: "test_app", gems: "rspec, pry, , sinatra")
74
+
75
+ expect(CreateRubyApp::App).to have_received(:new).with(
76
+ name: "test_app",
77
+ gems: %w[rspec pry sinatra],
78
+ version: nil
79
+ )
80
+ end
81
+
82
+ it "accepts both Ruby and gems options" do
83
+ command.call(name: "test_app", ruby: "jruby-9.4.0",
84
+ gems: "sequel,sinatra")
85
+
86
+ expect(CreateRubyApp::App).to have_received(:new).with(
87
+ name: "test_app",
88
+ gems: %w[sequel sinatra],
89
+ version: "jruby-9.4.0"
90
+ )
91
+ end
92
+ end
93
+ end
94
+
95
+ RSpec.describe CreateRubyApp::CLI do
96
+ describe ".call" do
97
+ let(:dry_cli) { instance_double(Dry::CLI) }
98
+
99
+ before do
100
+ allow(Dry::CLI).to receive(:new).with(CreateRubyApp::Commands)
101
+ .and_return(dry_cli)
102
+ allow(dry_cli).to receive(:call)
103
+ end
104
+
105
+ it "creates a Dry::CLI instance with commands and calls it" do
106
+ described_class.call
107
+
108
+ expect(Dry::CLI).to have_received(:new).with(CreateRubyApp::Commands)
109
+ expect(dry_cli).to have_received(:call)
110
+ end
111
+ end
112
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,11 @@
1
- # frozen_string_literal: true
1
+ require "simplecov"
2
2
 
3
- require "rspec"
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ minimum_coverage 90
6
+ end
4
7
 
8
+ require "rspec"
5
9
  require_relative "../lib/create_ruby_app"
6
10
 
7
11
  RSpec.configure do |config|
metadata CHANGED
@@ -1,60 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: create-ruby-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Jean Johansen
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
10
  date: 2019-03-11 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: thor
13
+ name: dry-cli
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 0.20.3
18
+ version: '1.0'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: 0.20.3
25
+ version: '1.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: logger
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.6'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.6'
27
40
  - !ruby/object:Gem::Dependency
28
41
  name: rake
29
42
  requirement: !ruby/object:Gem::Requirement
30
43
  requirements:
31
44
  - - "~>"
32
45
  - !ruby/object:Gem::Version
33
- version: 12.3.2
46
+ version: 13.3.0
34
47
  type: :development
35
48
  prerelease: false
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
38
51
  - - "~>"
39
52
  - !ruby/object:Gem::Version
40
- version: 12.3.2
53
+ version: 13.3.0
41
54
  - !ruby/object:Gem::Dependency
42
55
  name: rspec
43
56
  requirement: !ruby/object:Gem::Requirement
44
57
  requirements:
45
58
  - - "~>"
46
59
  - !ruby/object:Gem::Version
47
- version: 3.8.0
60
+ version: 3.13.1
48
61
  type: :development
49
62
  prerelease: false
50
63
  version_requirements: !ruby/object:Gem::Requirement
51
64
  requirements:
52
65
  - - "~>"
53
66
  - !ruby/object:Gem::Version
54
- version: 3.8.0
55
- description: |-
56
- create-ruby-app is an opinionated tool for scaffolding Ruby
57
- applications
67
+ version: 3.13.1
68
+ - !ruby/object:Gem::Dependency
69
+ name: simplecov
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.22.0
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.22.0
82
+ description: create-ruby-app is an opinionated tool for scaffolding Ruby applications
58
83
  email: mathias@mjj.io
59
84
  executables:
60
85
  - create-ruby-app
@@ -62,15 +87,18 @@ extensions: []
62
87
  extra_rdoc_files: []
63
88
  files:
64
89
  - CHANGELOG.md
90
+ - CLAUDE.md
91
+ - CODE_REVIEW.md
65
92
  - LICENSE
66
93
  - README.md
94
+ - REFACTORING_PLAN.md
67
95
  - bin/create-ruby-app
68
96
  - lib/create_ruby_app.rb
69
97
  - lib/create_ruby_app/actions/create_directories.rb
70
98
  - lib/create_ruby_app/actions/generate_files.rb
71
99
  - lib/create_ruby_app/actions/install_gems.rb
72
100
  - lib/create_ruby_app/actions/make_script_executable.rb
73
- - lib/create_ruby_app/actions/null_action.rb
101
+ - lib/create_ruby_app/actions/set_ruby_implementation.rb
74
102
  - lib/create_ruby_app/app.rb
75
103
  - lib/create_ruby_app/cli.rb
76
104
  - lib/create_ruby_app/templates/Gemfile.erb
@@ -79,17 +107,19 @@ files:
79
107
  - lib/create_ruby_app/templates/script_file.erb
80
108
  - lib/create_ruby_app/templates/spec_helper.erb
81
109
  - lib/create_ruby_app/version.rb
110
+ - spec/integration/app_creation_spec.rb
82
111
  - spec/lib/create_ruby_app/actions/create_directories_spec.rb
83
112
  - spec/lib/create_ruby_app/actions/generate_files_spec.rb
84
113
  - spec/lib/create_ruby_app/actions/install_gems_spec.rb
85
114
  - spec/lib/create_ruby_app/actions/make_script_executable_spec.rb
115
+ - spec/lib/create_ruby_app/actions/set_ruby_implementation_spec.rb
86
116
  - spec/lib/create_ruby_app/app_spec.rb
117
+ - spec/lib/create_ruby_app/cli_spec.rb
87
118
  - spec/spec_helper.rb
88
119
  homepage: https://github.com/majjoha/create-ruby-app
89
120
  licenses:
90
- - MIT
121
+ - ISC
91
122
  metadata: {}
92
- post_install_message:
93
123
  rdoc_options: []
94
124
  require_paths:
95
125
  - lib
@@ -97,21 +127,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
127
  requirements:
98
128
  - - ">="
99
129
  - !ruby/object:Gem::Version
100
- version: '0'
130
+ version: 3.4.5
101
131
  required_rubygems_version: !ruby/object:Gem::Requirement
102
132
  requirements:
103
133
  - - ">="
104
134
  - !ruby/object:Gem::Version
105
135
  version: '0'
106
136
  requirements: []
107
- rubygems_version: 3.0.3
108
- signing_key:
137
+ rubygems_version: 3.6.9
109
138
  specification_version: 4
110
139
  summary: Scaffold Ruby applications effortlessly
111
140
  test_files:
112
- - spec/spec_helper.rb
113
- - spec/lib/create_ruby_app/actions/make_script_executable_spec.rb
141
+ - spec/integration/app_creation_spec.rb
114
142
  - spec/lib/create_ruby_app/actions/create_directories_spec.rb
115
143
  - spec/lib/create_ruby_app/actions/generate_files_spec.rb
116
144
  - spec/lib/create_ruby_app/actions/install_gems_spec.rb
145
+ - spec/lib/create_ruby_app/actions/make_script_executable_spec.rb
146
+ - spec/lib/create_ruby_app/actions/set_ruby_implementation_spec.rb
117
147
  - spec/lib/create_ruby_app/app_spec.rb
148
+ - spec/lib/create_ruby_app/cli_spec.rb
149
+ - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CreateRubyApp
4
- module Actions
5
- class NullAction
6
- def self.call(app); end
7
- end
8
- end
9
- end