create-ruby-app 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 769d91354db227cdf9f8e82610666d2ba473e5f559e36708df0841850d1c777c
4
- data.tar.gz: 28eb12ac49e3334ffa4757b74793ac3b9081115c75dc4ab6a45c5b75e2b9ccd2
3
+ metadata.gz: ff8d6584b0b8947926a85ec594f77b14b2a2cd20c1257fa84a9eb340c8031082
4
+ data.tar.gz: 1d70581a447648a128dd208840c8faa709a1e7b7bfe51780cb3f4e0457716569
5
5
  SHA512:
6
- metadata.gz: 4ca234dfc8161a2f6335905e8898e3c3697e9eb736aeb7b7cd5e8f2c240cb212232b690eeb1fb395ffb7ce5a195e5631d7dd56ff1bfabe32f1a07e51b09b8381
7
- data.tar.gz: 0e26c8a4e941063b07d4bf8d64d147d0d462efb214b874ea5d81fca0a3bdc0b665d9cbb903372d0068585cab063f078924590cb53840e202b0b2ac872689bd83
6
+ metadata.gz: af116d9f492b893d3bc020800330c4e84d76f13f69e0112286aa0170511ced20bc81e177732a3813f158acb5448115c1d0bd4ddcf752f2cdc0f13a753cb0d428
7
+ data.tar.gz: 459e38e43ad058ba50b916b57d7f8262507821a85db7b4b26e05135522ccfe08d9a9849868552021d9f8ed18f7f13f726a3bd62fc9f382464d00cbd99146eade
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # 1.1.0
2
+ - Disable monkey patching for RSpec.
3
+ - Bump Ruby version to 2.6.2.
4
+ - Improve safety of `system` call.
5
+ - Add descriptions to command line arguments.
6
+
7
+ # 1.0.0
8
+ Initial release.
data/README.md CHANGED
@@ -1,13 +1,20 @@
1
1
  # Create Ruby App
