exegesis 0.0.3 → 0.0.4
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.
- data/CHANGELOG +6 -0
- data/lib/exegesis/file_searcher.rb +9 -4
- data/lib/exegesis/registerable.rb +0 -1
- data/lib/exegesis/source_file.rb +6 -3
- data/lib/exegesis/version.rb +1 -1
- data/spec/integration/flyweight_registerable_spec.rb +0 -6
- data/spec/unit/directory_spec.rb +0 -6
- data/spec/unit/file_searcher_spec.rb +26 -23
- data/spec/unit/flyweight_spec.rb +4 -10
- data/spec/unit/source_file_spec.rb +11 -12
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
= 0.0.3 - 0.0.4
|
2
|
+
* Make sure Forwardable gem dependency gets loaded at the appropriate
|
3
|
+
load-level
|
4
|
+
* Skirt a very rare crash during tests (happens _literally_ only to my one
|
5
|
+
computer) in rubinius 2.0.0rc1
|
6
|
+
* Internal Refactoring to avoid stubbing core classes like `File` and `Dir`
|
1
7
|
|
2
8
|
* 0.0.2
|
3
9
|
Large amount of functionality in place, including BaseDirectories,
|
@@ -19,18 +19,23 @@ class FileSearcher
|
|
19
19
|
# Create a new FileSearcher on the given path
|
20
20
|
#
|
21
21
|
# @param parent [Directory] the parent directory to search downward from
|
22
|
-
def initialize(parent)
|
22
|
+
def initialize(parent, fs_interface = File)
|
23
|
+
@fs_interface = fs_interface
|
23
24
|
@parent = parent
|
24
25
|
end
|
25
26
|
|
26
27
|
#All of the directories in the given path
|
27
28
|
def directories
|
28
|
-
content.
|
29
|
+
content.
|
30
|
+
select { |s| fs_interface.directory?(s) }.
|
31
|
+
map { |s| Directory.create(parent, fs_interface.basename(s)) }
|
29
32
|
end
|
30
33
|
|
31
34
|
#All of the files in the given path
|
32
35
|
def files
|
33
|
-
content.
|
36
|
+
content.
|
37
|
+
select { |s| fs_interface.file?(s) }.
|
38
|
+
map { |s| SourceFile.create(parent, fs_interface.basename(s)) }
|
34
39
|
end
|
35
40
|
|
36
41
|
#All of the content from the given path
|
@@ -44,5 +49,5 @@ class FileSearcher
|
|
44
49
|
|
45
50
|
private
|
46
51
|
|
47
|
-
attr_reader :parent
|
52
|
+
attr_reader :parent, :fs_interface
|
48
53
|
end
|
data/lib/exegesis/source_file.rb
CHANGED
@@ -21,7 +21,7 @@ class SourceFile
|
|
21
21
|
include FileSystemEntity
|
22
22
|
|
23
23
|
def content
|
24
|
-
|
24
|
+
fs_interface.read(path)
|
25
25
|
end
|
26
26
|
|
27
27
|
attr_reader :dependencies
|
@@ -32,14 +32,17 @@ class SourceFile
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
def initialize(parent, name)
|
35
|
+
def initialize(parent, name, fs_interface = File)
|
36
36
|
raise ArgumentError, "parent must be a directory" unless parent.is_a?(Directory)
|
37
37
|
|
38
|
-
@
|
38
|
+
@fs_interface = fs_interface
|
39
|
+
@ext = fs_interface.extname(name)
|
39
40
|
@name = name
|
40
41
|
@parent = parent
|
41
42
|
@dependencies = []
|
42
43
|
end
|
44
|
+
|
45
|
+
attr_reader :fs_interface
|
43
46
|
end
|
44
47
|
|
45
48
|
class InvalidDependency < StandardError ; end
|
data/lib/exegesis/version.rb
CHANGED
@@ -47,12 +47,6 @@ describe Flyweight, "mixin", "other objects" do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe 'instantiation' do
|
51
|
-
it 'disallows instantiation via #new' do
|
52
|
-
expect { Example.new(parent, 'n') }.to raise_error NoMethodError
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
50
|
describe 'creating a new instance' do
|
57
51
|
subject { Example.create(parent, 'n') }
|
58
52
|
end
|
data/spec/unit/directory_spec.rb
CHANGED
@@ -16,12 +16,6 @@ describe Directory do
|
|
16
16
|
|
17
17
|
subject { directory }
|
18
18
|
|
19
|
-
describe 'instantiation' do
|
20
|
-
it 'disallows instantiation via #new' do
|
21
|
-
expect { Directory.new(parent, name, searcher) }.to raise_error NoMethodError
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
19
|
describe 'api' do
|
26
20
|
it { should respond_to :directories }
|
27
21
|
it { should respond_to :parent }
|
@@ -1,30 +1,31 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
|
3
3
|
describe FileSearcher do
|
4
|
-
let (:root) { double('a fake backend')
|
5
|
-
let (:root_path) { double('a fake path')
|
6
|
-
let (:globbed_path) { double('a fake glob of root_path with *')
|
7
|
-
let (:
|
8
|
-
let (:
|
9
|
-
let (:
|
10
|
-
let (:
|
11
|
-
let (:
|
4
|
+
let (:root) { double('a fake backend') }
|
5
|
+
let (:root_path) { double('a fake path') }
|
6
|
+
let (:globbed_path) { double('a fake glob of root_path with *') }
|
7
|
+
let (:fs_interface) { double('a File System Interface like `File`') }
|
8
|
+
let (:file_searcher) { FileSearcher.new(root, fs_interface) }
|
9
|
+
let (:dir) { double('a fake directory') }
|
10
|
+
let (:file) { double('a fake file') }
|
11
|
+
let (:file_path) { double('the fake file path') }
|
12
|
+
let (:dir_path) { double('the directory file path') }
|
12
13
|
|
13
14
|
let (:fake_source_file_instance) { double('a fake SourceFile instance') }
|
14
15
|
let (:fake_directory_instance) { double('a fake Directory instance') }
|
15
16
|
|
16
17
|
before do
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
fs_interface.stub(:directory?).with(dir).and_return(true)
|
19
|
+
fs_interface.stub(:file?).with(dir).and_return(false)
|
20
|
+
fs_interface.stub(:basename).with(dir).and_return(dir)
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
fs_interface.stub(:directory?).with(file).and_return(false)
|
23
|
+
fs_interface.stub(:file?).with(file).and_return(true)
|
24
|
+
fs_interface.stub(:basename).with(file).and_return(file)
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
fs_interface.stub(:join).with(root_path, '*').and_return(globbed_path)
|
27
|
+
fs_interface.stub(:join).with(root_path, file).and_return(file_path)
|
28
|
+
fs_interface.stub(:join).with(root_path, dir).and_return(dir_path)
|
28
29
|
|
29
30
|
Directory.stub(:new).with(root, dir).and_return(fake_directory_instance)
|
30
31
|
SourceFile.stub(:new).with(root, file).and_return(fake_source_file_instance)
|
@@ -43,13 +44,15 @@ describe FileSearcher do
|
|
43
44
|
it { should respond_to :content }
|
44
45
|
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
pending "better dependency injection" do
|
48
|
+
describe '#content' do
|
49
|
+
before do
|
50
|
+
Dir.stub(:[])
|
51
|
+
file_searcher.content
|
52
|
+
end
|
51
53
|
|
52
|
-
|
54
|
+
the(Dir) { should have_received(:[]).with(globbed_path) }
|
55
|
+
end
|
53
56
|
end
|
54
57
|
|
55
58
|
context do
|
data/spec/unit/flyweight_spec.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
|
3
3
|
describe Flyweight do
|
4
|
-
let (:processor) { proc { instance_key }
|
5
|
-
let (:flyweight) { Flyweight.new(&processor)
|
6
|
-
let (:instance) { double('instance')
|
7
|
-
let (:instance_key) { double('instance_key')
|
4
|
+
let (:processor) { proc { |instance| instance_key } }
|
5
|
+
let (:flyweight) { Flyweight.new(&processor) }
|
6
|
+
let (:instance) { double('instance') }
|
7
|
+
let (:instance_key) { double('instance_key') }
|
8
8
|
|
9
9
|
subject { flyweight }
|
10
10
|
|
11
|
-
before do
|
12
|
-
processor.stub(:call).and_return(instance_key)
|
13
|
-
end
|
14
|
-
|
15
11
|
context 'shared examples' do
|
16
12
|
shared_examples_for 'flyweight unregistration' do
|
17
13
|
before { flyweight.unregister!(key) }
|
@@ -48,8 +44,6 @@ describe Flyweight do
|
|
48
44
|
before { flyweight.register!(instance) }
|
49
45
|
|
50
46
|
describe '#register! and #register' do
|
51
|
-
the(:processor) { should have_received(:call).with(instance) }
|
52
|
-
|
53
47
|
describe 'registering an instance with an already-used key' do
|
54
48
|
it 'raises an error' do
|
55
49
|
expect { flyweight.register!(instance) }.to raise_error Flyweight::AlreadyRegisteredError
|
@@ -1,28 +1,27 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
|
3
3
|
describe SourceFile do
|
4
|
-
let(:basename)
|
5
|
-
let(:extension)
|
6
|
-
let(:name)
|
7
|
-
let(:parent)
|
4
|
+
let(:basename) { 'fake' }
|
5
|
+
let(:extension) { '.c' }
|
6
|
+
let(:name) { basename + extension }
|
7
|
+
let(:parent) { double('directory') }
|
8
|
+
let(:fs_interface) { double('an arbitrary interface to a filesystem') }
|
8
9
|
|
10
|
+
# TODO: Eliminate use of File here? More mocks?
|
9
11
|
let(:full_path) { File.join(parent.path, name) }
|
10
12
|
let(:content) { double('content') }
|
11
13
|
|
12
|
-
let(:source_file) { SourceFile.create(parent, name) }
|
14
|
+
let(:source_file) { SourceFile.create(parent, name, fs_interface) }
|
15
|
+
|
13
16
|
|
14
17
|
subject { source_file }
|
15
18
|
|
16
19
|
before do
|
17
20
|
parent.stub(:path).and_return('/path/to/parent/')
|
18
21
|
parent.stub(:is_a?).with(Directory).and_return(true)
|
19
|
-
File.stub(:read).with(full_path).and_return(content)
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
expect { SourceFile.new(parent, name) }.to raise_error NoMethodError
|
25
|
-
end
|
23
|
+
fs_interface.stub(:read).with(full_path).and_return(content)
|
24
|
+
fs_interface.stub(:extname).with(name).and_return(extension)
|
26
25
|
end
|
27
26
|
|
28
27
|
describe 'api' do
|
@@ -91,7 +90,7 @@ describe SourceFile do
|
|
91
90
|
describe '#content' do
|
92
91
|
before { source_file.content }
|
93
92
|
|
94
|
-
|
93
|
+
the(:fs_interface) { should have_received(:read).with(full_path) }
|
95
94
|
end
|
96
95
|
|
97
96
|
describe '#dependencies' do
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: exegesis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joe Fredette
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
type: :runtime
|