jefferies_tube 1.5.2 → 1.6.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: b198777c05f8317a5e390997d5591bff0364660bf109cd8eeff3f0f21bdd8da4
4
- data.tar.gz: 12cde353d7a77b39f2b6625a90b156dbe2af4e74737365923838f313cc47ff35
3
+ metadata.gz: 716c0ff79c3d49dc0a798f652893f52f2da6b8db643b21b84c76dbe1e56c765f
4
+ data.tar.gz: 79f241ab6a97ebfc27fa2c4fbf070927fb4a2f960317532e11fbf80b1128e350
5
5
  SHA512:
6
- metadata.gz: 5a20b3231274286cf315f85defcaa66e0ba1ad8f3be0cd87dc981d3b1fc1f4ee3abe5346b026bbe63b53afdc7fcd809e2a028a46b58ea9b9898ee23aa3de3764
7
- data.tar.gz: '084c3100acaa3a1b8d331b2facd9627ed165a674251a3109a63cad3c54b78899b21981f5321397c5ba00e3a42ff124373723bdeed90598b7268461633a79f0b0'
6
+ metadata.gz: 84f5131653cd0887fe715cdd4d9f113468aa3c4da74b37b3b3bd127ad56b34dbb88ebd09421034cbc3f066578dbdbdc14af9c9a9646418b79fdf45e8d1162611
7
+ data.tar.gz: 103babd618aa140b2f6dfd1c7e21f30e42ea4b9613d5dc2d9db4f4d693b0e4e15a501c0cb742a57e45ae07d9b8aa4596406efc501c5320b4535a1ea56c1940a9
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.1.1
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ This project attempts to follow [semantic versioning](https://semver.org/)
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 1.6.0
10
+ Default rake task that runs rspec with simlecov and rubocop!
11
+ ## 1.5.4
12
+ Fix a bug in the prompt if Pry is present.
13
+ ## 1.5.3
14
+ * Minor tweaks to the IRB console when sshing. Don't use JT IRB locally
9
15
  ## 1.5
10
16
 
11
17
  * enhancements
data/README.md CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
26
26
 
27
27
  JefferiesTube by default installs a catchall route that will render 404 for you and supress the rollbar error. This also allows you to create super easy custom error pages.
28
28
 
29
- Simple put a template in the parent app in `app/views/errors/404.haml` (or html or erb, etc) and it will be rendered instead of the default Jefferies tube error.
29
+ Simple put a template in the parent app in `app/views/errors/404.haml` (or html or erb, etc) and it will be rendered instead of the default JefferiesTube error.
30
30
 
31
31
  #### 500 handling
32
32
 
@@ -182,6 +182,47 @@ JefferiesTube.configure do |config|
182
182
  end
183
183
  ```
184
184
 
185
+ ### Default Rake Tasks
186
+ JefferiesTube sets up the default rake task to run rspec with simplecov, then rubocop. Everything should be configued to the default automatically. All you need to do is run `rake`!
187
+
188
+ ### Simplecov
189
+ JefferiesTube configures Simplecov to check for coverage based solely on groups, not on the overall project. This is to ensure that important/easy files are covered and unimportant files can be untested without causing the total percentage to go down. If you override the required test coverage, warnings will show if you do not match the JefferiesTube default. The default required test coverage is as follows:
190
+
191
+ ```
192
+ 'Controllers' => 10,
193
+ 'API Controllers' => 100,
194
+ 'Models' => 100,
195
+ 'Services' => 100,
196
+ 'Helpers' => 10,
197
+ 'Policies' => 100,
198
+ 'Jobs' => 100,
199
+ 'Mailers' => 0,
200
+ 'Libraries' => 0,
201
+ 'Plugins' => 0,
202
+ 'Ungrouped' => 10
203
+ ```
204
+
205
+ and can be overrided by setting `JefferiesTube::Coverage.required_coverage` in an initializer.
206
+
207
+ ```
208
+ JefferiesTube::Coverage.required_coverage = {
209
+ 'Controllers' => 0,
210
+ 'API Controllers' => 0,
211
+ 'Models' => 0,
212
+ 'Services' => 0,
213
+ 'Helpers' => 0,
214
+ 'Policies' => 0,
215
+ 'Jobs' => 0,
216
+ 'Mailers' => 0,
217
+ 'Libraries' => 0,
218
+ 'Plugins' => 0,
219
+ 'Ungrouped' => 0
220
+ }
221
+ ```
222
+
223
+ ## Rubocop
224
+ Our Rubocop rules are built from the ground up to ensure the rules are all "actually good"! The first time you run `rake` JT will create a .rubocop.yml configuration file that inherits all the rules from JT. You can add/modify that file if you need to customize the rules for your project.
225
+
185
226
  ## Contributing
186
227
 
187
228
  1. Fork it ( http://github.com/<my-github-username>/jefferies_tube/fork )
data/default.yml ADDED
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ DisabledByDefault: true
3
+ SuggestExtensions: false
4
+ Layout/LineLength:
5
+ Max: 200
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "bundler-audit", '~> 0.9.0'
28
28
  spec.add_dependency "pry", '~> 0.13'
29
+ spec.add_dependency 'rubocop', '~> 1.26'
30
+ spec.add_dependency 'simplecov'
29
31
  end
@@ -51,4 +51,4 @@ namespace :deploy do
51
51
  end
52
52
 
53
53
  before 'deploy:migrate', 'deploy:backup_database'
54
- before 'deploy', 'deploy:scan_gems'
54
+ before 'deploy', 'deploy:scan_gems'
@@ -3,7 +3,7 @@ namespace :rails do
3
3
  task :console do
4
4
  console_roles = [roles(:worker), roles(:app)].find(&:any?)
5
5
  on console_roles, primary: true do |host, user|
6
- run_interactively "RAILS_ENV=#{rails_env} bundle exec rails console"
6
+ run_interactively "RAILS_ENV=#{rails_env} JEFFERIES_TUBE_IRB=1 bundle exec rails console"
7
7
  end
8
8
  end
9
9
 
@@ -0,0 +1,3 @@
1
+ inherit_gem:
2
+ jefferies_tube:
3
+ - default.yml
@@ -0,0 +1,68 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/test/'
4
+ add_filter '/config/'
5
+
6
+ add_group 'Controllers' do |src_file|
7
+ src_file.filename.include?('app/controllers') && !src_file.filename.include?('api')
8
+ end
9
+ add_group 'API Controllers' do |src_file|
10
+ src_file.filename.include?('app/controllers') && src_file.filename.include?('api')
11
+ end
12
+ add_group 'Models', 'app/models'
13
+ add_group 'Services', 'app/services'
14
+ add_group 'Helpers', 'app/helpers'
15
+ add_group 'Policies', 'app/policies'
16
+ add_group 'Jobs', 'app/jobs'
17
+ add_group 'Mailers', 'app/mailers'
18
+ add_group 'Libraries', 'lib'
19
+ add_group 'Plugins', 'vendor/plugins'
20
+ end
21
+ SimpleCov.at_exit do
22
+ ideal_coverage = {
23
+ 'Controllers' => 10,
24
+ 'API Controllers' => 100,
25
+ 'Models' => 100,
26
+ 'Services' => 100,
27
+ 'Helpers' => 10,
28
+ 'Policies' => 100,
29
+ 'Jobs' => 100,
30
+ 'Mailers' => 0,
31
+ 'Libraries' => 0,
32
+ 'Plugins' => 0,
33
+ 'Ungrouped' => 10
34
+ }
35
+ required_coverage = JefferiesTube::Coverage.required_coverage
36
+ overall_failed = false
37
+ output = "=====================Test Coverage=====================\n"
38
+ output << "Group Files Current / Required (Ideal)\n"
39
+ SimpleCov.result.groups.each do |name, group|
40
+ next if group.size.zero?
41
+ failed = false
42
+ warning = false
43
+ if group.covered_percent.round(2) < ideal_coverage[name]
44
+ warning = true
45
+ end
46
+ if group.covered_percent.round(2) < required_coverage[name]
47
+ warning = false
48
+ failed = true
49
+ overall_failed = true
50
+ end
51
+ color = if failed
52
+ "\e[31m"
53
+ elsif warning
54
+ "\e[33m"
55
+ else
56
+ "\e[32m"
57
+ end
58
+ files = "Files: #{group.size}".ljust(11)
59
+ current = "#{group.covered_percent.round(2)}%".ljust(7)
60
+ required = "#{required_coverage[name]}%".ljust(8)
61
+ output << "#{color}#{name.ljust(16)} #{files} #{current} / #{required} (#{ideal_coverage[name]}%)\e[0m\n"
62
+ end
63
+ output += "\n"
64
+ puts output
65
+ if overall_failed
66
+ exit(SimpleCov::ExitCodes::MINIMUM_COVERAGE)
67
+ end
68
+ end
@@ -1,26 +1,32 @@
1
1
  class JefferiesTube::Console
2
- def self.prompt
2
+ def self.prompt_base
3
3
  rails_env = JefferiesTube.configuration.environment
4
4
  if rails_env
5
5
  color = "\e[0m" #Default to white text on no background
6
6
  current_app = JefferiesTube.configuration.prompt_name
7
7
 
8
- # shorten some common long environment names
9
8
  if rails_env == "development"
10
9
  elsif rails_env == "dev"
11
- rails_env = "dev"
12
10
  color = "\e[0;37m\e[1;44m" #White on blue
13
11
  elsif ["test", "qa", "staging"].include? rails_env
14
12
  color = "\e[0;37m\e[1;43m" #White on yellow
15
13
  elsif rails_env == "production"
16
- rails_env = "prod"
17
14
  color = "\e[0;37m\e[1;41m" #White on red
18
15
  end
19
16
 
20
17
  base = "#{color}#{current_app}(#{rails_env})\e[0m"
21
- return "#{base}> "
18
+ return "#{base}"
22
19
  else
23
- return "#{current_app}> "
20
+ return "#{current_app}"
24
21
  end
25
22
  end
23
+
24
+ def self.pry_prompts
25
+ [
26
+ # wait_proc
27
+ proc { prompt_base + " > " },
28
+ # incomplete_proc
29
+ proc { prompt_base + "*> "}
30
+ ]
31
+ end
26
32
  end
@@ -0,0 +1,25 @@
1
+ module JefferiesTube::Coverage
2
+ def self.default_converage
3
+ {
4
+ 'Controllers' => 10,
5
+ 'API Controllers' => 100,
6
+ 'Models' => 100,
7
+ 'Services' => 100,
8
+ 'Helpers' => 10,
9
+ 'Policies' => 100,
10
+ 'Jobs' => 100,
11
+ 'Mailers' => 0,
12
+ 'Libraries' => 0,
13
+ 'Plugins' => 0,
14
+ 'Ungrouped' => 10
15
+ }
16
+ end
17
+
18
+ def self.required_coverage=(hash)
19
+ @required_coverage = hash
20
+ end
21
+
22
+ def self.required_coverage
23
+ self.default_converage.merge(@required_coverage || {})
24
+ end
25
+ end
@@ -1,11 +1,15 @@
1
- prompt = JefferiesTube::Console.prompt
1
+ prompt = JefferiesTube::Console.prompt_base
2
2
 
3
- IRB.conf[:PROMPT][:RAILS_ENV] = {
4
- :PROMPT_I => prompt,
5
- :PROMPT_N => prompt,
6
- :PROMPT_S => nil,
7
- :PROMPT_C => prompt.sub('> ', '>* '),
8
- :RETURN => "=> %s\n"
3
+ IRB.conf[:PROMPT][:JEFFERIES_TUBE] = {
4
+ :PROMPT_I => "#{prompt} > ",
5
+ :PROMPT_N => "#{prompt}%l> ",
6
+ :PROMPT_S => "#{prompt}%l> ",
7
+ :PROMPT_C => "#{prompt}*> ",
8
+ :RETURN => " => %s\n"
9
9
  }
10
10
 
11
- IRB.conf[:PROMPT_MODE] = :RAILS_ENV
11
+ if ENV["JEFFERIES_TUBE_IRB"]
12
+ IRB.conf[:USE_MULTILINE] = false
13
+ IRB.conf[:USE_AUTOCOMPLETE] = false
14
+ IRB.conf[:PROMPT_MODE] = :JEFFERIES_TUBE
15
+ end
@@ -1,5 +1,6 @@
1
1
  require 'jefferies_tube'
2
2
  require 'jefferies_tube/console'
3
+ require 'jefferies_tube/coverage'
3
4
  require 'rails'
4
5
 
5
6
  module JefferiesTube
@@ -12,8 +13,9 @@ module JefferiesTube
12
13
 
13
14
  ARGV.push "-r", File.join(File.dirname(__FILE__),"custom_prompts.irbrc.rb")
14
15
 
16
+ require 'pry'
15
17
  if defined? Pry
16
- Pry.prompt = Pry::Prompt.new(:jefferies_tube, '', Array.new(2) { proc { JefferiesTube::Console.prompt } })
18
+ Pry.prompt = Pry::Prompt.new(:jefferies_tube, 'Jefferies Tube custom prompt', JefferiesTube::Console.pry_prompts)
17
19
  end
18
20
  end
19
21
 
@@ -66,5 +68,29 @@ module JefferiesTube
66
68
  end
67
69
  end
68
70
  end
71
+
72
+ initializer "create default rubocop config if missing" do |config|
73
+ default_rubocop = File.join(File.dirname(__FILE__), "config", "rubocop_default.yml")
74
+ rubocop_path = ::Rails.root.join ".rubocop.yml"
75
+ if !File.file?(rubocop_path)
76
+ FileUtils::cp(default_rubocop, rubocop_path)
77
+ end
78
+ end
79
+
80
+ initializer 'load simplecov for tests' do |config|
81
+ if ::Rails.env.test?
82
+ simplecov_config = 'config/simplecov.rb'
83
+ require_relative simplecov_config
84
+ end
85
+ end
86
+
87
+ rake_tasks do
88
+ Rake.application['default'].clear
89
+ task default: :spec
90
+ require 'rubocop/rake_task'
91
+
92
+ RuboCop::RakeTask.new(:rubocop)
93
+ task default: :rubocop
94
+ end
69
95
  end
70
96
  end
@@ -1,7 +1,7 @@
1
1
  require 'open-uri'
2
2
 
3
3
  module JefferiesTube
4
- VERSION = "1.5.2"
4
+ VERSION = "1.6.0"
5
5
 
6
6
  def self.latest_rubygems_version
7
7
  JSON.parse(URI.parse("https://rubygems.org/api/v1/versions/jefferies_tube/latest.json").read)["version"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jefferies_tube
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Samson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2022-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.13'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.26'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.26'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: Useful tools for Rails.
112
140
  email:
113
141
  - brian@tenforwardconsulting.com
@@ -132,6 +160,7 @@ files:
132
160
  - app/views/errors/404.json.jbuilder
133
161
  - app/views/errors/404.xml
134
162
  - app/views/errors/500.haml
163
+ - default.yml
135
164
  - jefferies_tube.gemspec
136
165
  - lib/jefferies_tube.rb
137
166
  - lib/jefferies_tube/access_token.rb
@@ -143,7 +172,10 @@ files:
143
172
  - lib/jefferies_tube/capistrano/rails.rb
144
173
  - lib/jefferies_tube/capistrano/s3_assets.rb
145
174
  - lib/jefferies_tube/capistrano/ssh.rb
175
+ - lib/jefferies_tube/config/rubocop_default.yml
176
+ - lib/jefferies_tube/config/simplecov.rb
146
177
  - lib/jefferies_tube/console.rb
178
+ - lib/jefferies_tube/coverage.rb
147
179
  - lib/jefferies_tube/custom_prompts.irbrc.rb
148
180
  - lib/jefferies_tube/database_backup.rb
149
181
  - lib/jefferies_tube/database_backup_adapter.rb
@@ -176,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
208
  - !ruby/object:Gem::Version
177
209
  version: '0'
178
210
  requirements: []
179
- rubygems_version: 3.3.3
211
+ rubygems_version: 3.3.11
180
212
  signing_key:
181
213
  specification_version: 4
182
214
  summary: Ten Forward Consulting useful tools.