File: ruby-beautify_spec.rb

package info (click to toggle)
ruby-beautify 0.97.4-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 340 kB
  • sloc: ruby: 628; makefile: 8
file content (65 lines) | stat: -rw-r--r-- 2,743 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'spec_helper.rb'

describe "Ruby Beautify" do
	# This acts as a config block for files and anything else that you may set.
	before (:all) do
		# a very quick to parse file, since this isn't to test the function of the parser (but the function of the binary).
		@small_file = 'spec/binary_scenarios/small_example.rb'
		# should be the contents of the small file twice.
		@doubled_file = 'spec/binary_scenarios/doubled_example.rb'
		# Our file to overwrite (should be ugly to start).
		@overwrite_file = "spec/binary_scenarios/overwrite.rb"
		@overwrite_target_file = "tmp/copied.rb"
		@overwrite_pretty_file = "spec/binary_scenarios/overwrite_pretty.rb"
		# Our space test.
		@space_before = 'spec/binary_scenarios/spaces_before.rb'
		@space_after = 'spec/binary_scenarios/spaces_after.rb'
		@space_after_sum = Digest::MD5.hexdigest File.read @space_after
		# our count test.
		@count_before = 'spec/binary_scenarios/count_before.rb'
		@count_after = 'spec/binary_scenarios/count_after.rb'
	end

	it "will work" do
		small_md5_sum = Digest::MD5.hexdigest File.read(@small_file)
		md5_sum = Digest::MD5.hexdigest `exec #{BEAUTIFY_BIN} #{@small_file}`
		expect(md5_sum).to eq small_md5_sum
	end

	it "will do multiple files" do
		md5_sum = Digest::MD5.hexdigest `exec #{BEAUTIFY_BIN} #{@small_file} #{@small_file}`
		doubled_md5_sum = Digest::MD5.hexdigest File.read(@doubled_file)
		expect(md5_sum).to eq doubled_md5_sum
	end

	# I want to make sure the file actually changes, so I do this (I could make yet another file).
	it "will update files (overwrite) in place" do
		FileUtils.mkdir_p File.dirname @overwrite_target_file
		FileUtils.cp @overwrite_file, @overwrite_target_file
		`exec #{BEAUTIFY_BIN} --overwrite #{@overwrite_target_file}`
		md5_sum = Digest::MD5.hexdigest File.read @overwrite_target_file
	 	overwrite_md5_sum = Digest::MD5.hexdigest File.read(@overwrite_pretty_file)
		expect(md5_sum).to eq overwrite_md5_sum
		FileUtils.rm @overwrite_target_file
	end

	it "will honor --spaces" do
		beautified_sum = Digest::MD5.hexdigest `exec #{BEAUTIFY_BIN} --spaces #{@space_before}`
		expect(beautified_sum).to eq(@space_after_sum)
	end

	it "will honor the ident_count prefix" do
		beautified_sum = Digest::MD5.hexdigest `exec #{BEAUTIFY_BIN} --indent_count=3 #{@count_before}`
		count_after_sum = Digest::MD5.hexdigest File.read @count_after
		expect(beautified_sum).to eq(count_after_sum)
	end

	it "will use a .ruby-beautify config file" do
		FileUtils.cp "spec/ruby-beautify.dotfile", "tmp/.ruby-beautify"
		Dir.chdir "tmp"
		beautified_sum = Digest::MD5.hexdigest `exec #{BEAUTIFY_BIN} ../#{@space_before}`
		Dir.chdir ".."
		FileUtils.rm "tmp/.ruby-beautify"
		expect(beautified_sum).to eq(@space_after_sum)
	end
end