ruby-beautify 0.96.0 → 0.97.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/CONTRIB.md +7 -0
- data/README.md +21 -22
- data/WHATSNEW.md +7 -0
- data/bin/rbeautify +36 -17
- data/bin/ruby-beautify +36 -17
- data/lib/ruby-beautify.rb +146 -144
- data/lib/ruby-beautify/version.rb +1 -1
- data/spec/bin/ruby-beautify_spec.rb +37 -18
- data/spec/binary_scenarios/doubled_example.rb +6 -0
- data/spec/binary_scenarios/overwrite.rb +6 -0
- data/spec/binary_scenarios/overwrite_pretty.rb +6 -0
- data/spec/binary_scenarios/small_example.rb +3 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/usage_scenarios/README.md +44 -0
- data/spec/usage_scenarios/case.rb +11 -0
- data/spec/usage_scenarios/case_pretty.rb +11 -0
- data/spec/usage_scenarios/from_control.rb +17 -0
- data/spec/usage_scenarios/from_control_pretty.rb +17 -0
- data/spec/usage_scenarios/monolithic_example.rb +40 -0
- data/spec/usage_scenarios/monolithic_example_pretty.rb +40 -0
- data/spec/usage_scenarios/multiline_strings.rb +10 -0
- data/spec/usage_scenarios/multiline_strings_pretty.rb +10 -0
- data/spec/usage_scenarios/mutli_level.rb +34 -0
- data/spec/usage_scenarios/mutli_level_pretty.rb +34 -0
- data/spec/usage_scenarios/or_equals.rb +21 -0
- data/spec/usage_scenarios/or_equals_pretty.rb +21 -0
- data/spec/usage_scenarios/pre_indented.rb +12 -0
- data/spec/usage_scenarios/pre_indented_pretty.rb +12 -0
- data/spec/usage_scenarios_spec.rb +20 -0
- metadata +42 -6
- data/spec/example.rb +0 -151
- data/spec/example_beautified.rb +0 -151
@@ -1,22 +1,41 @@
|
|
1
|
-
# one big spec (for now).
|
2
1
|
require 'spec_helper.rb'
|
3
|
-
require 'digest/md5'
|
4
|
-
|
5
|
-
# this is so simple, it's stupid. I basically used the 'example.rb' file while
|
6
|
-
# testing this indenting method. So I've visually approved of the output, and
|
7
|
-
# I've run that through md5. Then we just run our build, gather that md5 and
|
8
|
-
# compare the two.
|
9
|
-
# Eventually, I should break out the code into smaller chunks so I can identify
|
10
|
-
# which component is breaking down.
|
11
2
|
|
12
3
|
describe "Ruby Beautify" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
4
|
+
# This acts as a config block for files and anything else that you may set.
|
5
|
+
before (:all) do
|
6
|
+
# a very quick to parse file, since this isn't to test the function of the parser (but the function of the binary).
|
7
|
+
@small_file = 'spec/binary_scenarios/small_example.rb'
|
8
|
+
# should be the contents of the small file twice.
|
9
|
+
@doubled_file = 'spec/binary_scenarios/doubled_example.rb'
|
10
|
+
# Our file to overwrite (should be ugly to start).
|
11
|
+
@overwrite_file = "spec/binary_scenarios/overwrite.rb"
|
12
|
+
@overwrite_target_file = "tmp/copied.rb"
|
13
|
+
@overwrite_pretty_file = "spec/binary_scenarios/overwrite_pretty.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "will work" do
|
17
|
+
small_md5_sum = Digest::MD5.hexdigest File.read(@small_file)
|
18
|
+
md5_sum = Digest::MD5.hexdigest `bundle exec #{BEAUTIFY_BIN} #{@small_file}`
|
19
|
+
expect(md5_sum).to eq small_md5_sum
|
20
|
+
end
|
21
|
+
|
22
|
+
it "will do multiple files" do
|
23
|
+
md5_sum = Digest::MD5.hexdigest `bundle exec #{BEAUTIFY_BIN} #{@small_file} #{@small_file}`
|
24
|
+
doubled_md5_sum = Digest::MD5.hexdigest File.read(@doubled_file)
|
25
|
+
expect(md5_sum).to eq doubled_md5_sum
|
26
|
+
end
|
27
|
+
|
28
|
+
# I want to make sure the file actually changes, so I do this (I could make yet another file).
|
29
|
+
it "will update files (overwrite) in place" do
|
30
|
+
FileUtils.mkdir_p File.dirname @overwrite_target_file
|
31
|
+
FileUtils.cp @overwrite_file, @overwrite_target_file
|
32
|
+
`bundle exec #{BEAUTIFY_BIN} --overwrite #{@overwrite_target_file}`
|
33
|
+
md5_sum = Digest::MD5.hexdigest File.read @overwrite_target_file
|
34
|
+
overwrite_md5_sum = Digest::MD5.hexdigest File.read(@overwrite_pretty_file)
|
35
|
+
expect(md5_sum).to eq overwrite_md5_sum
|
36
|
+
FileUtils.rm @overwrite_target_file
|
37
|
+
end
|
38
|
+
|
39
|
+
it "will honor --tabs vs --spaces"
|
40
|
+
it "will honor the count prefix"
|
22
41
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
## This Directory
|
2
|
+
|
3
|
+
The examples in this directory are not direct examples but file pairs we want to consume/test to ensure that what we want to see is what we get.
|
4
|
+
|
5
|
+
For example, the most basic test would be something like:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
def this_is_ugly(nowhere)
|
9
|
+
if true
|
10
|
+
puts true
|
11
|
+
else
|
12
|
+
puts false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
We would expect this to look like:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
def this_is_ugly(nowhere)
|
21
|
+
if true
|
22
|
+
puts true
|
23
|
+
else
|
24
|
+
puts false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Notice we are testing that we get the *actual* output we want. Not the configuratbility of the binary or our output but rather the representation of ugly vs beauty.
|
30
|
+
|
31
|
+
We can expect a high level of redundancy in these specific examples, and that is ok. We want to ensure that as we make changes to the binary, we don't break the possible ways people use Ruby. I don't care if one file tests something another file does, as long as our ideas of what we want prettied up are throughly tested.
|
32
|
+
|
33
|
+
We should avoid testing the binary. Therefor, the tests will always be run with the binary in *default* mode. Testing the binary's options can be handled elsewhere.
|
34
|
+
|
35
|
+
## File names
|
36
|
+
|
37
|
+
Each usage pair of files will need to be in a specific format of:
|
38
|
+
|
39
|
+
```
|
40
|
+
test_or_whatever.rb
|
41
|
+
test_or_whatever_pretty.rb
|
42
|
+
```
|
43
|
+
|
44
|
+
With the pretty file being what we want it to look like by default. The spec framework will loop through, consume the pairs, execute the parsing method and print out the results. This will allow for dynamic testing and migrating from one framework to another if need be.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Test for variable assignment from an if statement
|
2
|
+
@products = if params[:category]
|
3
|
+
Category.find(params[:category]).products
|
4
|
+
else
|
5
|
+
Product.all
|
6
|
+
end
|
7
|
+
|
8
|
+
# Test for variable assignment from a block
|
9
|
+
response = begin
|
10
|
+
if true?
|
11
|
+
api_call(test)
|
12
|
+
else
|
13
|
+
rejected
|
14
|
+
end
|
15
|
+
rescue
|
16
|
+
'FALSE'
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Test for variable assignment from an if statement
|
2
|
+
@products = if params[:category]
|
3
|
+
Category.find(params[:category]).products
|
4
|
+
else
|
5
|
+
Product.all
|
6
|
+
end
|
7
|
+
|
8
|
+
# Test for variable assignment from a block
|
9
|
+
response = begin
|
10
|
+
if true?
|
11
|
+
api_call(test)
|
12
|
+
else
|
13
|
+
rejected
|
14
|
+
end
|
15
|
+
rescue
|
16
|
+
'FALSE'
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
|
3
|
+
h = Here::There.new
|
4
|
+
|
5
|
+
h.why?({
|
6
|
+
here: 'there',
|
7
|
+
there: 'here'
|
8
|
+
})
|
9
|
+
|
10
|
+
h.with_block {
|
11
|
+
puts 'yahooie'
|
12
|
+
}
|
13
|
+
|
14
|
+
|
15
|
+
h.complex_method('asdkjasflkjdglksjglksfgjlfkgjdf',
|
16
|
+
'alfkjsdlkfjsflgkjfglk',
|
17
|
+
'alfkjsdlkfjsflgkjfglk',
|
18
|
+
'alfkjsdlkfjsflgkjfglk'
|
19
|
+
)
|
20
|
+
|
21
|
+
h.complex_method('asdkjasflkjdglksjglksfgjlfkgjdf',
|
22
|
+
'alfkjsdlkfjsflgkjfglk',
|
23
|
+
'alfkjsdlkfjsflgkjfglk',
|
24
|
+
'alfkjsdlkfjsflgkjfglk'
|
25
|
+
).map do |i|
|
26
|
+
i
|
27
|
+
end.map! { |i| i }
|
28
|
+
|
29
|
+
if 1 > 0
|
30
|
+
puts 'something'
|
31
|
+
elsif 1 < 0
|
32
|
+
puts 'never!'
|
33
|
+
else
|
34
|
+
puts 'not likely.'
|
35
|
+
end
|
36
|
+
|
37
|
+
# Flattened formatting
|
38
|
+
if 1 > 0 then puts 'something'
|
39
|
+
else puts 'nothing' end
|
40
|
+
puts "This line should stay the same"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
|
3
|
+
h = Here::There.new
|
4
|
+
|
5
|
+
h.why?({
|
6
|
+
here: 'there',
|
7
|
+
there: 'here'
|
8
|
+
})
|
9
|
+
|
10
|
+
h.with_block {
|
11
|
+
puts 'yahooie'
|
12
|
+
}
|
13
|
+
|
14
|
+
|
15
|
+
h.complex_method('asdkjasflkjdglksjglksfgjlfkgjdf',
|
16
|
+
'alfkjsdlkfjsflgkjfglk',
|
17
|
+
'alfkjsdlkfjsflgkjfglk',
|
18
|
+
'alfkjsdlkfjsflgkjfglk'
|
19
|
+
)
|
20
|
+
|
21
|
+
h.complex_method('asdkjasflkjdglksjglksfgjlfkgjdf',
|
22
|
+
'alfkjsdlkfjsflgkjfglk',
|
23
|
+
'alfkjsdlkfjsflgkjfglk',
|
24
|
+
'alfkjsdlkfjsflgkjfglk'
|
25
|
+
).map do |i|
|
26
|
+
i
|
27
|
+
end.map! { |i| i }
|
28
|
+
|
29
|
+
if 1 > 0
|
30
|
+
puts 'something'
|
31
|
+
elsif 1 < 0
|
32
|
+
puts 'never!'
|
33
|
+
else
|
34
|
+
puts 'not likely.'
|
35
|
+
end
|
36
|
+
|
37
|
+
# Flattened formatting
|
38
|
+
if 1 > 0 then puts 'something'
|
39
|
+
else puts 'nothing' end
|
40
|
+
puts "This line should stay the same"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Here
|
2
|
+
class There
|
3
|
+
def why?(argument = nil)
|
4
|
+
@array = [
|
5
|
+
1,
|
6
|
+
2,
|
7
|
+
3
|
8
|
+
]
|
9
|
+
hash = {
|
10
|
+
one:1,
|
11
|
+
two:2,
|
12
|
+
three:3
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
# a comment
|
17
|
+
def why_not?(argument: {})
|
18
|
+
@array = [4,5,6]
|
19
|
+
hash = {four:4, five:5, six:6}
|
20
|
+
s = "a #{"complex"} string."
|
21
|
+
end
|
22
|
+
|
23
|
+
def complex_method(one, two, three, four)
|
24
|
+
regex = /regex/
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_block
|
28
|
+
run = Proc.new { |argument| puts arugment }
|
29
|
+
run do |arugment|
|
30
|
+
puts argument
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Here
|
2
|
+
class There
|
3
|
+
def why?(argument = nil)
|
4
|
+
@array = [
|
5
|
+
1,
|
6
|
+
2,
|
7
|
+
3
|
8
|
+
]
|
9
|
+
hash = {
|
10
|
+
one:1,
|
11
|
+
two:2,
|
12
|
+
three:3
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
# a comment
|
17
|
+
def why_not?(argument: {})
|
18
|
+
@array = [4,5,6]
|
19
|
+
hash = {four:4, five:5, six:6}
|
20
|
+
s = "a #{"complex"} string."
|
21
|
+
end
|
22
|
+
|
23
|
+
def complex_method(one, two, three, four)
|
24
|
+
regex = /regex/
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_block
|
28
|
+
run = Proc.new { |argument| puts arugment }
|
29
|
+
run do |arugment|
|
30
|
+
puts argument
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Test or-equals
|
2
|
+
def expensive_value
|
3
|
+
@expensive_value ||= begin
|
4
|
+
if conn.active?
|
5
|
+
expensive_call
|
6
|
+
else
|
7
|
+
:none
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Test multiple or-equals
|
13
|
+
def expensive_value
|
14
|
+
@expensive_value ||= @cached_value ||= begin
|
15
|
+
if conn.active?
|
16
|
+
expensive_call
|
17
|
+
else
|
18
|
+
:none
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Test or-equals
|
2
|
+
def expensive_value
|
3
|
+
@expensive_value ||= begin
|
4
|
+
if conn.active?
|
5
|
+
expensive_call
|
6
|
+
else
|
7
|
+
:none
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Test multiple or-equals
|
13
|
+
def expensive_value
|
14
|
+
@expensive_value ||= @cached_value ||= begin
|
15
|
+
if conn.active?
|
16
|
+
expensive_call
|
17
|
+
else
|
18
|
+
:none
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|