snipgem 0.0.5
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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/Rakefile +42 -0
- data/app/controllers/controller.rb +20 -0
- data/app/models/snippet.rb +37 -0
- data/app/models/utils/batchprocessing.rb +11 -0
- data/app/models/utils/codescanner.rb +58 -0
- data/app/models/utils/destinationfilewriter.rb +100 -0
- data/app/models/utils/sourcefilereader.rb +63 -0
- data/app/views/viewformatter.rb +133 -0
- data/bin/snip +6 -0
- data/config/filepath.config +0 -0
- data/lib/snip/version.rb +3 -0
- data/lib/snip.rb +56 -0
- data/my_snips.rb +0 -0
- data/pkg/snip-0.0.1.gem +0 -0
- data/rspec/rspec.rb +158 -0
- data/rspec/snip.sublime-project +9 -0
- data/rspec/snip.sublime-workspace +1644 -0
- data/rspec/test_snip_files/subfolder/test3.rb +31 -0
- data/rspec/test_snip_files/test.rb +22 -0
- data/rspec/test_snip_files/test2.rb +17 -0
- data/snip.gemspec +28 -0
- metadata +119 -0
data/rspec/rspec.rb
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
# require 'active_record'
|
3
|
+
require_relative '../app/controllers/controller'
|
4
|
+
# require_relative '../config/environment'
|
5
|
+
|
6
|
+
describe "This program" do
|
7
|
+
|
8
|
+
# Setting up a test file and test code to work off of
|
9
|
+
before :all do
|
10
|
+
|
11
|
+
@rspec_test_file = "rspec_test.rb"
|
12
|
+
@num_of_snips = rand(1..10)
|
13
|
+
@test_file_code =
|
14
|
+
[
|
15
|
+
"#<snip>\n",
|
16
|
+
"5.times {|x| p x}\n",
|
17
|
+
"5.times {|x| p x}\n",
|
18
|
+
"#</snip>\n",
|
19
|
+
"\n"
|
20
|
+
]*@num_of_snips
|
21
|
+
|
22
|
+
File.open(@rspec_test_file, 'w+') do |f|
|
23
|
+
@test_file_code.each do |code|
|
24
|
+
f << code
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ARGV[0] = @rspec_test_file
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# Deleting test file after completion of tests
|
33
|
+
after :all do
|
34
|
+
File.delete(@rspec_test_file)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe SourceFileReaderWriter do
|
38
|
+
let(:open_file) {SourceFileReaderWriter.new(ARGV.first)}
|
39
|
+
|
40
|
+
describe "::new" do
|
41
|
+
|
42
|
+
it "should read command line for filename" do
|
43
|
+
command_line = ARGV[0]
|
44
|
+
open_file
|
45
|
+
expect(SourceFileReaderWriter.file_to_open).to eq(command_line)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".convert_to_array_of_lines" do
|
50
|
+
|
51
|
+
it "converts file input to an array" do
|
52
|
+
code_array = open_file.convert_to_array_of_lines
|
53
|
+
expect(code_array).to be_a Array
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
describe CodeScanner do
|
62
|
+
|
63
|
+
let(:empty_array) {[]}
|
64
|
+
let(:test_array) {SourceFileReaderWriter.new(@rspec_test_file).convert_to_array_of_lines}
|
65
|
+
|
66
|
+
before :all do
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
after :each do
|
71
|
+
Snippet.class_variable_set(:@@snippet_array, [])
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "::run" do
|
75
|
+
|
76
|
+
it "creates an empty array for an empty input" do
|
77
|
+
CodeScanner.run(empty_array, @rspec_test_file)
|
78
|
+
expect(CodeScanner.scan_array).to be_a Array
|
79
|
+
expect(CodeScanner.scan_array.length).to eq(0)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "creates snippets for each snip tag in the code array" do
|
83
|
+
CodeScanner.run(test_array, @rspec_test_file)
|
84
|
+
expect(Snippet.snippet_array.length).to eq(@num_of_snips)
|
85
|
+
expect(Snippet.snippet_array.first).to be_a Snippet
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
it "removes opening and closing tags from the local scan array" do
|
90
|
+
CodeScanner.run(test_array, @rspec_test_file)
|
91
|
+
expect(CodeScanner.scan_array.join.include?('snip>')).to eq(false)
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
describe "::run special cases" do
|
102
|
+
|
103
|
+
before :all do
|
104
|
+
|
105
|
+
@rspec_test_file = "rspec_test.rb"
|
106
|
+
@num_of_snips = rand(1..10)
|
107
|
+
@test_file_code =
|
108
|
+
["# erwer <snip>Title\n",
|
109
|
+
"5.times {|x| pppppp x}\n",
|
110
|
+
"# rwerewr </snip> rewre \n",
|
111
|
+
"\n"
|
112
|
+
]*@num_of_snips
|
113
|
+
|
114
|
+
File.open(@rspec_test_file, 'w+') do |f|
|
115
|
+
@test_file_code.each do |code|
|
116
|
+
f << code
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
ARGV[0] = @rspec_test_file
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
# Deleting test file after completion of tests
|
126
|
+
after :all do
|
127
|
+
File.delete(@rspec_test_file)
|
128
|
+
end
|
129
|
+
|
130
|
+
let(:empty_array) {[]}
|
131
|
+
let(:test_array) {SourceFileReaderWriter.new(@rspec_test_file).convert_to_array_of_lines}
|
132
|
+
|
133
|
+
it "finds tags anywhere in the line, not just adjacent to the # comment symbol" do
|
134
|
+
p Snippet.snippet_array
|
135
|
+
CodeScanner.run(test_array, @rspec_test_file)
|
136
|
+
expect(Snippet.snippet_array.length).to eq(@num_of_snips)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "contains the expected title" do
|
140
|
+
expect(Snippet.snippet_array[0].title).to eq("Title")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "contains the expected filename" do
|
144
|
+
expect(Snippet.snippet_array[0].filename).to eq(@rspec_test_file)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "contains the expected line number" do
|
148
|
+
expect(Snippet.snippet_array[0].line).to eq(1)
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|