2
2
  [![Build Status](https://travis-ci.org/majjoha/create-ruby-app.svg)](https://travis-ci.org/majjoha/create-ruby-app)
3
+ [![Gem Version](https://badge.fury.io/rb/create-ruby-app.svg)](http://badge.fury.io/rb/create-ruby-app)
3
4
 
4
5
  `create-ruby-app` is an opinionated tool for scaffolding Ruby applications
5
6
  effortlessly inspired by [Create React
6
7
  App](https://github.com/facebook/create-react-app). It generates only the
7
8
  essentials needed to start working.
8
9
 
10
+ It specifically targets non-Rails applications. For Ruby on Rails apps, it might
11
+ be worth looking into [Rails Application
12
+ Templates](https://guides.rubyonrails.org/rails_application_templates.html)
13
+ instead, and if you are building a gem, please take a look at the `bundle gem`
14
+ command.
15
+
9
16
  ## Requirements
10
- * Ruby (version 2.6.0 or newer).
17
+ * Ruby (version 2.6.2 or newer).
11
18
 
12
19
  ## Installation
13
20
  ```
@@ -2,8 +2,12 @@
2
2
 
3
3
  require_relative "create_ruby_app/app"
4
4
  require_relative "create_ruby_app/cli"
5
- require_relative "create_ruby_app/file_generator"
6
5
  require_relative "create_ruby_app/version"
6
+ require_relative "create_ruby_app/actions/create_directories"
7
+ require_relative "create_ruby_app/actions/generate_files"
8
+ require_relative "create_ruby_app/actions/install_gems"
9
+ require_relative "create_ruby_app/actions/make_script_executable"
10
+ require_relative "create_ruby_app/actions/null_action"
7
11
 
8
12
  module CreateRubyApp
9
13
  class CreateRubyApp
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "pathname"
5
+
6
+ module CreateRubyApp
7
+ module Actions
8
+ class CreateDirectories
9
+ def self.call(app)
10
+ [
11
+ Pathname.new("#{app.name}/bin"),
12
+ Pathname.new("#{app.name}/lib/#{app.name}"),
13
+ Pathname.new("#{app.name}/spec/lib/#{app.name}")
14
+ ].each(&FileUtils.method(:mkdir_p))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require "pathname"
5
+
6
+ module CreateRubyApp
7
+ module Actions
8
+ class GenerateFiles
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def self.call(app)
14
+ new(app).call
15
+ end
16
+
17
+ def call
18
+ generate_files
19
+ end
20
+
21
+ def script_file
22
+ generate_file(file: "script_file.erb", locals: {})
23
+ end
24
+
25
+ def lib_file
26
+ generate_file(file: "lib_file.erb", locals: { app: app.classify_name })
27
+ end
28
+
29
+ def spec_helper_file
30
+ generate_file(file: "spec_helper.erb", locals: { app: app.name })
31
+ end
32
+
33
+ def ruby_version_file
34
+ generate_file(
35
+ file: "ruby-version.erb",
36
+ locals: { version: app.version }
37
+ )
38
+ end
39
+
40
+ def gemfile
41
+ generate_file(file: "Gemfile.erb", locals: { gems: app.gems.sort })
42
+ end
43
+
44
+ private
45
+
46
+ attr_reader :app
47
+
48
+ def generate_files
49
+ files.each {|path, content| create_file(path: path, content: content) }
50
+ end
51
+
52
+ def create_file(path:, content:)
53
+ File.write("#{app.name}/#{path}", content)
54
+ end
55
+
56
+ def generate_file(file:, locals: [])
57
+ ERB
58
+ .new(read_file(file), trim_mode: TRIM_MODE)
59
+ .result_with_hash(locals: locals)
60
+ end
61
+
62
+ def read_file(file)
63
+ Pathname.new(__FILE__)
64
+ .dirname
65
+ .join("#{TEMPLATES_DIR}/#{file}")
66
+ .read
67
+ end
68
+
69
+ def files
70
+ {
71
+ "bin/#{app.name}" => script_file,
72
+ "lib/#{app.name}.rb" => lib_file,
73
+ "spec/spec_helper.rb" => spec_helper_file,
74
+ ".ruby-version" => ruby_version_file,
75
+ "Gemfile" => gemfile
76
+ }
77
+ end
78
+
79
+ TRIM_MODE = "<>"
80
+ TEMPLATES_DIR = "../templates"
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CreateRubyApp
4
+ module Actions
5
+ class InstallGems
6
+ def self.call(app)
7
+ Dir.chdir(app.name) { system("bundle", "install") }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module CreateRubyApp
6
+ module Actions
7
+ class MakeScriptExecutable
8
+ def self.call(app)
9
+ FileUtils.chmod("+x", "#{app.name}/bin/#{app.name}")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
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
@@ -17,30 +17,26 @@ module CreateRubyApp
17
17
  end
18
18
 
19
19
  def run!
20
- with_logger("Creating directories...", :create_directories)
21
- with_logger("Generating files...", :generate_files)
22
- with_logger("Making script executable...", :make_script_executable)
23
- with_logger("Installing gems...", :install_gems)
24
- with_logger("Happy hacking!")
20
+ with_logger("Creating directories...", Actions::CreateDirectories)
21
+ with_logger("Generating files...", Actions::GenerateFiles)
22
+ with_logger("Making script executable...", Actions::MakeScriptExecutable)
23
+ with_logger("Installing gems...", Actions::InstallGems)
24
+ with_logger("Happy hacking!", Actions::NullAction)
25
25
  end
26
26
 
27
27
  def classify_name
28
28
  name.split("_").collect(&:capitalize).join
29
29
  end
30
30
 
31
- attr_accessor :name, :gems, :version, :logger
31
+ attr_reader :name, :gems, :version, :logger
32
32
 
33
- RUBY_VERSION = "ruby-2.6.0"
33
+ RUBY_VERSION = "ruby-2.6.2"
34
34
 
35
35
  private
36
36
 
37
- def with_logger(text, callable = false)
37
+ def with_logger(text, action)
38
38
  logger.info(text)
39
- file_generator.method(callable).call if callable
40
- end
41
-
42
- def file_generator
43
- @file_generator ||= FileGenerator.new(app: self)
39
+ action.call(self)
44
40
  end
45
41
  end
46
42
  end
@@ -23,9 +23,18 @@ module CreateRubyApp
23
23
  \x5$ create-ruby-app new -g sinatra,sequel -r ruby-2.6.0 web_app
24
24
  \x5$ create-ruby-app new --ruby jruby-2.9.6.0 my_app
25
25
  DESC
26
-
27
- method_option(:ruby, default: App::RUBY_VERSION, aliases: "-r")
28
- method_option(:gems, default: "", aliases: "-g")
26
+ method_option(
27
+ :ruby,
28
+ aliases: "-r",
29
+ desc: "Specify which Ruby version to use for the project",
30
+ default: App::RUBY_VERSION
31
+ )
32
+ method_option(
33
+ :gems,
34
+ aliases: "-g",
35
+ desc: "Specify which gems to add to the project",
36
+ default: ""
37
+ )
29
38
  def new(name)
30
39
  App.new(
31
40
  name: replace_dashes_with_underscores(name),
@@ -7,4 +7,6 @@ RSpec.configure do |config|
7
7
  config.expect_with(:rspec) do |c|
8
8
  c.syntax = :expect
9
9
  end
10
+
11
+ config.disable_monkey_patching!
10
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CreateRubyApp
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe CreateRubyApp::Actions::CreateDirectories do
6
+ describe ".call" do
7
+ let(:app) { instance_double("app", name: "foo_bar") }
8
+ let(:action) { described_class }
9
+
10
+ it "creates the directories" do
11
+ allow(FileUtils).to receive(:mkdir_p)
12
+
13
+ action.call(app)
14
+
15
+ expect(FileUtils).to have_received(:mkdir_p).exactly(3).times
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe CreateRubyApp::Actions::GenerateFiles do
6
+ describe "#generate_gemfile" do
7
+ context "when no additional gems are added" do
8
+ let(:app) { instance_double("app", gems: []) }
9
+ let(:action) { described_class.new(app) }
10
+ let(:gemfile) do
11
+ <<~GEMFILE
12
+ # frozen_string_literal: true
13
+
14
+ source "https://rubygems.org"
15
+
16
+ group :test, :development do
17
+ gem "rspec"
18
+ end
19
+ GEMFILE
20
+ end
21
+
22
+ it "produces a Gemfile without any additional gems" do
23
+ expect(action.gemfile).to eq(gemfile)
24
+ end
25
+ end
26
+
27
+ context "when additional gems are added" do
28
+ let(:app) { instance_double("app", gems: %w[sinatra sqlite]) }
29
+ let(:action) { described_class.new(app) }
30
+ let(:gemfile) do
31
+ <<~GEMFILE
32
+ # frozen_string_literal: true
33
+
34
+ source "https://rubygems.org"
35
+
36
+ group :test, :development do
37
+ gem "rspec"
38
+ end
39
+
40
+ gem "sinatra"
41
+ gem "sqlite"
42
+ GEMFILE
43
+ end
44
+
45
+ it "produces a Gemfile with the gems" do
46
+ expect(action.gemfile).to eq(gemfile)
47
+ end
48
+ end
49
+ end
50
+
51
+ describe "#generate_ruby_version_file" do
52
+ context "when no version is specified" do
53
+ let(:app) do
54
+ instance_double("app", version: CreateRubyApp::App::RUBY_VERSION)
55
+ end
56
+ let(:action) { described_class.new(app) }
57
+
58
+ it { expect(action.ruby_version_file).to eq("ruby-2.6.2") }
59
+ end
60
+
61
+ context "when a version is specified" do
62
+ let(:app) { instance_double("app", version: "ruby-2.5.0") }
63
+ let(:action) { described_class.new(app) }
64
+
65
+ it { expect(action.ruby_version_file).to eq("ruby-2.5.0") }
66
+ end
67
+ end
68
+
69
+ describe "#generate_lib_file" do
70
+ context "when generating a lib file" do
71
+ let(:app) { instance_double("app") }
72
+ let(:action) { described_class.new(app) }
73
+ let(:lib_file) do
74
+ <<~LIB_FILE
75
+ # frozen_string_literal: true
76
+
77
+ module ThisIsAnApp
78
+ class ThisIsAnApp
79
+ end
80
+ end
81
+ LIB_FILE
82
+ end
83
+
84
+ it "fills out a lib file with the correct module and class name" do
85
+ allow(app).to receive(:classify_name).and_return("ThisIsAnApp")
86
+
87
+ expect(action.lib_file).to eq(lib_file)
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "#generate_spec_helper_file" do
93
+ context "when generating a spec helper file" do
94
+ let(:app) { instance_double("app", name: "this_is_an_app") }
95
+ let(:action) { described_class.new(app) }
96
+ let(:spec_helper) do
97
+ <<~SPEC_HELPER
98
+ # frozen_string_literal: true
99
+
100
+ require "rspec"
101
+ require_relative "../lib/this_is_an_app"
102
+
103
+ RSpec.configure do |config|
104
+ config.expect_with(:rspec) do |c|
105
+ c.syntax = :expect
106
+ end
107
+
108
+ config.disable_monkey_patching!
109
+ end
110
+ SPEC_HELPER
111
+ end
112
+
113
+ it "fills out the file and references the app" do
114
+ expect(action.spec_helper_file).to eq(spec_helper)
115
+ end
116
+ end
117
+ end
118
+
119
+ describe "#generate_script_file" do
120
+ context "when generating an executable script file" do
121
+ let(:app) { instance_double("app") }
122
+ let(:action) { described_class.new(app) }
123
+ let(:script_file) do
124
+ <<~SCRIPT_FILE
125
+ #!/usr/bin/env ruby
126
+
127
+ # frozen_string_literal: true
128
+ SCRIPT_FILE
129
+ end
130
+
131
+ it "fills out a default script file template" do
132
+ expect(action.script_file).to eq(script_file)
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe CreateRubyApp::Actions::InstallGems do
6
+ describe ".call" do
7
+ let(:app) { instance_double("app", name: "foo_bar") }
8
+ let(:action) { described_class }
9
+
10
+ it "installs the gems" do
11
+ allow(Dir).to receive(:chdir).with("foo_bar")
12
+
13
+ action.call(app)
14
+
15
+ expect(Dir).to have_received(:chdir).with("foo_bar")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../spec_helper"
4
+
5
+ RSpec.describe CreateRubyApp::Actions::MakeScriptExecutable do
6
+ describe ".call" do
7
+ let(:app) { instance_double("app", name: "foo_bar") }
8
+ let(:action) { described_class }
9
+
10
+ it "creates the directories" do
11
+ allow(FileUtils).to receive(:chmod).with("+x", "foo_bar/bin/foo_bar")
12
+
13
+ action.call(app)
14
+
15
+ expect(FileUtils).to(
16
+ have_received(:chmod).with("+x", "foo_bar/bin/foo_bar")
17
+ )
18
+ end
19
+ end
20
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "../../spec_helper"
4
4
 
5
- describe CreateRubyApp::App do
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
8
  let(:app) { described_class.new(name: "foo_bar_baz") }
data/spec/spec_helper.rb CHANGED
@@ -8,4 +8,6 @@ RSpec.configure do |config|
8
8
  config.expect_with(:rspec) do |c|
9
9
  c.syntax = :expect
10
10
  end
11
+
12
+ config.disable_monkey_patching!
11
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: create-ruby-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Jean Johansen
@@ -61,21 +61,29 @@ executables:
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
+ - CHANGELOG.md
64
65
  - LICENSE
65
66
  - README.md
66
67
  - bin/create-ruby-app
67
68
  - lib/create_ruby_app.rb
69
+ - lib/create_ruby_app/actions/create_directories.rb
70
+ - lib/create_ruby_app/actions/generate_files.rb
71
+ - lib/create_ruby_app/actions/install_gems.rb
72
+ - lib/create_ruby_app/actions/make_script_executable.rb
73
+ - lib/create_ruby_app/actions/null_action.rb
68
74
  - lib/create_ruby_app/app.rb
69
75
  - lib/create_ruby_app/cli.rb
70
- - lib/create_ruby_app/file_generator.rb
71
76
  - lib/create_ruby_app/templates/Gemfile.erb
72
77
  - lib/create_ruby_app/templates/lib_file.erb
73
78
  - lib/create_ruby_app/templates/ruby-version.erb
74
79
  - lib/create_ruby_app/templates/script_file.erb
75
80
  - lib/create_ruby_app/templates/spec_helper.erb
76
81
  - lib/create_ruby_app/version.rb
82
+ - spec/lib/create_ruby_app/actions/create_directories_spec.rb
83
+ - spec/lib/create_ruby_app/actions/generate_files_spec.rb
84
+ - spec/lib/create_ruby_app/actions/install_gems_spec.rb
85
+ - spec/lib/create_ruby_app/actions/make_script_executable_spec.rb
77
86
  - spec/lib/create_ruby_app/app_spec.rb
78
- - spec/lib/create_ruby_app/file_generator_spec.rb
79
87
  - spec/spec_helper.rb
80
88
  homepage: https://github.com/majjoha/create-ruby-app
81
89
  licenses:
@@ -96,11 +104,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
104
  - !ruby/object:Gem::Version
97
105
  version: '0'
98
106
  requirements: []
99
- rubygems_version: 3.0.1
107
+ rubygems_version: 3.0.3
100
108
  signing_key:
101
109
  specification_version: 4
102
110
  summary: Scaffold Ruby applications effortlessly
103
111
  test_files:
104
112
  - spec/spec_helper.rb
105
- - spec/lib/create_ruby_app/file_generator_spec.rb
113
+ - spec/lib/create_ruby_app/actions/make_script_executable_spec.rb
114
+ - spec/lib/create_ruby_app/actions/create_directories_spec.rb
115
+ - spec/lib/create_ruby_app/actions/generate_files_spec.rb
116
+ - spec/lib/create_ruby_app/actions/install_gems_spec.rb
106
117
  - spec/lib/create_ruby_app/app_spec.rb
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "erb"
4
- require "fileutils"
5
- require "pathname"
6
-
7
- module CreateRubyApp
8
- class FileGenerator
9
- def initialize(app: App.new)
10
- @app = app
11
- end
12
-
13
- def generate_gemfile
14
- generate_file(file: "Gemfile.erb", locals: { gems: app.gems.sort })
15
- end
16
-
17
- def generate_lib_file
18
- generate_file(file: "lib_file.erb", locals: { app: app.classify_name })
19
- end
20
-
21
- def generate_ruby_version_file
22
- generate_file(file: "ruby-version.erb", locals: { version: app.version })
23
- end
24
-
25
- def generate_script_file
26
- generate_file(file: "script_file.erb", locals: {})
27
- end
28
-
29
- def generate_spec_helper_file
30
- generate_file(file: "spec_helper.erb", locals: { app: app.name })
31
- end
32
-
33
- def create_directories
34
- directories.each(&FileUtils.method(:mkdir_p))
35
- end
36
-
37
- def generate_files
38
- files.each {|path, content| create_file(path: path, content: content) }
39
- end
40
-
41
- def make_script_executable
42
- FileUtils.chmod("+x", "#{app.name}/bin/#{app.name}")
43
- end
44
-
45
- def install_gems
46
- system("cd #{app.name} && bundle install")
47
- end
48
-
49
- private
50
-
51
- attr_accessor :app
52
-
53
- def generate_file(file:, locals: [])
54
- ERB
55
- .new(read_file(file), trim_mode: TRIM_MODE)
56
- .result_with_hash(locals: locals)
57
- end
58
-
59
- def read_file(file)
60
- Pathname.new(__FILE__).dirname.join("#{TEMPLATES_DIR}/#{file}").read
61
- end
62
-
63
- def create_file(path:, content:)
64
- File.write("#{app.name}/#{path}", content)
65
- end
66
-
67
- def files
68
- {
69
- "bin/#{app.name}" => generate_script_file,
70
- "lib/#{app.name}.rb" => generate_lib_file,
71
- "spec/spec_helper.rb" => generate_spec_helper_file,
72
- ".ruby-version" => generate_ruby_version_file,
73
- "Gemfile" => generate_gemfile
74
- }
75
- end
76
-
77
- def directories
78
- [
79
- Pathname.new("#{app.name}/bin"),
80
- Pathname.new("#{app.name}/lib/#{app.name}"),
81
- Pathname.new("#{app.name}/spec/lib/#{app.name}")
82
- ]
83
- end
84
-
85
- TEMPLATES_DIR = "templates"
86
- TRIM_MODE = "<>"
87
- end
88
- end
@@ -1,138 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../../spec_helper"
4
-
5
- describe CreateRubyApp::FileGenerator do
6
- describe "#generate_gemfile" do
7
- context "when no additional gems are added" do
8
- let(:file_generator) { described_class.new }
9
-
10
- it "produces a Gemfile without any additional gems" do
11
- expect(file_generator.generate_gemfile).to eq(
12
- <<~GEMFILE
13
- # frozen_string_literal: true
14
-
15
- source "https://rubygems.org"
16
-
17
- group :test, :development do
18
- gem "rspec"
19
- end
20
- GEMFILE
21
- )
22
- end
23
- end
24
-
25
- context "when additional gems are added" do
26
- let(:app) { instance_double("app") }
27
- let(:file_generator) { described_class.new(app: app) }
28
-
29
- it "produces a Gemfile with the gems" do
30
- allow(app).to receive(:gems).and_return(%w[sinatra sqlite])
31
-
32
- expect(file_generator.generate_gemfile).to eq(
33
- <<~GEMFILE
34
- # frozen_string_literal: true
35
-
36
- source "https://rubygems.org"
37
-
38
- group :test, :development do
39
- gem "rspec"
40
- end
41
-
42
- gem "sinatra"
43
- gem "sqlite"
44
- GEMFILE
45
- )
46
- end
47
- end
48
- end
49
-
50
- describe "#generate_ruby_version_file" do
51
- context "when no version is specified" do
52
- let(:app) { instance_double("app") }
53
- let(:file_generator) { described_class.new(app: app) }
54
-
55
- it "uses version 2.6.0 as default" do
56
- allow(app).to receive(:version).and_return("ruby-2.6.0")
57
-
58
- expect(file_generator.generate_ruby_version_file).to eq("ruby-2.6.0")
59
- end
60
- end
61
-
62
- context "when a version is specified" do
63
- let(:app) { instance_double("app") }
64
- let(:file_generator) { described_class.new(app: app) }
65
-
66
- it "uses the version in the .ruby-version file" do
67
- allow(app).to receive(:version).and_return("ruby-2.5.0")
68
-
69
- expect(file_generator.generate_ruby_version_file).to eq("ruby-2.5.0")
70
- end
71
- end
72
- end
73
-
74
- describe "#generate_lib_file" do
75
- context "when generating a lib file" do
76
- let(:app) { instance_double("app") }
77
- let(:file_generator) { described_class.new(app: app) }
78
-
79
- it "fills out a lib file with the correct module and class name" do
80
- allow(app).to receive(:name).and_return("this_is_an_app")
81
- allow(app).to receive(:classify_name).and_return("ThisIsAnApp")
82
-
83
- expect(file_generator.generate_lib_file).to eq(
84
- <<~LIB_FILE
85
- # frozen_string_literal: true
86
-
87
- module ThisIsAnApp
88
- class ThisIsAnApp
89
- end
90
- end
91
- LIB_FILE
92
- )
93
- end
94
- end
95
- end
96
-
97
- describe "#generate_spec_helper_file" do
98
- context "when generating a spec helper file" do
99
- let(:app) { instance_double("app") }
100
- let(:file_generator) { described_class.new(app: app) }
101
-
102
- it "fills out the file and references the app" do
103
- allow(app).to receive(:name).and_return("this_is_an_app")
104
-
105
- expect(file_generator.generate_spec_helper_file).to eq(
106
- <<~SPEC_HELPER
107
- # frozen_string_literal: true
108
-
109
- require "rspec"
110
- require_relative "../lib/this_is_an_app"
111
-
112
- RSpec.configure do |config|
113
- config.expect_with(:rspec) do |c|
114
- c.syntax = :expect
115
- end
116
- end
117
- SPEC_HELPER
118
- )
119
- end
120
- end
121
- end
122
-
123
- describe "#generate_script_file" do
124
- context "when generating an executable script file" do
125
- let(:file_generator) { described_class.new }
126
-
127
- it "fills out a default script file template" do
128
- expect(file_generator.generate_script_file).to eq(
129
- <<~SCRIPT_FILE
130
- #!/usr/bin/env ruby
131
-
132
- # frozen_string_literal: true
133
- SCRIPT_FILE
134
- )
135
- end
136
- end
137
- end
138
- end