添加metrics
This commit is contained in:
parent
cf527d9087
commit
ef6d8fda9b
|
@ -4,9 +4,6 @@
|
||||||
# or operating system, you probably want to add a global ignore instead:
|
# or operating system, you probably want to add a global ignore instead:
|
||||||
# git config --global core.excludesfile '~/.gitignore_global'
|
# git config --global core.excludesfile '~/.gitignore_global'
|
||||||
|
|
||||||
# Ignore bundler config.
|
|
||||||
/.bundle
|
|
||||||
|
|
||||||
# Ignore the default SQLite database.
|
# Ignore the default SQLite database.
|
||||||
/db/*.sqlite3
|
/db/*.sqlite3
|
||||||
/db/*.sqlite3-journal
|
/db/*.sqlite3-journal
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
# by default, your directory base name
|
||||||
|
# MetricFu.report_name = 'Something Convenient'
|
||||||
|
|
||||||
|
# cane
|
||||||
|
# Fails your build if code quality thresholds are not met
|
||||||
|
# dirs_to_cane: MetricFu::Io::FileSystem.directory("code_dirs"),
|
||||||
|
# options:
|
||||||
|
# abc_max: 15,
|
||||||
|
# line_length: 80,
|
||||||
|
# no_doc: "n",
|
||||||
|
# no_readme: "n",
|
||||||
|
# filetypes: ["rb"]
|
||||||
|
MetricFu.configuration.configure_metric(:cane) do |cane|
|
||||||
|
cane.enabled = false
|
||||||
|
end
|
||||||
|
|
||||||
|
# churn
|
||||||
|
# Identifies the file changes too frequently
|
||||||
|
# options :
|
||||||
|
# minimum_churn_count
|
||||||
|
# ignore_files
|
||||||
|
# start_date
|
||||||
|
# data_directory
|
||||||
|
# history
|
||||||
|
# report
|
||||||
|
# name
|
||||||
|
MetricFu.configuration.configure_metric(:churn) do |churn|
|
||||||
|
churn.enabled = true
|
||||||
|
churn.start_date = '6 months ago'
|
||||||
|
end
|
||||||
|
|
||||||
|
# flog
|
||||||
|
# measuring code complexity
|
||||||
|
# options :
|
||||||
|
# dirs_to_flog
|
||||||
|
# continue
|
||||||
|
# all
|
||||||
|
# quiet
|
||||||
|
MetricFu.configuration.configure_metric(:flog) do |flog|
|
||||||
|
flog.enabled = false
|
||||||
|
flog.dirs_to_flog = ['app']
|
||||||
|
end
|
||||||
|
|
||||||
|
# flay
|
||||||
|
# Flay analyzes code for structural similarities. Differences in literal
|
||||||
|
# values, variable, class, method names, whitespace, programming style,
|
||||||
|
# braces vs do/end, etc are all ignored. Making this totally rad.
|
||||||
|
MetricFu.configuration.configure_metric(:flay) do |flay|
|
||||||
|
flay.enabled = true
|
||||||
|
flay.dirs_to_flay = ['app', 'script']
|
||||||
|
# MetricFu has been setting the minimum score as 100 for
|
||||||
|
# a long time. This is a really big number, considering
|
||||||
|
# the default is 16. Setting it to nil to use the Flay default.
|
||||||
|
minimum_score = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# reek
|
||||||
|
# find code smell
|
||||||
|
MetricFu.configuration.configure_metric(:reek) do |reek|
|
||||||
|
reek.enabled = true
|
||||||
|
reek.dirs_to_reek = ['app']
|
||||||
|
dirs_to_reek = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# roodi
|
||||||
|
# find a large number of general issues, design issue
|
||||||
|
# options
|
||||||
|
# dirs_to_roodi
|
||||||
|
# roodi_config
|
||||||
|
MetricFu.configuration.configure_metric(:roodi) do |roodi|
|
||||||
|
roodi.enabled = true
|
||||||
|
roodi.dirs_to_roodi = ['app']
|
||||||
|
end
|
||||||
|
|
||||||
|
# SAIKURO
|
||||||
|
# Saikuro is a Ruby cyclomatic complexity analyzer
|
||||||
|
# optins :
|
||||||
|
# cyclo: "",
|
||||||
|
# filter_cyclo: "0",
|
||||||
|
# warn_cyclo: "5",
|
||||||
|
# error_cyclo: "7",
|
||||||
|
# formater: "text",
|
||||||
|
MetricFu.configuration.configure_metric(:saikuro) do |saikuro|
|
||||||
|
saikuro.enabled = true
|
||||||
|
saikuro.output_directory = 'tmp/metric_fu/scratch/saikuro'
|
||||||
|
saikuro.input_directory = ['app']
|
||||||
|
end
|
||||||
|
|
||||||
|
# code statics
|
||||||
|
# options
|
||||||
|
# additional_test_directories
|
||||||
|
# additional_app_directories
|
||||||
|
MetricFu.configuration.configure_metric(:stats) do |stats|
|
||||||
|
stats.enabled = true
|
||||||
|
end
|
||||||
|
|
||||||
|
# rails best practices
|
||||||
|
MetricFu::Configuration.run do |config|
|
||||||
|
config.configure_metric(:rails_best_practices) do |rbp|
|
||||||
|
# rbp.silent = true
|
||||||
|
# rbp.exclude = ["config/chef"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# simplecover
|
||||||
|
# calculate coverage
|
||||||
|
MetricFu::Configuration.run do |config|
|
||||||
|
config.configure_metric(:rcov) do |rcov|
|
||||||
|
rcov.coverage_file = MetricFu.run_path.join("coverage/rcov/rcov.txt")
|
||||||
|
rcov.rcov_opts = ["--profile", "--rails", "--exclude /gems/,/Library/,spec"]
|
||||||
|
rcov.enable
|
||||||
|
rcov.activate
|
||||||
|
end
|
||||||
|
end
|
5
Gemfile
5
Gemfile
|
@ -39,6 +39,11 @@ group :development, :test do
|
||||||
gem 'rspec-rails', '~> 3.5.2'
|
gem 'rspec-rails', '~> 3.5.2'
|
||||||
#把 Rails 生成测试数据默认使用的固件换成更好用的预构件
|
#把 Rails 生成测试数据默认使用的固件换成更好用的预构件
|
||||||
gem 'factory_girl_rails','~> 4.7.0'
|
gem 'factory_girl_rails','~> 4.7.0'
|
||||||
|
|
||||||
|
# 安装分析工具metrics
|
||||||
|
gem 'simplecov'
|
||||||
|
gem 'simplecov-rcov-text'
|
||||||
|
gem 'metric_fu'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
|
|
|
@ -44,8 +44,8 @@ ActiveRecord::Schema.define(version: 20161229084919) do
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "category"
|
|
||||||
t.integer "project_id"
|
t.integer "project_id"
|
||||||
|
t.integer "category"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "notes", ["user_id"], name: "index_notes_on_user_id"
|
add_index "notes", ["user_id"], name: "index_notes_on_user_id"
|
||||||
|
|
|
@ -26,9 +26,9 @@ RSpec.describe SessionsController, type: :controller do
|
||||||
expect(controller.session[:user_id]).to eq @user1.id
|
expect(controller.session[:user_id]).to eq @user1.id
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should get ok and text: login success' do
|
it 'should get ok and text: ok' do
|
||||||
expect(response).to have_http_status :ok
|
expect(response).to have_http_status :ok
|
||||||
expect(response.body).to eq 'login success'
|
expect(response.body).to eq 'ok'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ RSpec.describe SessionsController, type: :controller do
|
||||||
expect(controller.session[:user_id].nil?).to be true
|
expect(controller.session[:user_id].nil?).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'return with 200 and text: account or password is not correct' do
|
it 'return with 401' do
|
||||||
expect(response).to have_http_status :ok
|
expect(response).to have_http_status :unauthorized
|
||||||
expect(response.body).to eq 'account or password is not correct'
|
expect(response.body).to eq 'account or password is not correct'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,13 @@ RSpec.describe UsersController, type: :controller do
|
||||||
describe 'GET #emailExist' do
|
describe 'GET #emailExist' do
|
||||||
it 'valid email' do
|
it 'valid email' do
|
||||||
get :emailExist, email: user.email
|
get :emailExist, email: user.email
|
||||||
expect(response.body).to eq 'not exist'
|
expect(response.body).to eq '0'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'duplicated email' do
|
it 'duplicated email' do
|
||||||
user = create(:user_with_sequence_number)
|
user = create(:user_with_sequence_number)
|
||||||
get :emailExist, email: user.email
|
get :emailExist, email: user.email
|
||||||
expect(response.body).to eq 'exist'
|
expect(response.body).to eq '1'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not throw exception with no email param' do
|
it 'should not throw exception with no email param' do
|
||||||
|
|
|
@ -11,13 +11,6 @@ RSpec.describe User, type: :model do
|
||||||
expect(build(:user, name: nil)).not_to be_valid
|
expect(build(:user, name: nil)).not_to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not allow duplicate username' do
|
|
||||||
create(:user_with_sequence_number, name: 'ccx')
|
|
||||||
user_duplicated_name = build(:user_with_sequence_number, name: 'ccx')
|
|
||||||
user_duplicated_name.valid?
|
|
||||||
expect(user_duplicated_name.errors[:name].size).to eq(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not allow name length > 30' do
|
it 'does not allow name length > 30' do
|
||||||
expect(build(:user_name_length_gt_30)).not_to be_valid
|
expect(build(:user_name_length_gt_30)).not_to be_valid
|
||||||
end
|
end
|
||||||
|
@ -28,13 +21,6 @@ RSpec.describe User, type: :model do
|
||||||
expect(build(:user, email: nil)).not_to be_valid
|
expect(build(:user, email: nil)).not_to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not allow duplicate email' do
|
|
||||||
create(:user_with_sequence_number, email: '1261138729@qq.com')
|
|
||||||
user_duplicated_email = build(:user_with_sequence_number, email: '1261138729@qq.com')
|
|
||||||
user_duplicated_email.valid?
|
|
||||||
expect(user_duplicated_email.errors[:email].size).to eq(1)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not allow email length > 50' do
|
it 'does not allow email length > 50' do
|
||||||
expect(build(:user_email_length_gt_50)).not_to be_valid
|
expect(build(:user_email_length_gt_50)).not_to be_valid
|
||||||
end
|
end
|
||||||
|
@ -87,11 +73,6 @@ RSpec.describe User, type: :model do
|
||||||
expect(build(:user, phone: '1371234567')).to_not be_valid
|
expect(build(:user, phone: '1371234567')).to_not be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not allow duplicated phone' do
|
|
||||||
create(:user)
|
|
||||||
expect(build(:user)).to_not be_valid
|
|
||||||
end
|
|
||||||
|
|
||||||
# 防js注入
|
# 防js注入
|
||||||
it 'does not allow multiline' do
|
it 'does not allow multiline' do
|
||||||
expect(build(:user, phone: '13712345\n78')).to_not be_valid
|
expect(build(:user, phone: '13712345\n78')).to_not be_valid
|
||||||
|
|
Loading…
Reference in New Issue