rstub 0.0.1 → 0.1.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/.gitignore +35 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +14 -0
- data/LICENSE +22 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/bin/rstub +1 -1
- data/lib/rstub/file_parser.rb +30 -0
- data/lib/rstub/path_parser.rb +53 -0
- data/lib/rstub.rb +55 -3
- data/rstub.gemspec +18 -0
- data/spec/file_parser_spec.rb +90 -0
- data/spec/fixtures/baz.rb +1 -0
- data/spec/fixtures/foo.rb +5 -0
- data/spec/fixtures/foobar/foobaz.rb +0 -0
- data/spec/path_parser_spec.rb +50 -0
- data/spec/rstub_spec.rb +72 -0
- data/spec/spec_helper.rb +9 -0
- metadata +55 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b3b5fda95d0ecb11fdee272415143f53b917c3c
|
|
4
|
+
data.tar.gz: ec0ea820b25d336f7e13fad0f488fa9192bf3552
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 96798ac54e1f6cc7b639033fc91448c0ab217f64ba192b9d27b13fe7bb83d65e006c8a64a2bd6952473ce58fbad7b2a7b0e6269787e33576a059901aff2e0e63
|
|
7
|
+
data.tar.gz: 2f572420e3b83ee4adf65bbfe724ff9a784a5d9e85c6d0379eb0b49486dbde8aa2294b6ab6b111023f69680c74d60d9ffdbef70ce12faddf396bd31670646302
|
data/.gitignore
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/test/tmp/
|
|
9
|
+
/test/version_tmp/
|
|
10
|
+
/tmp/
|
|
11
|
+
|
|
12
|
+
## Specific to RubyMotion:
|
|
13
|
+
.dat*
|
|
14
|
+
.repl_history
|
|
15
|
+
build/
|
|
16
|
+
|
|
17
|
+
## Documentation cache and generated files:
|
|
18
|
+
/.yardoc/
|
|
19
|
+
/_yardoc/
|
|
20
|
+
/doc/
|
|
21
|
+
/rdoc/
|
|
22
|
+
|
|
23
|
+
## Environment normalisation:
|
|
24
|
+
/.bundle/
|
|
25
|
+
/vendor/bundle
|
|
26
|
+
/lib/bundler/man/
|
|
27
|
+
|
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
30
|
+
Gemfile.lock
|
|
31
|
+
.ruby-version
|
|
32
|
+
.ruby-gemset
|
|
33
|
+
|
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# RStub
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/jusjmkim/rstub)
|
|
4
|
+
[](https://coveralls.io/r/jusjmkim/rstub?branch=master)
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
Run `gem install rstub`
|
|
8
|
+
|
|
9
|
+
## About
|
|
10
|
+
RStub was created for [CIS 196](http://www.seas.upenn.edu/~cis196/) to generate
|
|
11
|
+
boilerplate homework for students to fill out. It was inspired from the
|
|
12
|
+
[Stubbify](https://github.com/isibner/stubbify) module.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
Running `rstub homework.rb studentHW` on homework.rb, which has the following
|
|
16
|
+
code:
|
|
17
|
+
```ruby
|
|
18
|
+
def add (a, b)
|
|
19
|
+
# add the two input variables
|
|
20
|
+
# STUB
|
|
21
|
+
a + b
|
|
22
|
+
# ENDSTUB
|
|
23
|
+
end
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then, the stubs will be removed.
|
|
27
|
+
```ruby
|
|
28
|
+
def add (a, b)
|
|
29
|
+
# add the two input variables
|
|
30
|
+
end
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Any number of files can be provided, and files can be glob patterns like `*/*.rb`.
|
|
34
|
+
The last argument must be the test directory.
|
|
35
|
+
|
|
36
|
+
RStub preserves the relative paths of the stubbed files, so `./foo/bar.rb` will
|
|
37
|
+
be copied and stubbed into `./targetDir/foo/bar.rb`.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
$ rstub rb/homeworkFile1.rb rb/homeworkFile2.rb rb/util/homeworkUtil.rb student-homework
|
|
41
|
+
$ rstub "rb/**/*.rb" student-homework # equivalent with glob pattern
|
|
42
|
+
$ tree .
|
|
43
|
+
.
|
|
44
|
+
├── rb
|
|
45
|
+
│ ├── homeworkFile1.rb
|
|
46
|
+
│ ├── homeworkFile2.rb
|
|
47
|
+
│ └── util
|
|
48
|
+
│ └── homeworkUtil.rb
|
|
49
|
+
└── student-homework
|
|
50
|
+
└── rb
|
|
51
|
+
├── homeworkFile1.rb
|
|
52
|
+
├── homeworkFile2.rb
|
|
53
|
+
└── util
|
|
54
|
+
└── homeworkUtil.rb
|
|
55
|
+
```
|
|
56
|
+
|
data/Rakefile
ADDED
data/bin/rstub
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class FileParser
|
|
2
|
+
def stub(target_file, file)
|
|
3
|
+
File.open(file, 'r') do |readable_file|
|
|
4
|
+
File.open(target_file, 'w') do |target|
|
|
5
|
+
write_text(target, readable_file)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def start_stubbing?(line, stubbing)
|
|
13
|
+
return true if !!/#\s*stub\s*/i.match(line)
|
|
14
|
+
stubbing
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def end_stubbing?(line, stubbing)
|
|
18
|
+
return false if !!/#\s*endstub\s*/i.match(line)
|
|
19
|
+
stubbing
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def write_text(target, readable_file)
|
|
23
|
+
stubbing = false
|
|
24
|
+
IO.foreach(readable_file) do |line|
|
|
25
|
+
stubbing = start_stubbing?(line, stubbing)
|
|
26
|
+
target.puts line unless stubbing
|
|
27
|
+
stubbing = end_stubbing?(line, stubbing)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class PathParser
|
|
2
|
+
def self.directory?(directory)
|
|
3
|
+
!!/^\.?\w+$/.match(directory)
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def get_globs(files)
|
|
7
|
+
glob_files = check_globs(files)
|
|
8
|
+
directories = get_directories(glob_files)
|
|
9
|
+
all_files = get_files_from_directory(glob_files, directories)
|
|
10
|
+
{ directories: directories, files: all_files.flatten.uniq }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def is_glob?(file)
|
|
16
|
+
!!/\*/.match(file)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def check_globs(files)
|
|
20
|
+
new_files = []
|
|
21
|
+
files.each { |file| new_files << (is_glob?(file) ? Dir.glob(file) : file) }
|
|
22
|
+
new_files.flatten
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def in_directory?(file)
|
|
26
|
+
!!/\//.match(file)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def parse_files_in_directories(file)
|
|
30
|
+
file.split('/').slice(0...-1)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def parse_out_directories(files)
|
|
34
|
+
directories = []
|
|
35
|
+
files.each do |file|
|
|
36
|
+
directories << parse_files_in_directories(file) if in_directory?(file)
|
|
37
|
+
end
|
|
38
|
+
directories.flatten
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def get_directories(files)
|
|
42
|
+
files.select { |file| PathParser.directory?(file) }
|
|
43
|
+
.concat(parse_out_directories(files))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def get_files_from_directory(files, directories)
|
|
47
|
+
directories.each do |dir|
|
|
48
|
+
files.delete(dir)
|
|
49
|
+
files << Dir.glob("#{dir}/*")
|
|
50
|
+
end
|
|
51
|
+
files
|
|
52
|
+
end
|
|
53
|
+
end
|
data/lib/rstub.rb
CHANGED
|
@@ -1,8 +1,60 @@
|
|
|
1
1
|
class RStub
|
|
2
|
+
attr_reader :file_parser, :path_parser
|
|
3
|
+
attr_accessor :target, :files, :directories, :target_files
|
|
2
4
|
|
|
3
|
-
def
|
|
4
|
-
|
|
5
|
+
def initialize
|
|
6
|
+
@file_parser = FileParser.new
|
|
7
|
+
@path_parser = PathParser.new
|
|
5
8
|
end
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
def start(raw_args = '')
|
|
11
|
+
args = raw_args.split(' ')
|
|
12
|
+
raise 'Not enough arguments' if args.size < 2
|
|
13
|
+
parse_args(args)
|
|
14
|
+
make_new_directory_structure
|
|
15
|
+
parse_files
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# returns a hash with a files key with a value of an array of the files to be
|
|
21
|
+
# stubbed and a directory key with the name of the directory to be made as a
|
|
22
|
+
# string
|
|
23
|
+
def parse_args(args)
|
|
24
|
+
self.target = args.pop
|
|
25
|
+
raise 'The last argument needs to be a directory' unless PathParser.directory?(target)
|
|
26
|
+
self.files = args
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def make_target_directory
|
|
30
|
+
Dir.mkdir(target)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def make_new_directories
|
|
34
|
+
directories.each { |dir| Dir.mkdir("#{target}/#{dir}") unless dir == target }
|
|
35
|
+
end
|
|
8
36
|
|
|
37
|
+
def make_new_files
|
|
38
|
+
target_files.each { |file| File.new(file, 'w') }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def parse_files_and_directories
|
|
42
|
+
parsed_path = path_parser.get_globs(files)
|
|
43
|
+
self.files = parsed_path[:files].select { |file| File.exist? file }
|
|
44
|
+
self.target_files = files.map { |file| "#{target}/#{file}"}
|
|
45
|
+
self.directories = parsed_path[:directories]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def make_new_directory_structure
|
|
49
|
+
make_target_directory
|
|
50
|
+
parse_files_and_directories
|
|
51
|
+
make_new_directories
|
|
52
|
+
make_new_files
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def parse_files
|
|
56
|
+
target_files.each.with_index do |target_file, i|
|
|
57
|
+
file_parser.stub(target_file, files[i])
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/rstub.gemspec
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'rstub'
|
|
3
|
+
s.version = '0.1.0'
|
|
4
|
+
|
|
5
|
+
s.date = '2015-05-30'
|
|
6
|
+
s.summary = 'A gem to stub out code'
|
|
7
|
+
s.description = 'A gem to stub out pieces of code'
|
|
8
|
+
s.authors = 'Justin Kim'
|
|
9
|
+
s.email = ['justinjmkim@gmail.com']
|
|
10
|
+
s.executables = 'rstub'
|
|
11
|
+
s.homepage = 'https://github.com/jusjmkim/rstub'
|
|
12
|
+
s.license = 'MIT'
|
|
13
|
+
|
|
14
|
+
s.add_development_dependency 'bundler', ['~> 1.8']
|
|
15
|
+
s.add_development_dependency 'rake', ['~> 10.4']
|
|
16
|
+
s.files = `git ls-files`.split($ORS)
|
|
17
|
+
s.test_files = s.files.grep(/^spec/)
|
|
18
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
describe FileParser do
|
|
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
|
+
Dir.chdir('../..')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_text(text)
|
|
16
|
+
File.open('foo.rb', 'w') { |f| f.puts text}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def stub_all
|
|
20
|
+
RStub.new.start('* target')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def expect_text(text)
|
|
24
|
+
expect(IO.read('target/foo.rb')).to eql(text)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'can add text without stubs' do
|
|
28
|
+
text = "foo\nbar\n"
|
|
29
|
+
add_text(text)
|
|
30
|
+
stub_all
|
|
31
|
+
expect_text("foo\nbar\n")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'stubs out stub delimiter' do
|
|
35
|
+
text = "# STUB\n"
|
|
36
|
+
add_text(text)
|
|
37
|
+
stub_all
|
|
38
|
+
expect_text('')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'preserves text before stub delimiter' do
|
|
42
|
+
text = "hello\n# STUB\n"
|
|
43
|
+
add_text(text)
|
|
44
|
+
stub_all
|
|
45
|
+
expect_text("hello\n")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'doesn\'t include endstub delimiter' do
|
|
49
|
+
text = "# STUB\n# ENDSTUB\n"
|
|
50
|
+
add_text(text)
|
|
51
|
+
stub_all
|
|
52
|
+
expect_text('')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'doesn\'t include text between stub delimiters' do
|
|
56
|
+
text = "# STUB\n hello # ENDSTUB\n"
|
|
57
|
+
add_text(text)
|
|
58
|
+
stub_all
|
|
59
|
+
expect_text('')
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'doesn\'t include text after the # STUB' do
|
|
63
|
+
text = "# STUB\n hello\n"
|
|
64
|
+
add_text(text)
|
|
65
|
+
stub_all
|
|
66
|
+
expect_text('')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'doesn\'t care about other stub starting delimiters after the first' do
|
|
70
|
+
text = "# STUB\n hello\n # STUB"
|
|
71
|
+
add_text(text)
|
|
72
|
+
stub_all
|
|
73
|
+
expect_text('')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'includes plain end stub delimiters' do
|
|
77
|
+
text = "# ENDSTUB\n"
|
|
78
|
+
add_text(text)
|
|
79
|
+
stub_all
|
|
80
|
+
expect_text("# ENDSTUB\n")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'resumes putting in text after end delimiter' do
|
|
84
|
+
text = "hello\n# STUB\nworld\n# ENDSTUB\nfoo\n"
|
|
85
|
+
add_text(text)
|
|
86
|
+
stub_all
|
|
87
|
+
expect_text("hello\nfoo\n")
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
describe PathParser do
|
|
2
|
+
before(:all) do
|
|
3
|
+
Dir.chdir('spec/fixtures')
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
after(:all) do
|
|
7
|
+
Dir.chdir('../..')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe '::directory?' do
|
|
11
|
+
it 'no file extension is directory' do
|
|
12
|
+
expect(PathParser.directory?('bar')).to be true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'file extension is file' do
|
|
16
|
+
expect(PathParser.directory?('foo.rb')).to be false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'detects hidden directories' do
|
|
20
|
+
expect(PathParser.directory?('.bar')).to be true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '#get_globs' do
|
|
25
|
+
let(:path_parser) { PathParser.new }
|
|
26
|
+
|
|
27
|
+
it 'returns the same array when there is no match' do
|
|
28
|
+
expect(path_parser.get_globs(['foo.rb'])[:files]).to match_array(['foo.rb'])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'returns glob matches from current directory' do
|
|
32
|
+
expect(path_parser.get_globs(['*']))
|
|
33
|
+
.to match_array({ directories: ['foobar'],
|
|
34
|
+
files: ['baz.rb', 'foo.rb', 'foobar/foobaz.rb']})
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'adds glob matches to the rest of the files' do
|
|
38
|
+
expect(path_parser.get_globs(['*', 'foo/bar.rb'])[:directories])
|
|
39
|
+
.to match_array(['foo', 'foobar'])
|
|
40
|
+
expect(path_parser.get_globs(['*', 'foo/bar.rb'])[:files])
|
|
41
|
+
.to match_array(['foo/bar.rb', 'baz.rb', 'foo.rb', 'foobar/foobaz.rb'])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'returns glob matches from lowel directory' do
|
|
45
|
+
expect(path_parser.get_globs(['*/*']))
|
|
46
|
+
.to match_array({ directories: ['foobar'],
|
|
47
|
+
files: ['foobar/foobaz.rb'] })
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/spec/rstub_spec.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
describe RStub do
|
|
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
|
+
let(:rstub) { RStub.new }
|
|
16
|
+
|
|
17
|
+
it 'creates the correct directory and file' do
|
|
18
|
+
rstub.start('foo.rb target')
|
|
19
|
+
expect(Dir.exist?('target')).to be true
|
|
20
|
+
expect(File.exist?('target/foo.rb')).to be true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'raises error with invalid number of arguments' do
|
|
24
|
+
expect{rstub.start}.to raise_error('Not enough arguments')
|
|
25
|
+
expect{rstub.start('foo')}.to raise_error('Not enough arguments')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'raises error if the last argument isn\'t a directory' do
|
|
29
|
+
expect{rstub.start('foo.rb baz.rb')}
|
|
30
|
+
.to raise_error('The last argument needs to be a directory')
|
|
31
|
+
expect{rstub.start('target foo.rb')}
|
|
32
|
+
.to raise_error('The last argument needs to be a directory')
|
|
33
|
+
expect{rstub.start('foo.rb *')}
|
|
34
|
+
.to raise_error('The last argument needs to be a directory')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'doesn\'t create files that aren\' already there but were passed in' do
|
|
38
|
+
rstub.start('bar.rb target')
|
|
39
|
+
expect(Dir.exist?('target')).to be true
|
|
40
|
+
expect(File.exist?('target/bar.rb')).to be false
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'adds multiple files to the directory' do
|
|
44
|
+
rstub.start('foo.rb baz.rb target')
|
|
45
|
+
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
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'doesn\'t add nonexistent files even when there are multiple files' do
|
|
51
|
+
rstub.start('foo.rb bar.rb target')
|
|
52
|
+
expect(Dir.exist?('target')).to be true
|
|
53
|
+
expect(File.exist?('target/foo.rb')).to be true
|
|
54
|
+
expect(File.exist?('target/bar.rb')).to be false
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'doesn\'t add nonexistent files even with wildcard' do
|
|
58
|
+
rstub.start('foo/* target')
|
|
59
|
+
expect(Dir.exist?('target')).to be true
|
|
60
|
+
expect(Dir.exist?('target/foo')).to be false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'all files are added with wildcard' do
|
|
64
|
+
rstub.start('* target')
|
|
65
|
+
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
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
data/spec/spec_helper.rb
ADDED
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.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Kim
|
|
@@ -9,7 +9,35 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 2015-05-30 00:00:00.000000000 Z
|
|
12
|
-
dependencies:
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.8'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.8'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.4'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.4'
|
|
13
41
|
description: A gem to stub out pieces of code
|
|
14
42
|
email:
|
|
15
43
|
- justinjmkim@gmail.com
|
|
@@ -18,8 +46,25 @@ executables:
|
|
|
18
46
|
extensions: []
|
|
19
47
|
extra_rdoc_files: []
|
|
20
48
|
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- ".rspec"
|
|
51
|
+
- ".travis.yml"
|
|
52
|
+
- Gemfile
|
|
53
|
+
- LICENSE
|
|
54
|
+
- README.md
|
|
55
|
+
- Rakefile
|
|
21
56
|
- bin/rstub
|
|
22
57
|
- lib/rstub.rb
|
|
58
|
+
- lib/rstub/file_parser.rb
|
|
59
|
+
- lib/rstub/path_parser.rb
|
|
60
|
+
- rstub.gemspec
|
|
61
|
+
- spec/file_parser_spec.rb
|
|
62
|
+
- spec/fixtures/baz.rb
|
|
63
|
+
- spec/fixtures/foo.rb
|
|
64
|
+
- spec/fixtures/foobar/foobaz.rb
|
|
65
|
+
- spec/path_parser_spec.rb
|
|
66
|
+
- spec/rstub_spec.rb
|
|
67
|
+
- spec/spec_helper.rb
|
|
23
68
|
homepage: https://github.com/jusjmkim/rstub
|
|
24
69
|
licenses:
|
|
25
70
|
- MIT
|
|
@@ -44,4 +89,11 @@ rubygems_version: 2.4.6
|
|
|
44
89
|
signing_key:
|
|
45
90
|
specification_version: 4
|
|
46
91
|
summary: A gem to stub out code
|
|
47
|
-
test_files:
|
|
92
|
+
test_files:
|
|
93
|
+
- spec/file_parser_spec.rb
|
|
94
|
+
- spec/fixtures/baz.rb
|
|
95
|
+
- spec/fixtures/foo.rb
|
|
96
|
+
- spec/fixtures/foobar/foobaz.rb
|
|
97
|
+
- spec/path_parser_spec.rb
|
|
98
|
+
- spec/rstub_spec.rb
|
|
99
|
+
- spec/spec_helper.rb
|