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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecffc042bdc6192d0e134540bf3952861dc70bac
4
- data.tar.gz: dc688dd4721bd4cbde6f381b058cb55d2e6972d4
3
+ metadata.gz: fca65c701dc58118fbb3791d49778b7119309bce
4
+ data.tar.gz: f34d7b9e44d1df57392939bbd6579068a677f14d
5
5
  SHA512:
6
- metadata.gz: 29c7d8a57f05805d818a1fe56b987cb303de7d9d0cca65829f259694c8944c5268ffa86ff539fcac9fb53231e8631d5cc95fe3f07832ecc959f4ef14cdcd241a
7
- data.tar.gz: 2f6d0adc62a34381d6d269380c735e4285d90b81c7f01b5bcfbbf419d4573fbf31b2646b98e8a52f97b480e6a9369c9aeb1fe1c6209d7d2ff6a79b26c41b2400
6
+ metadata.gz: 5fefb10fd8466b63c231e99f3a41954c2d7579481a312fc9bbf8955cf3fd3e09ca03fc860bce1778f2881b4979bf4f204ed689eb6c12fcbedfe6518411d6b678
7
+ data.tar.gz: f884090380dde77d40408c6fbf5946f204ad0c8db9f8ff511c0d7a75c93c700de722135f42280c3e9e8ae70f87caca381859454d8dcff3e4d43a5b146e1a0063
@@ -37,14 +37,22 @@ class PathParser
37
37
  end
38
38
 
39
39
  def get_directories(files)
40
- files.select { |file| Dir.exist?(file) }
41
- .concat(parse_out_directories(files))
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
- files << Dir.glob("#{dir}/*")
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.exists? target
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 d == target && Dir.exists?(new_dir)
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rstub'
3
- s.version = '0.1.3'
3
+ s.version = '0.2.0'
4
4
 
5
5
  s.date = '2015-05-30'
6
6
  s.summary = 'A gem to stub out code'
@@ -1,91 +1,80 @@
1
1
  describe FileParser do
2
2
  describe '#stub' do
3
- before(:all) do
4
- Dir.chdir('spec/fixtures')
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('target/foo.rb')).to eql(text)
11
+ def expect_text(file, text)
12
+ expect(IO.read("target/#{file}")).to eql(text)
26
13
  end
27
14
 
28
- it 'can add text without stubs' do
29
- text = "foo\nbar\n"
30
- add_text(text)
31
- stub_all
32
- expect_text("foo\nbar\n")
33
- end
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
- it 'stubs out stub delimiter' do
36
- text = "# STUB\n"
37
- add_text(text)
38
- stub_all
39
- expect_text('')
40
- end
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
- it 'preserves text before stub delimiter' do
43
- text = "hello\n# STUB\n"
44
- add_text(text)
45
- stub_all
46
- expect_text("hello\n")
47
- end
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
- it 'doesn\'t include endstub delimiter' do
50
- text = "# STUB\n# ENDSTUB\n"
51
- add_text(text)
52
- stub_all
53
- expect_text('')
54
- end
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
- it 'doesn\'t include text between stub delimiters' do
57
- text = "# STUB\n hello # ENDSTUB\n"
58
- add_text(text)
59
- stub_all
60
- expect_text('')
61
- end
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
- it 'doesn\'t include text after the # STUB' do
64
- text = "# STUB\n hello\n"
65
- add_text(text)
66
- stub_all
67
- expect_text('')
68
- end
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
- it 'doesn\'t care about other stub starting delimiters after the first' do
71
- text = "# STUB\n hello\n # STUB"
72
- add_text(text)
73
- stub_all
74
- expect_text('')
75
- end
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
- it 'includes plain end stub delimiters' do
78
- text = "# ENDSTUB\n"
79
- add_text(text)
80
- stub_all
81
- expect_text("# ENDSTUB\n")
82
- end
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
- it 'resumes putting in text after end delimiter' do
85
- text = "hello\n# STUB\nworld\n# ENDSTUB\nfoo\n"
86
- add_text(text)
87
- stub_all
88
- expect_text("hello\nfoo\n")
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
@@ -1,37 +1,37 @@
1
1
  describe PathParser do
2
- before(:all) do
3
- Dir.chdir('spec/fixtures')
4
- end
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
- after(:all) do
7
- Dir.chdir('../..')
8
- end
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(['foo.rb'])[:files])
15
- .to match_array(['foo.rb'])
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
- expect(path_parser.get_globs(['*']))
20
- .to match_array(directories: ['foobar'],
21
- files: %w(baz.rb foo.rb foobar/foobaz.rb))
22
- end
23
-
24
- it 'adds glob matches to the rest of the files' do
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
- expect(path_parser.get_globs(['*/*']))
33
- .to match_array(directories: ['foobar'],
34
- files: ['foobar/foobaz.rb'])
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(['foo.rb', 'target'])
6
+ rstub.start(['file1.rb', 'target'])
19
7
  expect(Dir.exist?('target')).to be true
20
- expect(File.exist?('target/foo.rb')).to be true
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(['foo']) }.to raise_error('Not enough arguments')
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(['foo.rb', 'baz.rb']) }
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', 'foo.rb']) }
19
+ expect { rstub.start(['target', 'file1.rb']) }
32
20
  .to raise_error('The last argument needs to be a directory')
33
- expect { rstub.start(['foo.rb', '*']) }
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(['foo.rb', 'baz.rb', 'target'])
32
+ rstub.start(['file1.rb', 'file2.rb', 'target'])
45
33
  expect(Dir.exist?('target')).to be true
46
- expect(File.exist?('target/foo.rb')).to be true
47
- expect(File.exist?('target/baz.rb')).to be true
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(['foo.rb', 'bar.rb', 'target'])
39
+ rstub.start(['file1.rb', 'bar.rb', 'target'])
52
40
  expect(Dir.exist?('target')).to be true
53
- expect(File.exist?('target/foo.rb')).to be true
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(['foo/*', 'target'])
46
+ rstub.start(['file1/*', 'target'])
59
47
  expect(Dir.exist?('target')).to be true
60
- expect(Dir.exist?('target/foo')).to be false
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/foo.rb')).to be true
67
- expect(File.exist?('target/baz.rb')).to be true
68
- expect(Dir.exist?('target/foobar')).to be true
69
- expect(File.exist?('target/foobar/foobaz.rb')).to be true
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.1.3
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