rstub 0.1.3 → 0.2.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 +4 -4
- data/lib/rstub/path_parser.rb +11 -3
- data/lib/rstub.rb +3 -3
- data/rstub.gemspec +1 -1
- data/spec/file_parser_spec.rb +59 -70
- data/spec/path_parser_spec.rb +22 -22
- data/spec/rstub_spec.rb +17 -29
- data/spec/spec_helper.rb +21 -0
- metadata +2 -7
- data/spec/fixtures/baz.rb +0 -1
- data/spec/fixtures/foo.rb +0 -0
- data/spec/fixtures/foobar/foobaz.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fca65c701dc58118fbb3791d49778b7119309bce
|
|
4
|
+
data.tar.gz: f34d7b9e44d1df57392939bbd6579068a677f14d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5fefb10fd8466b63c231e99f3a41954c2d7579481a312fc9bbf8955cf3fd3e09ca03fc860bce1778f2881b4979bf4f204ed689eb6c12fcbedfe6518411d6b678
|
|
7
|
+
data.tar.gz: f884090380dde77d40408c6fbf5946f204ad0c8db9f8ff511c0d7a75c93c700de722135f42280c3e9e8ae70f87caca381859454d8dcff3e4d43a5b146e1a0063
|
data/lib/rstub/path_parser.rb
CHANGED
|
@@ -37,14 +37,22 @@ class PathParser
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def get_directories(files)
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
dirs = []
|
|
41
|
+
files.each do |file|
|
|
42
|
+
if Dir.exist? file
|
|
43
|
+
dirs << file
|
|
44
|
+
dirs.concat(get_directories(Dir.glob("#{file}/*")))
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
dirs
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
def get_files_from_directory(files, directories)
|
|
45
51
|
directories.each do |dir|
|
|
46
52
|
files.delete(dir)
|
|
47
|
-
|
|
53
|
+
Dir.glob("#{dir}/*").each do |file|
|
|
54
|
+
files << file unless File.directory? file
|
|
55
|
+
end
|
|
48
56
|
end
|
|
49
57
|
files
|
|
50
58
|
end
|
data/lib/rstub.rb
CHANGED
|
@@ -38,18 +38,18 @@ class RStub
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def make_target_directory
|
|
41
|
-
Dir.mkdir(target) unless Dir.
|
|
41
|
+
Dir.mkdir(target) unless Dir.exist? target
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def make_new_directories
|
|
45
45
|
directories.each do |d|
|
|
46
46
|
new_dir = "#{target}/#{d}"
|
|
47
|
-
Dir.mkdir(new_dir) unless
|
|
47
|
+
Dir.mkdir(new_dir) unless Dir.exist?(new_dir)
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def make_new_files
|
|
52
|
-
target_files.each { |file| File.new(file, 'w') }
|
|
52
|
+
target_files.each { |file| File.new(file, 'w') unless directory? file }
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def parse_files_and_directories
|
data/rstub.gemspec
CHANGED
data/spec/file_parser_spec.rb
CHANGED
|
@@ -1,91 +1,80 @@
|
|
|
1
1
|
describe FileParser do
|
|
2
2
|
describe '#stub' do
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
after(:each) do
|
|
8
|
-
FileUtils.rm_r('target')
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
after(:all) do
|
|
12
|
-
File.new('foo.rb', 'w')
|
|
13
|
-
Dir.chdir('../..')
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def add_text(text)
|
|
17
|
-
File.open('foo.rb', 'w') { |f| f.puts text }
|
|
3
|
+
def add_text(file, text)
|
|
4
|
+
File.open(file, 'w') { |f| f.puts text }
|
|
18
5
|
end
|
|
19
6
|
|
|
20
7
|
def stub_all
|
|
21
8
|
RStub.new.start(['*', 'target'])
|
|
22
9
|
end
|
|
23
10
|
|
|
24
|
-
def expect_text(text)
|
|
25
|
-
expect(IO.read(
|
|
11
|
+
def expect_text(file, text)
|
|
12
|
+
expect(IO.read("target/#{file}")).to eql(text)
|
|
26
13
|
end
|
|
27
14
|
|
|
28
|
-
|
|
29
|
-
text
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
describe 'can stub files in the top directory' do
|
|
16
|
+
it 'can add text without stubs' do
|
|
17
|
+
text = "foo\nbar\n"
|
|
18
|
+
add_text('file1.rb', text)
|
|
19
|
+
stub_all
|
|
20
|
+
expect_text('file1.rb', "foo\nbar\n")
|
|
21
|
+
end
|
|
34
22
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
it 'stubs out stub delimiter' do
|
|
24
|
+
text = "# STUB\n"
|
|
25
|
+
add_text('file1.rb', text)
|
|
26
|
+
stub_all
|
|
27
|
+
expect_text('file1.rb', '')
|
|
28
|
+
end
|
|
41
29
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
it 'preserves text before stub delimiter' do
|
|
31
|
+
text = "hello\n# STUB\n"
|
|
32
|
+
add_text('file1.rb', text)
|
|
33
|
+
stub_all
|
|
34
|
+
expect_text('file1.rb', "hello\n")
|
|
35
|
+
end
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
37
|
+
it 'doesn\'t include endstub delimiter' do
|
|
38
|
+
text = "# STUB\n# ENDSTUB\n"
|
|
39
|
+
add_text('file1.rb', text)
|
|
40
|
+
stub_all
|
|
41
|
+
expect_text('file1.rb', '')
|
|
42
|
+
end
|
|
55
43
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
44
|
+
it 'doesn\'t include text between stub delimiters' do
|
|
45
|
+
text = "# STUB\n hello # ENDSTUB\n"
|
|
46
|
+
add_text('file1.rb', text)
|
|
47
|
+
stub_all
|
|
48
|
+
expect_text('file1.rb', '')
|
|
49
|
+
end
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
it 'doesn\'t include text after the # STUB' do
|
|
52
|
+
text = "# STUB\n hello\n"
|
|
53
|
+
add_text('file1.rb', text)
|
|
54
|
+
stub_all
|
|
55
|
+
expect_text('file1.rb', '')
|
|
56
|
+
end
|
|
69
57
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
it 'doesn\'t care about other stub starting delimiters after the first' do
|
|
59
|
+
text = "# STUB\n hello\n # STUB"
|
|
60
|
+
add_text('file1.rb', text)
|
|
61
|
+
stub_all
|
|
62
|
+
expect_text('file1.rb', '')
|
|
63
|
+
end
|
|
76
64
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
65
|
+
it 'includes plain end stub delimiters' do
|
|
66
|
+
text = "# ENDSTUB\n"
|
|
67
|
+
add_text('file1.rb', text)
|
|
68
|
+
stub_all
|
|
69
|
+
expect_text('file1.rb', "# ENDSTUB\n")
|
|
70
|
+
end
|
|
83
71
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
72
|
+
it 'resumes putting in text after end delimiter' do
|
|
73
|
+
text = "hello\n# STUB\nworld\n# ENDSTUB\nfoo\n"
|
|
74
|
+
add_text('file1.rb', text)
|
|
75
|
+
stub_all
|
|
76
|
+
expect_text('file1.rb', "hello\nfoo\n")
|
|
77
|
+
end
|
|
89
78
|
end
|
|
90
79
|
end
|
|
91
80
|
end
|
data/spec/path_parser_spec.rb
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
describe PathParser do
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
describe '#get_globs' do
|
|
3
|
+
before :all do
|
|
4
|
+
Dir.mkdir 'test_dir/nested_dir'
|
|
5
|
+
File.new 'test_dir/nested_dir/nested_file2.rb', 'w+'
|
|
6
|
+
end
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
after :all do
|
|
9
|
+
FileUtils.rm_r 'test_dir/nested_dir' if Dir.exist? 'test_dir/nested_dir'
|
|
10
|
+
end
|
|
9
11
|
|
|
10
|
-
describe '#get_globs' do
|
|
11
12
|
let(:path_parser) { PathParser.new }
|
|
12
13
|
|
|
13
14
|
it 'returns the same array when there is no match' do
|
|
14
|
-
expect(path_parser.get_globs(['
|
|
15
|
-
.to match_array(['
|
|
15
|
+
expect(path_parser.get_globs(['file1.rb'])[:files])
|
|
16
|
+
.to match_array(['file1.rb'])
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
it 'returns glob matches from current directory' do
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
expect(path_parser.get_globs(['*', 'foo/bar.rb'])[:directories])
|
|
26
|
-
.to match_array(%w(foo foobar))
|
|
27
|
-
expect(path_parser.get_globs(['*', 'foo/bar.rb'])[:files])
|
|
28
|
-
.to match_array(%w(foo/bar.rb baz.rb foo.rb foobar/foobaz.rb))
|
|
20
|
+
paths = path_parser.get_globs(['*'])
|
|
21
|
+
expect(paths[:directories])
|
|
22
|
+
.to match_array(%w(test_dir test_dir/nested_dir))
|
|
23
|
+
expect(paths[:files])
|
|
24
|
+
.to match_array(%w(file1.rb file2.rb test_dir/nested_file.rb
|
|
25
|
+
test_dir/nested_dir/nested_file2.rb))
|
|
29
26
|
end
|
|
30
27
|
|
|
31
28
|
it 'returns glob matches from lowel directory' do
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
paths = path_parser.get_globs(['*/*'])
|
|
30
|
+
expect(paths[:directories])
|
|
31
|
+
.to match_array(%w(test_dir/nested_dir))
|
|
32
|
+
expect(paths[:files])
|
|
33
|
+
.to match_array(%w(test_dir/nested_file.rb
|
|
34
|
+
test_dir/nested_dir/nested_file2.rb))
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
data/spec/rstub_spec.rb
CHANGED
|
@@ -1,36 +1,24 @@
|
|
|
1
1
|
describe RStub do
|
|
2
2
|
describe '#start' do
|
|
3
|
-
before(:all) do
|
|
4
|
-
Dir.chdir('spec/fixtures')
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
after(:each) do
|
|
8
|
-
FileUtils.rm_r 'target' if Dir.exist?('target')
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
after(:all) do
|
|
12
|
-
Dir.chdir('../..')
|
|
13
|
-
end
|
|
14
|
-
|
|
15
3
|
let(:rstub) { RStub.new }
|
|
16
4
|
|
|
17
5
|
it 'creates the correct directory and file' do
|
|
18
|
-
rstub.start(['
|
|
6
|
+
rstub.start(['file1.rb', 'target'])
|
|
19
7
|
expect(Dir.exist?('target')).to be true
|
|
20
|
-
expect(File.exist?('target/
|
|
8
|
+
expect(File.exist?('target/file1.rb')).to be true
|
|
21
9
|
end
|
|
22
10
|
|
|
23
11
|
it 'raises error with invalid number of arguments' do
|
|
24
12
|
expect { rstub.start }.to raise_error('Not enough arguments')
|
|
25
|
-
expect { rstub.start(['
|
|
13
|
+
expect { rstub.start(['file1']) }.to raise_error('Not enough arguments')
|
|
26
14
|
end
|
|
27
15
|
|
|
28
16
|
it 'raises error if the last argument isn\'t a directory' do
|
|
29
|
-
expect { rstub.start(['
|
|
17
|
+
expect { rstub.start(['file1.rb', 'file2.rb']) }
|
|
30
18
|
.to raise_error('The last argument needs to be a directory')
|
|
31
|
-
expect { rstub.start(['target', '
|
|
19
|
+
expect { rstub.start(['target', 'file1.rb']) }
|
|
32
20
|
.to raise_error('The last argument needs to be a directory')
|
|
33
|
-
expect { rstub.start(['
|
|
21
|
+
expect { rstub.start(['file1.rb', '*']) }
|
|
34
22
|
.to raise_error('The last argument needs to be a directory')
|
|
35
23
|
end
|
|
36
24
|
|
|
@@ -41,32 +29,32 @@ describe RStub do
|
|
|
41
29
|
end
|
|
42
30
|
|
|
43
31
|
it 'adds multiple files to the directory' do
|
|
44
|
-
rstub.start(['
|
|
32
|
+
rstub.start(['file1.rb', 'file2.rb', 'target'])
|
|
45
33
|
expect(Dir.exist?('target')).to be true
|
|
46
|
-
expect(File.exist?('target/
|
|
47
|
-
expect(File.exist?('target/
|
|
34
|
+
expect(File.exist?('target/file1.rb')).to be true
|
|
35
|
+
expect(File.exist?('target/file2.rb')).to be true
|
|
48
36
|
end
|
|
49
37
|
|
|
50
38
|
it 'doesn\'t add nonexistent files even when there are multiple files' do
|
|
51
|
-
rstub.start(['
|
|
39
|
+
rstub.start(['file1.rb', 'bar.rb', 'target'])
|
|
52
40
|
expect(Dir.exist?('target')).to be true
|
|
53
|
-
expect(File.exist?('target/
|
|
41
|
+
expect(File.exist?('target/file1.rb')).to be true
|
|
54
42
|
expect(File.exist?('target/bar.rb')).to be false
|
|
55
43
|
end
|
|
56
44
|
|
|
57
45
|
it 'doesn\'t add nonexistent files even with wildcard' do
|
|
58
|
-
rstub.start(['
|
|
46
|
+
rstub.start(['file1/*', 'target'])
|
|
59
47
|
expect(Dir.exist?('target')).to be true
|
|
60
|
-
expect(Dir.exist?('target/
|
|
48
|
+
expect(Dir.exist?('target/file1')).to be false
|
|
61
49
|
end
|
|
62
50
|
|
|
63
51
|
it 'all files are added with wildcard' do
|
|
64
52
|
rstub.start(['*', 'target'])
|
|
65
53
|
expect(Dir.exist?('target')).to be true
|
|
66
|
-
expect(File.exist?('target/
|
|
67
|
-
expect(File.exist?('target/
|
|
68
|
-
expect(Dir.exist?('target/
|
|
69
|
-
expect(File.exist?('target/
|
|
54
|
+
expect(File.exist?('target/file1.rb')).to be true
|
|
55
|
+
expect(File.exist?('target/file2.rb')).to be true
|
|
56
|
+
expect(Dir.exist?('target/test_dir')).to be true
|
|
57
|
+
expect(File.exist?('target/test_dir/nested_file.rb')).to be true
|
|
70
58
|
end
|
|
71
59
|
end
|
|
72
60
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -7,3 +7,24 @@ Coveralls.wear!
|
|
|
7
7
|
|
|
8
8
|
require 'rstub'
|
|
9
9
|
Dir[File.expand_path('../../lib/rstub/*.rb', __FILE__)].each { |f| require f }
|
|
10
|
+
|
|
11
|
+
RSpec.configure do |config|
|
|
12
|
+
config.before :all do
|
|
13
|
+
Dir.chdir('spec/fixtures')
|
|
14
|
+
Dir.mkdir 'test_dir' unless Dir.exist? 'test_dir'
|
|
15
|
+
File.new 'file1.rb', 'w+'
|
|
16
|
+
File.new 'file2.rb', 'w+'
|
|
17
|
+
File.new 'test_dir/nested_file.rb', 'w+'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
config.after :each do
|
|
21
|
+
FileUtils.rm_r 'target' if Dir.exist? 'target'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
config.after :all do
|
|
25
|
+
FileUtils.rm_r 'test_dir' if Dir.exist? 'test_dir'
|
|
26
|
+
FileUtils.rm_r 'file1.rb'
|
|
27
|
+
FileUtils.rm_r 'file2.rb'
|
|
28
|
+
Dir.chdir('../..')
|
|
29
|
+
end
|
|
30
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rstub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Kim
|
|
@@ -59,9 +59,6 @@ files:
|
|
|
59
59
|
- lib/rstub/path_parser.rb
|
|
60
60
|
- rstub.gemspec
|
|
61
61
|
- spec/file_parser_spec.rb
|
|
62
|
-
- spec/fixtures/baz.rb
|
|
63
|
-
- spec/fixtures/foo.rb
|
|
64
|
-
- spec/fixtures/foobar/foobaz.rb
|
|
65
62
|
- spec/path_parser_spec.rb
|
|
66
63
|
- spec/rstub_spec.rb
|
|
67
64
|
- spec/spec_helper.rb
|
|
@@ -91,9 +88,7 @@ specification_version: 4
|
|
|
91
88
|
summary: A gem to stub out code
|
|
92
89
|
test_files:
|
|
93
90
|
- spec/file_parser_spec.rb
|
|
94
|
-
- spec/fixtures/baz.rb
|
|
95
|
-
- spec/fixtures/foo.rb
|
|
96
|
-
- spec/fixtures/foobar/foobaz.rb
|
|
97
91
|
- spec/path_parser_spec.rb
|
|
98
92
|
- spec/rstub_spec.rb
|
|
99
93
|
- spec/spec_helper.rb
|
|
94
|
+
has_rdoc:
|
data/spec/fixtures/baz.rb
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
data/spec/fixtures/foo.rb
DELETED
|
File without changes
|
|
File without changes
|