create-ruby-app 1.2.0 → 1.4.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.
@@ -0,0 +1,196 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe CreateRubyApp::Actions::SetRubyImplementation do
6
+ describe ".call" do
7
+ let(:action) { described_class }
8
+
9
+ context "when a Ruby version is provided" do
10
+ let(:app) do
11
+ instance_double(CreateRubyApp::App, name: "foo", version: "ruby-3.4.5")
12
+ end
13
+
14
+ it "returns the specific version provided" do
15
+ expect(action.call(app).version).to eq("ruby-3.4.5")
16
+ end
17
+ end
18
+
19
+ context "when no version if provided, but an `mruby` implementation is found" do
20
+ let(:app) do
21
+ instance_double(CreateRubyApp::App, name: "mruby_app", version: nil)
22
+ end
23
+
24
+ it "returns the local version" do
25
+ %w[ruby truffleruby jruby rubinius].each do |ruby_implementation|
26
+ allow(Open3).to receive(:capture3).with(
27
+ "#{ruby_implementation} -v"
28
+ ).and_return(
29
+ ["", "", instance_double(Process::Status, success?: false)]
30
+ )
31
+ end
32
+
33
+ allow(Open3).to receive(:capture3).with("mruby -v").and_return(
34
+ ["mruby 3.3.0", "", instance_double(Process::Status, success?: true)]
35
+ )
36
+
37
+ allow(app).to receive(:version=) do |version|
38
+ allow(app).to receive(:version).and_return(version)
39
+ end
40
+
41
+ expect(action.call(app).version).to eq("mruby-3.3.0")
42
+ expect(app).to have_received(:version=).with("mruby-3.3.0")
43
+
44
+ expect(Open3).to have_received(:capture3).with("mruby -v")
45
+ end
46
+ end
47
+
48
+ context "when no version if provided, but a `jruby` implementation is found" do
49
+ let(:app) do
50
+ instance_double(CreateRubyApp::App, name: "jruby_app", version: nil)
51
+ end
52
+
53
+ it "returns the local version" do
54
+ %w[ruby truffleruby mruby rubinius].each do |ruby_implementation|
55
+ allow(Open3).to receive(:capture3).with(
56
+ "#{ruby_implementation} -v"
57
+ ).and_return(
58
+ ["", "", instance_double(Process::Status, success?: false)]
59
+ )
60
+ end
61
+
62
+ allow(Open3).to receive(:capture3).with("jruby -v").and_return([
63
+ "jruby 9.4.14.0", "", instance_double(
64
+ Process::Status, success?: true
65
+ )
66
+ ])
67
+
68
+ allow(app).to receive(:version=) do |version|
69
+ allow(app).to receive(:version).and_return(version)
70
+ end
71
+
72
+ expect(action.call(app).version).to eq("jruby-9.4.14.0")
73
+ expect(app).to have_received(:version=).with("jruby-9.4.14.0")
74
+
75
+ expect(Open3).to have_received(:capture3).with("jruby -v")
76
+ end
77
+ end
78
+
79
+ context "when no version if provided, but a `rubinius` implementation is found" do
80
+ let(:app) do
81
+ instance_double(CreateRubyApp::App, name: "rubinius_app", version: nil)
82
+ end
83
+
84
+ it "returns the local version" do
85
+ %w[ruby truffleruby jruby mruby].each do |ruby_implementation|
86
+ allow(Open3).to receive(:capture3).with(
87
+ "#{ruby_implementation} -v"
88
+ ).and_return(
89
+ ["", "", instance_double(Process::Status, success?: false)]
90
+ )
91
+ end
92
+
93
+ allow(Open3).to receive(:capture3).with("rubinius -v").and_return(
94
+ ["rubinius 5.0", "", instance_double(Process::Status, success?: true)]
95
+ )
96
+
97
+ allow(app).to receive(:version=) do |version|
98
+ allow(app).to receive(:version).and_return(version)
99
+ end
100
+
101
+ expect(action.call(app).version).to eq("rubinius-5.0")
102
+ expect(app).to have_received(:version=).with("rubinius-5.0")
103
+
104
+ expect(Open3).to have_received(:capture3).with("rubinius -v")
105
+ end
106
+ end
107
+
108
+ context "when no version if provided, but a `ruby` implementation is found" do
109
+ let(:app) do
110
+ instance_double(CreateRubyApp::App, name: "ruby_app", version: nil)
111
+ end
112
+
113
+ it "returns the local version" do
114
+ %w[truffleruby jruby mruby rubinius].each do |ruby_implementation|
115
+ allow(Open3).to receive(:capture3).with(
116
+ "#{ruby_implementation} -v"
117
+ ).and_return(
118
+ ["", "", instance_double(Process::Status, success?: false)]
119
+ )
120
+ end
121
+
122
+ allow(Open3).to receive(:capture3).with("ruby -v").and_return(
123
+ ["ruby 3.4.6", "", instance_double(Process::Status, success?: true)]
124
+ )
125
+
126
+ allow(app).to receive(:version=) do |version|
127
+ allow(app).to receive(:version).and_return(version)
128
+ end
129
+
130
+ expect(action.call(app).version).to eq("ruby-3.4.6")
131
+ expect(app).to have_received(:version=).with("ruby-3.4.6")
132
+
133
+ expect(Open3).to have_received(:capture3).with("ruby -v")
134
+ end
135
+ end
136
+
137
+ context "when no version if provided, but a `truffleruby` implementation is found" do
138
+ let(:app) do
139
+ instance_double(
140
+ CreateRubyApp::App,
141
+ name: "truffleruby_app",
142
+ version: nil
143
+ )
144
+ end
145
+
146
+ it "returns the local version" do
147
+ %w[ruby jruby mruby rubinius].each do |ruby_implementation|
148
+ allow(Open3).to receive(:capture3).with(
149
+ "#{ruby_implementation} -v"
150
+ ).and_return(
151
+ ["", "", instance_double(Process::Status, success?: false)]
152
+ )
153
+ end
154
+
155
+ allow(Open3).to receive(:capture3).with("truffleruby -v").and_return([
156
+ "truffleruby 25.0.0",
157
+ "",
158
+ instance_double(
159
+ Process::Status, success?: true
160
+ )
161
+ ])
162
+
163
+ allow(app).to receive(:version=) do |version|
164
+ allow(app).to receive(:version).and_return(version)
165
+ end
166
+
167
+ expect(action.call(app).version).to eq("truffleruby-25.0.0")
168
+ expect(app).to have_received(:version=).with("truffleruby-25.0.0")
169
+
170
+ expect(Open3).to have_received(:capture3).with("truffleruby -v")
171
+ end
172
+ end
173
+
174
+ context "when no implementation of Ruby is found or provided" do
175
+ let(:app) do
176
+ instance_double(CreateRubyApp::App, name: "bar", version: nil)
177
+ end
178
+
179
+ it "throws an error" do
180
+ %w[ruby truffleruby jruby mruby rubinius].each do |ruby_implementation|
181
+ allow(Open3).to receive(:capture3).with(
182
+ "#{ruby_implementation} -v"
183
+ ).and_return(
184
+ ["", "", instance_double(Process::Status, success?: false)]
185
+ )
186
+ end
187
+
188
+ expect do
189
+ action.call(app)
190
+ end.to raise_error(
191
+ "No version of Ruby is found or provided"
192
+ )
193
+ end
194
+ end
195
+ end
196
+ end
@@ -5,7 +5,9 @@ require_relative "../../spec_helper"
5
5
  RSpec.describe CreateRubyApp::App do
6
6
  describe "#classify_name" do
7
7
  context "when the name of the app contains underscores" do
8
- let(:app) { described_class.new(name: "foo_bar_baz") }
8
+ let(:app) do
9
+ described_class.new(name: "foo_bar_baz", version: "ruby-3.2.9")
10
+ end
9
11
 
10
12
  it "removes the underscores and capitalizes each word" do
11
13
  expect(app.classify_name).to eq("FooBarBaz")
@@ -13,7 +15,7 @@ RSpec.describe CreateRubyApp::App do
13
15
  end
14
16
 
15
17
  context "when the name of the app contains no underscores" do
16
- let(:app) { described_class.new(name: "foobar") }
18
+ let(:app) { described_class.new(name: "foobar", version: "ruby-3.5.0") }
17
19
 
18
20
  it "capitalizes the name" do
19
21
  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.4.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,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rspec"
3
+ require "simplecov"
4
+
5
+ SimpleCov.start do
6
+ add_filter "/spec/"
7
+ minimum_coverage 90
8
+ end
4
9
 
10
+ require "rspec"
5
11
  require_relative "../lib/create_ruby_app"
6
12
 
7
13
  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.2.0
4
+ version: 1.4.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.1.2
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