Skip to content

Commit

Permalink
lint: update files generate by cli
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoGabriel55 committed Aug 17, 2024
1 parent acbc7c4 commit cda86c5
Showing 1 changed file with 92 additions and 51 deletions.
143 changes: 92 additions & 51 deletions lib/sinatra_scaffold/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,33 @@ def create_directory_structure(app_name)

def create_main_files(app_name)
File.write("#{app_name}/config.ru", <<~RUBY)
require './app'
require "./app"
run Sinatra::Application
RUBY

File.write("#{app_name}/app/routes/users_routes.rb", <<~RUBY)
require 'sinatra/base'
get '/users' do
['User 1', 'User 2'].to_json
require "sinatra/base"
get "/users" do
["User 1", "User 2"].to_json
end
RUBY

File.write("#{app_name}/server.rb", <<~RUBY)
require 'sinatra'
require 'sinatra/base'
require 'dotenv'
require "sinatra"
require "sinatra/base"
require "dotenv"
Dotenv.load
set :bind, '0.0.0.0'
set :bind, "0.0.0.0"
set :default_content_type, :json
require './app/routes/users_routes'
get '/health-check' do
{ status: 'ok' }.to_json
require "./app/routes/users_routes"
get "/health-check" do
{status: "ok"}.to_json
end
RUBY

Expand All @@ -63,22 +63,23 @@ def create_main_files(app_name)

File.write("#{app_name}/spec/spec_helper.rb", <<~RUBY)
# frozen_string_literal: true
ENV['RACK_ENV'] = 'test'
require 'rubygems'
require 'bundler'
require_relative '../server'
ENV["RACK_ENV"] = "test"
require "rubygems"
require "bundler"
require_relative "../server"
Bundler.require(:default) # load all the default gems
Bundler.require(Sinatra::Base.environment) # load all the environment specific gems
Dotenv.load
def app
Sinatra::Application
end
RSpec.configure do |config|
config.include Rack::Test::Methods
config.expect_with :rspec do |expectations|
Expand All @@ -91,54 +92,94 @@ def app
config.run_all_when_everything_filtered = true
config.disable_monkey_patching!
config.warnings = true
config.default_formatter = 'doc' if config.files_to_run.one?
config.default_formatter = "doc" if config.files_to_run.one?
config.profile_examples = 10
config.order = :random
Kernel.srand config.seed
end
RUBY

File.write("#{app_name}/spec/requests/users_spec.rb", <<~RUBY)
require 'spec_helper'
RSpec.describe 'GET /users' do
it 'returns a list of users' do
get '/users'
require "spec_helper"
RSpec.describe "GET /users" do
it "returns a list of users" do
get "/users"
expect(last_response).to be_ok
expect(last_response.body).to eq(['User 1', 'User 2'].to_json)
expect(last_response.body).to eq(["User 1", "User 2"].to_json)
end
end
RUBY

File.write("#{app_name}/spec/requests/health_check_spec.rb", <<~RUBY)
require 'spec_helper'
RSpec.describe 'GET /health-check' do
it 'returns ok' do
get '/health-check'
require "spec_helper"
RSpec.describe "GET /health-check" do
it "returns ok" do
get "/health-check"
expect(last_response).to be_ok
expect(last_response.body).to eq({ status: 'ok' }.to_json)
expect(last_response.body).to eq({status: "ok"}.to_json)
end
end
RUBY

File.write("#{app_name}/Gemfile", <<~RUBY)
source 'https://rubygems.org'
gem 'sinatra'
gem 'dotenv'
source "https://rubygems.org"
gem "sinatra"
gem "dotenv"
gem "rake"
group :test do
gem 'rack-test'
gem 'rspec'
gem "rack-test"
gem "rspec"
end
group :development, :test do
gem 'pry'
gem "pry"
gem "standard"
end
RUBY

File.write("#{app_name}/Rakefile", <<~RUBY)
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
require "standard/rake"
task default: %i[spec standard]
RUBY

File.write("#{app_name}/README.md", <<~RUBY)
# #{app_name}
My Sinatra application
## Running
Run:
```sh
ruby server.rb
```
## Testing
Run:
```sh
bundle exec rspec
bundle exec rspec [file-or-directory-path]
```
## Lint
```sh
bundle exec rake standard
```
Lint and fix with:
```sh
bundle exec rake standard:fix
```
RUBY
end
end
end

0 comments on commit cda86c5

Please sign in to comment.