see_double 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2083377ae0a8192afea291f8ec5a6f22f2c9eea9e12d79d406dbf690e3e0bdc9
4
+ data.tar.gz: f3ea147cdb7e314b66b4988df7ff014cc97f62278059316e4321a163e9286444
5
+ SHA512:
6
+ metadata.gz: 1bbdd092c281b816474f3cbaccba7346e4839564168cee89c1765a9a7b985173246b01147887027c446beb72fbc5ca6e2875d94255dd60f080a07929eca27824
7
+ data.tar.gz: e993e339946d4f400e63e3981ff5b9a6dcabe88c7f7242a25b4def22299ccef9dbb913ef974698daa8223af83a7f01087877270b4fb77b0b0a5c45fc8fa493da
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Clement Morisset
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # SeeDouble
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'see_double'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install see_double
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SeeDouble'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
data/bin/see_double ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby -wU
2
+ require 'see_double'
3
+
4
+ CheckDuplication.recupere_data_from_spec(ARGV[0])
@@ -0,0 +1,91 @@
1
+ require 'rails'
2
+ require_relative 'check_expect'
3
+ require 'colorize'
4
+
5
+ class CheckDuplication
6
+ class << self
7
+ def recupere_data_from_spec(arg)
8
+ datas = GetDataFromSpec.resultat_trie(arg)
9
+ trie_les_expects_et_les_noms_de_fichiers(datas)
10
+ identifie_duplication_au_sein_d_un_mm_file(datas, arg)
11
+ end
12
+
13
+ def trie_les_expects_et_les_noms_de_fichiers(datas)
14
+ @array_filename = []
15
+ datas.each do |a|
16
+ @array_filename << a.first
17
+ a.shift
18
+ end
19
+ end
20
+
21
+ def identifie_duplication_au_sein_d_un_mm_file(datas, arg)
22
+ duplication_final = []
23
+ datas.each do |data|
24
+ duplication = []
25
+ data.each{ |expect| duplication << expect }
26
+ duplication_final << duplication.flatten
27
+ end
28
+ formate_les_resultats_par_fichier(duplication_final, arg)
29
+ end
30
+
31
+ def formate_les_resultats_par_fichier(duplication_final, arg)
32
+ array_reconstitue = @array_filename.zip(duplication_final)
33
+ return if arg.nil?
34
+ affiche_les_resultats_par_fichier(array_reconstitue, arg)
35
+ affiche_les_resultats_pour_ensemble_des_specs(array_reconstitue, arg)
36
+ end
37
+
38
+ private
39
+
40
+ def affiche_les_resultats_par_fichier(arr_trie, arg)
41
+ display_result = []
42
+ formate_le_nbre_d_occurence(display_result,arr_trie)
43
+ affiche_les_resultats_dans_le_teminal(display_result, arg)
44
+ end
45
+
46
+ def formate_le_nbre_d_occurence(display_result,arr_trie)
47
+ arr_trie.each do |a|
48
+ hash_count = a.last.inject(Hash.new(0)) {|h,i| h[i] += 1; h }
49
+ hash_count.to_a.map { |expect_name,count| display_result << [a.first, expect_name.delete('()'), count] }
50
+ print ".".colorize(color: COLORS.sample)
51
+ sleep(0.2)
52
+ end
53
+ puts "\n\n"
54
+ end
55
+
56
+ def affiche_les_resultats_dans_le_teminal(display_result, arg)
57
+ result_triee_par_file = display_result.sort_by(&:last).reverse
58
+ path = []
59
+ puts "----- Analyze of your #{arg} from each features specs -----"
60
+ result_triee_par_file.each do |a|
61
+ if !path.include?(a.first)
62
+ path.push(a.first)
63
+ puts "\n"
64
+ puts "#{a.first.green}:"
65
+ end
66
+ output = "you use #{a[2].to_s.light_red} times #{a[1].light_red} as #{arg}"
67
+ puts output unless a[1].blank?
68
+ end
69
+ end
70
+
71
+ def trie_les_resultats_pour_ensemble_des_specs(arr_trie)
72
+ global_array = arr_trie.flatten.flatten
73
+ global_hash = global_array.inject(Hash.new(0)) { |total, e| total[e] += 1 ;total}
74
+ global_hash.delete_if { |k, v| v <= 1 }
75
+ @global_array_trie = global_hash.sort_by(&:last).reverse
76
+ end
77
+
78
+ def affiche_les_resultats_pour_ensemble_des_specs(arr_trie, arg)
79
+ puts "\n\n"
80
+ puts "----- Analyze of your #{arg} from all yours specs -----"
81
+ puts "\n"
82
+ trie_les_resultats_pour_ensemble_des_specs(arr_trie)
83
+ @global_array_trie.map do |expect_name,count|
84
+ puts "You use #{count.to_s.light_red} times the #{expect_name.light_red} as #{arg}"
85
+ end
86
+ puts "\n"
87
+ end
88
+ end
89
+ end
90
+
91
+ COLORS = [:light_black, :red, :light_red, :green, :light_green, :yellow, :light_yellow, :blue, :light_blue, :magenta, :light_magenta, :cyan, :light_cyan]
@@ -0,0 +1,104 @@
1
+ require 'rails'
2
+
3
+ class GetDataFromSpec
4
+ class << self
5
+
6
+ def resultat_trie mot_cle
7
+ datas = recupere_data mot_cle
8
+ contenu_trie = []
9
+ itere_sur_chaque_ligne_des_expects(datas, contenu_trie, mot_cle)
10
+ clean_result(contenu_trie)
11
+ end
12
+
13
+ private
14
+
15
+ def recupere_data mot_cle
16
+ specs_content = parcours_spec_et_recupere_content
17
+ if mot_cle == 'result'
18
+ expect = ['expect'].freeze #mot clé pour choper les expects
19
+ else
20
+ expect = [mot_cle].freeze
21
+ end
22
+ datas = []
23
+ parcours_recupere_data(specs_content, expect, datas)
24
+ datas
25
+ end
26
+
27
+ def parcours_spec_et_recupere_content
28
+ specs_content = []
29
+ Dir.glob(renvoie_le_bon_chemin) do |spec_path|
30
+ spec_file_content = []
31
+ ajoute_path_dans_array(spec_file_content, spec_path)
32
+ File.foreach(spec_path) do |line|
33
+ spec_file_content << line.strip
34
+ end
35
+ specs_content << spec_file_content
36
+ end
37
+ specs_content
38
+ end
39
+
40
+ def renvoie_le_bon_chemin
41
+ Dir.exist?("./rails_app/dummy") ? "./rails_app/dummy/spec/**/*.rb" : "./spec/features/**/*.rb"
42
+ end
43
+
44
+ def parcours_recupere_data(specs_content, mot_cle, data_currated )
45
+ specs_content.each do |lines|
46
+ expect_pour_un_fichier = []
47
+ lines.each do |line|
48
+ ajoute_path_dans_array(expect_pour_un_fichier, lines.first)
49
+ recupere_contenu_des_expects(line, expect_pour_un_fichier, mot_cle)
50
+ end
51
+ data_currated.push(expect_pour_un_fichier)
52
+ end
53
+ end
54
+
55
+ def ajoute_path_dans_array(array, element)
56
+ array << element unless array.include? element
57
+ end
58
+
59
+ def recupere_contenu_des_expects(line, array, mot_cle)
60
+ line.split(/\W+/).each do |a|
61
+ return unless mot_cle.include?(a)
62
+ array.push(line)
63
+ end
64
+ end
65
+
66
+ def itere_sur_chaque_ligne_des_expects(array_initial, array_resultat, mot_cle)
67
+ array_initial.each do |line|
68
+ contenu = []
69
+ contenu << line.first
70
+ if mot_cle == 'result'
71
+ recupere_le_contenu_du_resultat_attendu(line, contenu)
72
+ else
73
+ recupere_contenu_entre_parenthese(line, contenu)
74
+ end
75
+ array_resultat << contenu
76
+ end
77
+ end
78
+
79
+ def recupere_contenu_entre_parenthese(line, array_initial)
80
+ line.each do |a|
81
+ recupere_contenu = []
82
+ recupere_contenu << a.scan(/\((.*?)\)/)
83
+ array_initial << recupere_contenu.first
84
+ array_initial.delete_if { |s| s.empty? }
85
+ end
86
+ end
87
+
88
+ def recupere_le_contenu_du_resultat_attendu(line, array_initial)
89
+ line.each do |a|
90
+ array_initial << a.scan(/^*have_content(.*)$/)
91
+ array_initial << a.scan(/^*eq(.*)$/)
92
+ array_initial.delete_if { |s| s.empty? }
93
+ end
94
+ end
95
+
96
+ def clean_result(array)
97
+ resultat_trie = array.map { |a| a.flatten }
98
+ resultat_trie.each do |a|
99
+ a.delete_if { |i| i == 'page'}
100
+ end
101
+ resultat_trie.delete_if { |a| a.length == 1 }
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,3 @@
1
+ module SeeDouble
2
+ VERSION = '1.0.0'
3
+ end
data/lib/see_double.rb ADDED
@@ -0,0 +1,8 @@
1
+ require_relative 'check_duplication'
2
+ require_relative 'check_expect'
3
+
4
+ module SeeDouble
5
+ def check_duplication_spec spec
6
+ CheckDuplication.recupere_data_from_spec(spec)
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :see_double do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: see_double
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Clement Morisset
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'ok: Description of SeeDouble.'
70
+ email:
71
+ - morissetcl87@gmail.com
72
+ executables:
73
+ - see_double
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - MIT-LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - bin/see_double
81
+ - lib/check_duplication.rb
82
+ - lib/check_expect.rb
83
+ - lib/see_double.rb
84
+ - lib/see_double/version.rb
85
+ - lib/tasks/see_double_tasks.rake
86
+ homepage:
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.7.6
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: 'ok: Summary of SeeDouble.'
110
+ test_files: []