fix-command 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c6c5c5575c6dfec515ac9016b879d47f9dd4abc
4
- data.tar.gz: b0027bad8769a6aa488b79004ce6bf09c074221f
3
+ metadata.gz: 1f3073b26715f2c4f04fe8529c2f48057f9b1778
4
+ data.tar.gz: 2639e35f4e61cafe6ff9bfa8ddf98accd04c6af8
5
5
  SHA512:
6
- metadata.gz: 4c62ca9e24b1668f1a3dd2b89e2e4a924db33dabd70be920b21bd184756d9b52a0bb8618c95df95da316882b730438659a8d9a0b59186ea2411d50c1c181e800
7
- data.tar.gz: 3ba8e1d943b52d9f28c9d2e712343a970f9c7efa201f2b724354daa62b46c97c6d8e177eb5a7a8bad1ab5a732c1d59c13a43ebb54a3834648475f2d03c02bdbb
6
+ metadata.gz: 2f3a05bad3471355cc7e75dd904fe0982982d74a4f000ae50b85aaec39073ec1f49cfd1706c659cfbdce23e3a98241e6f2da2c17f47e36b95dd31c6c6d5f56a2
7
+ data.tar.gz: 7c4dcb3677a5a93a4f63c80affa06813a568b36910da397bdb483b152e6514efef6e641b2886a40d06d17d7c477a18614166622c3fe54b5a47f684e5c769ca9d
checksums.yaml.gz.sig CHANGED
Binary file
data/.rubocop_todo.yml CHANGED
@@ -1,16 +1,32 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2015-10-31 15:20:34 +0100 using RuboCop version 0.34.2.
3
+ # on 2016-01-25 00:29:24 +0100 using RuboCop version 0.36.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
9
+ # Offense count: 4
10
10
  Metrics/AbcSize:
11
- Max: 23
11
+ Max: 32
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments.
15
+ Metrics/ClassLength:
16
+ Max: 127
17
+
18
+ # Offense count: 12
19
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
20
+ # URISchemes: http, https
21
+ Metrics/LineLength:
22
+ Max: 104
12
23
 
13
24
  # Offense count: 3
14
25
  # Configuration parameters: CountComments.
15
26
  Metrics/MethodLength:
16
- Max: 30
27
+ Max: 49
28
+
29
+ # Offense count: 1
30
+ Style/NestedParenthesizedCalls:
31
+ Exclude:
32
+ - 'test/command/test_version.rb'
data/README.md CHANGED
@@ -46,45 +46,47 @@ And then execute:
46
46
 
47
47
  First, let's see the API:
48
48
 
49
- $ bundle exec fix --help
50
- Usage: fix <files or directories> [options]
49
+ $ fix --help
50
+ Usage: fix <directory> [options]
51
51
 
52
52
  Specific options:
53
- --debug Enable ruby debug
54
- --warnings Enable ruby warnings
55
- --random=[SEED] Predictable randomization
56
- --prefix=[PREFIX] Prefix of the spec files
57
- --suffix=[SUFFIX] Suffix of the spec files
53
+ --[no-]debug Enable ruby debug
54
+ --[no-]warnings Enable ruby warnings
55
+ --[no-]diff Regression test selection
56
+ --random [SEED] Predictable randomization
57
+ --prefix [PREFIX] Prefix of the spec files
58
+ --suffix [SUFFIX] Suffix of the spec files
58
59
 
59
60
  Common options:
60
- --help Show this message
61
- --version Show the version
61
+ -h, --help Show this message
62
+ -v, --version Show the version
62
63
 
63
64
  And second, let's run a test:
64
65
 
65
- $ bundle exec fix duck_fix.rb --warnings
66
- > fix /Users/bob/code/duck_fix.rb --warnings
66
+ $ fix ./app/ --prefix test_ --suffix --diff
67
+ > fix /Users/bob/app/duck_fix.rb --diff --random 198142038504094374390860708229193114294 --prefix "test_" --suffix ""
67
68
 
68
- /Users/bob/code/duck_fix.rb ..I
69
+ /Users/bob/app/duck_fix.rb ..
69
70
 
70
- 1. Info: undefined method `sings' for #<Duck:0x007fdbeb05c1d8> (NoMethodError).
71
-
72
- Ran 3 tests in 0.000612 seconds
73
- 100% compliant - 1 infos, 0 failures, 0 errors
71
+ Ran 2 tests in 0.000382 seconds
72
+ 100% compliant - 0 infos, 0 failures, 0 errors
74
73
 
75
74
  ### Store Command Line Options
76
75
 
77
- You can store command line options in a `.fix` file in the project's root directory, and the fix command will read them as though you typed them on the command line.
76
+ You can store command-line configuration options in a `.fix` file in two different locations:
77
+
78
+ * Local: "`./.fix`" (i.e. in the project's root directory)
79
+ * Global: "`~/.fix`" (i.e. in the user's home directory)
80
+
81
+ __Fix::Command__ will thus read them as though you typed them on the command-line.
82
+
83
+ Options declared in the local file override those in the global file, while those declared in command-line will override any ".fix" file.
78
84
 
79
85
  ## Security
80
86
 
81
- As a basic form of security __Fix::Command__ provides a set of SHA512 checksums for
82
- every Gem release. These checksums can be found in the `checksum/` directory.
83
- Although these checksums do not prevent malicious users from tampering with a
84
- built Gem they can be used for basic integrity verification purposes.
87
+ As a basic form of security __Fix::Command__ provides a set of SHA512 checksums for every Gem release. These checksums can be found in the `checksum/` directory. Although these checksums do not prevent malicious users from tampering with a built Gem they can be used for basic integrity verification purposes.
85
88
 
86
- The checksum of a file can be checked using the `sha512sum` command. For
87
- example:
89
+ The checksum of a file can be checked using the `sha512sum` command. For example:
88
90
 
89
91
  $ sha512sum pkg/fix-command-0.1.0.gem
90
92
  26198b7812a5ac118a5f2a1b63927871b3378efb071b37abb7e1ba87c1aac9f3a6b45eeae87d9dc647b194c15171b13f15e46503a9a1440b1233faf924381ff5 pkg/fix-command-0.1.0.gem
data/VERSION.semver CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -0,0 +1 @@
1
+ 4abcd3dc61a08e4d20b80ab1605e607b4c87e24c96cd82447a00db1a65d590b7f68750a1a37d378de204891a79c36d0238b15676ad53288a458244b0e1c50b8b
data/fix-command.gemspec CHANGED
@@ -16,11 +16,11 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.add_dependency 'fix', '~> 0.17.0'
18
18
 
19
- spec.add_development_dependency 'bundler', '~> 1.10'
20
- spec.add_development_dependency 'rake', '~> 10.4'
19
+ spec.add_development_dependency 'bundler', '~> 1.11'
20
+ spec.add_development_dependency 'rake', '~> 10.5'
21
21
  spec.add_development_dependency 'yard', '~> 0.8'
22
- spec.add_development_dependency 'simplecov', '~> 0.10'
23
- spec.add_development_dependency 'rubocop', '~> 0.35'
22
+ spec.add_development_dependency 'simplecov', '~> 0.11'
23
+ spec.add_development_dependency 'rubocop', '~> 0.36'
24
24
  spec.add_development_dependency 'spectus', '~> 3.0'
25
25
 
26
26
  spec.cert_chain = ['certs/gem-fixrb-public_cert.pem']
data/lib/fix/command.rb CHANGED
@@ -6,26 +6,16 @@ require 'set'
6
6
  #
7
7
  # @api public
8
8
  #
9
- # @example Let's test a duck's spec!
10
- # Fix::Command.run('duck_fix.rb', '--warnings')
9
+ # @example Let's test a duck!
10
+ # Fix::Command.run('./duck/', '--warnings')
11
11
  #
12
12
  module Fix
13
- # Fix reads command line configuration options from files in two different
14
- # locations:
15
- #
16
- # Local: "./.fix" (i.e. in the project's root directory)
17
- # Global: "~/.fix" (i.e. in the user's home directory)
18
- #
19
- # Options declared in the local file override those in the global file, while
20
- # those declared in command-line will override any ".fix" file.
21
- COMMAND_LINE_OPTIONS_FILE = '.fix'
22
-
23
13
  # Open the command class.
24
14
  #
25
15
  # @api public
26
16
  #
27
- # @example Let's test a duck's spec!
28
- # Command.run('duck_fix.rb', '--warnings')
17
+ # @example Let's test a duck!
18
+ # Command.run('./duck/', '--warnings')
29
19
  #
30
20
  class Command
31
21
  # Handle the parameters passed to fix command from the console.
@@ -33,29 +23,31 @@ module Fix
33
23
  # @api public
34
24
  #
35
25
  # @example Let's test a duck's spec!
36
- # run('duck_fix.rb', '--warnings')
26
+ # run('./duck/', '--warnings')
37
27
  #
38
28
  # @param args [Array] A list of files and options.
39
29
  #
40
30
  # @raise [SystemExit] The result of the tests.
41
31
  def self.run(*args)
42
- config = process_args(args)
32
+ config = process_args(true, args)
33
+
34
+ if args.size > 1
35
+ fail ArgumentError, "wrong number of directories (given #{args.size})"
36
+ end
43
37
 
44
38
  file_paths = fetch_file_paths(
39
+ config.fetch(:diff),
45
40
  config.fetch(:prefix),
46
- config.fetch(:suffix), *args
47
- ).to_a.shuffle(random: Random.new(config.fetch(:random)))
41
+ config.fetch(:suffix),
42
+ (args.first || '.')
43
+ ).to_a.sort.shuffle(random: Random.new(config.fetch(:random)))
48
44
 
49
- str = "\e[37m"
50
- str += '> fix '
51
- str += file_paths.join(' ')
52
- str += ' --debug' if $DEBUG
53
- str += ' --warnings' if $VERBOSE
54
- str += ' --random' if config.fetch(:random)
55
- str += ' --prefix' if config.fetch(:prefix)
56
- str += ' --suffix' if config.fetch(:suffix)
45
+ puts report(config, *file_paths)
57
46
 
58
- puts "#{str} \e[22m"
47
+ if file_paths.empty?
48
+ puts 'Specs not found.'
49
+ exit
50
+ end
59
51
 
60
52
  status = true
61
53
 
@@ -73,50 +65,73 @@ module Fix
73
65
  end
74
66
 
75
67
  # @private
76
- def self.process_args(args)
68
+ #
69
+ # @return [String] Report the command-line.
70
+ def self.report(config, *file_paths)
71
+ str = '> fix ' + file_paths.join(' ')
72
+ str += ' --debug' if $DEBUG
73
+ str += ' --warnings' if $VERBOSE
74
+ str += ' --diff' if config.fetch(:diff)
75
+ str += " --random #{config.fetch(:random)}"
76
+ str += " --prefix #{config.fetch(:prefix).inspect}"
77
+ str += " --suffix #{config.fetch(:suffix).inspect}"
78
+
79
+ ["\e[37m", str, "\e[0m"].join
80
+ end
81
+
82
+ # @private
83
+ #
84
+ # @param load_file [Boolean] Preload configuration options from files.
85
+ # @param args [Array] List of parameters.
86
+ def self.process_args(load_file, args)
77
87
  options = {
78
- debug: false,
79
- warnings: false,
80
- random: Random.new_seed,
81
- prefix: '',
82
- suffix: '_fix'
88
+ debug: false,
89
+ warnings: false,
90
+ diff: false,
91
+ random: Random.new_seed,
92
+ prefix: '',
93
+ suffix: '_fix'
83
94
  }
84
95
 
85
96
  opt_parser = OptionParser.new do |opts|
86
- opts.banner = 'Usage: fix <files or directories> [options]'
97
+ opts.banner = 'Usage: fix <directory> [options]'
87
98
 
88
99
  opts.separator ''
89
100
  opts.separator 'Specific options:'
90
101
 
91
- opts.on('--debug', 'Enable ruby debug') do
92
- options[:debug] = $DEBUG = true
102
+ opts.on('--[no-]debug', 'Enable ruby debug') do |b|
103
+ options[:debug] = $DEBUG = b
93
104
  end
94
105
 
95
- opts.on('--warnings', 'Enable ruby warnings') do
96
- options[:warnings] = $VERBOSE = true
106
+ opts.on('--[no-]warnings', 'Enable ruby warnings') do |b|
107
+ options[:warnings] = $VERBOSE = b
97
108
  end
98
109
 
99
- opts.on('--random=[SEED]', Integer, 'Predictable randomization') do |i|
100
- options[:random] = i
110
+ opts.on('--[no-]diff', 'Regression test selection') do |b|
111
+ options[:diff] = b
101
112
  end
102
113
 
103
- opts.on('--prefix=[PREFIX]', String, 'Prefix of the spec files') do |s|
104
- options[:prefix] = s
114
+ opts.on('--random [SEED]', Integer, 'Predictable randomization') do |i|
115
+ options[:random] = Integer(i)
105
116
  end
106
117
 
107
- opts.on('--suffix=[SUFFIX]', String, 'Suffix of the spec files') do |s|
108
- options[:suffix] = s
118
+ opts.on('--prefix [PREFIX]', String, 'Prefix of the spec files') do |s|
119
+ options[:prefix] = s.to_s
120
+ end
121
+
122
+ opts.on('--suffix [SUFFIX]', String, 'Suffix of the spec files') do |s|
123
+ options[:suffix] = s.to_s
109
124
  end
110
125
 
111
126
  opts.separator ''
112
127
  opts.separator 'Common options:'
113
128
 
114
- opts.on_tail '--help', 'Show this message' do
129
+ opts.on_tail '-h', '--help', 'Show this message' do
115
130
  puts opts
116
131
  exit
117
132
  end
118
133
 
119
- opts.on_tail '--version', 'Show the version' do
134
+ opts.on_tail '-v', '--version', 'Show the version' do
120
135
  puts File.read(File.join(File.expand_path(File.dirname(__FILE__)),
121
136
  '..',
122
137
  '..',
@@ -126,9 +141,8 @@ module Fix
126
141
  end
127
142
  end
128
143
 
129
- %w(~ .).each do |c|
130
- config_path = File.join(File.expand_path(c), COMMAND_LINE_OPTIONS_FILE)
131
- opt_parser.load(config_path)
144
+ if load_file
145
+ config_paths.each { |config_path| opt_parser.load(config_path) }
132
146
  end
133
147
 
134
148
  opt_parser.parse!(args)
@@ -136,30 +150,63 @@ module Fix
136
150
  options
137
151
  end
138
152
 
153
+ # @return [String] The configuration file.
154
+ def self.config_file
155
+ '.fix'
156
+ end
157
+
158
+ # @return [Array] Different locations of command-line configuration options.
159
+ def self.config_paths
160
+ %w(~ .).map { |char| File.join(File.expand_path(char), config_file) }
161
+ end
162
+
139
163
  # @private
140
164
  #
141
165
  # @return [Set] A list of absolute paths.
142
- def self.fetch_file_paths(file_prefix, file_suffix, *args)
143
- absolute_paths = Set.new
144
-
145
- args << '.' if args.empty?
146
- args.each do |s|
147
- s = File.absolute_path(s) unless s.start_with?(File::SEPARATOR)
148
-
149
- if File.directory?(s)
150
- spec_files = File.join(s, '**', "#{file_prefix}*#{file_suffix}.rb")
151
- Dir.glob(spec_files).each { |spec_f| absolute_paths.add(spec_f) }
152
- else
153
- absolute_paths.add(s)
154
- end
166
+ def self.fetch_file_paths(diff, prefix, suffix, path)
167
+ unless File.directory?(path)
168
+ warn 'Sorry, invalid directory.'
169
+ exit false
155
170
  end
156
171
 
157
- if absolute_paths.empty?
158
- warn 'Sorry, files or directories not found.'
159
- exit false
172
+ path = File.absolute_path(path) unless path.start_with?(File::SEPARATOR)
173
+
174
+ spec_paths = Dir.glob(File.join(path, '**', "#{prefix}*#{suffix}.rb")).to_set
175
+ return spec_paths unless diff
176
+
177
+ Dir.chdir(path) do
178
+ modified_paths = git_diff_paths
179
+
180
+ # select only modified specs
181
+ modified_spec_paths = spec_paths & modified_paths
182
+
183
+ # select only unmodified specs
184
+ unmodified_spec_paths = spec_paths - modified_spec_paths
185
+
186
+ # select only modified code
187
+ modified_code_paths = modified_paths - spec_paths
188
+ modified_code_filenames = modified_code_paths.map do |p|
189
+ p.split(File::SEPARATOR).last.gsub(/\.rb\z/, '')
190
+ end.to_set
191
+
192
+ # select only specs of the modified code
193
+ additional_spec_paths = unmodified_spec_paths.select do |unmodified_spec_path|
194
+ unmodified_spec_filename = unmodified_spec_path.split(File::SEPARATOR).last.gsub(/\.rb\z/, '')
195
+ modified_code_filenames.any? do |modified_code_filename|
196
+ unmodified_spec_filename.include?(modified_code_filename)
197
+ end
198
+ end
199
+
200
+ modified_spec_paths + additional_spec_paths
160
201
  end
202
+ end
161
203
 
162
- absolute_paths
204
+ # @return [Set] The list of modified files.
205
+ def self.git_diff_paths
206
+ `git status --porcelain`
207
+ .split("\n")
208
+ .map { |p| File.absolute_path(p.split.last) }
209
+ .to_set
163
210
  end
164
211
  end
165
212
  end
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- $���M����Ą?��<�e@M�{x[��vQ�{9\���'N��# }}v��T�oi<a������(}��k�v��b�pqMS"��i���u���nv:���t'O@�����vVA�+�C�����ЦxR��(�O��a��Y��5�����������;4�M��9x������ǜn=؏������E)h��㕃3yI�GA���� J��<o=%b5�eq ެ�[���wW?j�R��'�C@^k
1
+ &N��zЁa�<I ��LV{����[`I���<��ɞ�g;rX�;�*ŷ���ƪ�|��/,__3C��U��E��țS[��{�On�is�|p��pϣ�ˤaj�k����y��&;ց��_��~8M 1U����x+�&��<3U��e�����l��m`bª����KM ��=��H.z�9|��|���!Uș}yjVL�I.}��8����l?�pWi}r�#;j}��3����0��2"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fix-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Wack
@@ -30,7 +30,7 @@ cert_chain:
30
30
  dzJvWzQ1+dJU6WQv75E9ddSkaQrK3nhdgQVu+/wgvGSrsMvOGNz+LXaSDxQqZuwX
31
31
  0KNQFuIukfrdk8URwRnHoAnvx4U93iUw
32
32
  -----END CERTIFICATE-----
33
- date: 2015-12-30 00:00:00.000000000 Z
33
+ date: 2016-01-24 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: fix
@@ -52,28 +52,28 @@ dependencies:
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1.10'
55
+ version: '1.11'
56
56
  type: :development
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '1.10'
62
+ version: '1.11'
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: rake
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '10.4'
69
+ version: '10.5'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '10.4'
76
+ version: '10.5'
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: yard
79
79
  requirement: !ruby/object:Gem::Requirement
@@ -94,28 +94,28 @@ dependencies:
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '0.10'
97
+ version: '0.11'
98
98
  type: :development
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0.10'
104
+ version: '0.11'
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: rubocop
107
107
  requirement: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0.35'
111
+ version: '0.36'
112
112
  type: :development
113
113
  prerelease: false
114
114
  version_requirements: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0.35'
118
+ version: '0.36'
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: spectus
121
121
  requirement: !ruby/object:Gem::Requirement
@@ -158,6 +158,7 @@ files:
158
158
  - checksum/fix-command-0.1.3.gem.sha512
159
159
  - checksum/fix-command-0.2.0.gem.sha512
160
160
  - checksum/fix-command-0.3.0.gem.sha512
161
+ - checksum/fix-command-0.4.0.gem.sha512
161
162
  - fix-command.gemspec
162
163
  - lib/fix/command.rb
163
164
  - pkg_checksum
metadata.gz.sig CHANGED
@@ -1 +1,3 @@
1
- DY� T�z�����Ӆ�5@��"��75�pqMg]��J����A���&V��_gZ������ZuT&z���PP�ʋ
1
+ �+0n��fdDZ����M��q���J܌\7��A WK������c��.�lqaG����1�kd~;`����ju�l���
2
+ ~�ڙ�w�킹48�4Z'�17��W��Y�Q ����g�=�
3
+ ��mנ���[�%��D���XS����_�vHf�ނ��`����Z�:����l����\p~A}���^�O��)��Ya�ܮ�W{�R�PG�%M���F��� ��YEs�XҐE���d*%������.��L��ߐ� <耯hLH