binder_core 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.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.markdown +86 -0
- data/Rakefile +1 -0
- data/binder_core.gemspec +24 -0
- data/lib/binder_core/asset.rb +45 -0
- data/lib/binder_core/binder.rb +26 -0
- data/lib/binder_core/compiler.rb +97 -0
- data/lib/binder_core/config.rb +98 -0
- data/lib/binder_core/console.rb +63 -0
- data/lib/binder_core/debug/stack.rb +86 -0
- data/lib/binder_core/defaults.rb +42 -0
- data/lib/binder_core/definition.rb +12 -0
- data/lib/binder_core/file_context.rb +46 -0
- data/lib/binder_core/file_ref.rb +38 -0
- data/lib/binder_core/folder_context.rb +55 -0
- data/lib/binder_core/parser.rb +82 -0
- data/lib/binder_core/parsers/asset_parser.rb +7 -0
- data/lib/binder_core/parsers/folder_parser.rb +7 -0
- data/lib/binder_core/parsers/null_parser.rb +6 -0
- data/lib/binder_core/parsers/text_parser.rb +11 -0
- data/lib/binder_core/registry.rb +45 -0
- data/lib/binder_core/scanner.rb +36 -0
- data/lib/binder_core/settings.rb +23 -0
- data/lib/binder_core/version.rb +3 -0
- data/lib/binder_core.rb +44 -0
- data/spec/binder_core/asset_spec.rb +64 -0
- data/spec/binder_core/binder_spec.rb +48 -0
- data/spec/binder_core/compiler_spec.rb +132 -0
- data/spec/binder_core/config_spec.rb +146 -0
- data/spec/binder_core/console_spec.rb +60 -0
- data/spec/binder_core/debug/stack_spec.rb +90 -0
- data/spec/binder_core/defaults_spec.rb +43 -0
- data/spec/binder_core/definition_spec.rb +20 -0
- data/spec/binder_core/file_context_spec.rb +79 -0
- data/spec/binder_core/file_ref_spec.rb +43 -0
- data/spec/binder_core/folder_context_spec.rb +104 -0
- data/spec/binder_core/parser_spec.rb +72 -0
- data/spec/binder_core/parsers/asset_parser_spec.rb +14 -0
- data/spec/binder_core/parsers/folder_parser_spec.rb +15 -0
- data/spec/binder_core/parsers/null_parser_spec.rb +9 -0
- data/spec/binder_core/parsers/text_parser_spec.rb +16 -0
- data/spec/binder_core/registry_spec.rb +61 -0
- data/spec/binder_core/scanner_spec.rb +79 -0
- data/spec/binder_core/settings_spec.rb +32 -0
- data/spec/binder_core_spec.rb +87 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/content/test/_hidden_file.txt +1 -0
- data/spec/support/content/test/_hidden_folder/childofhiddenfolder.txt +1 -0
- data/spec/support/content/test/emptyfolder/_ignore.txt +1 -0
- data/spec/support/content/test/logo.png +0 -0
- data/spec/support/content/test/subfolder/subtext.txt +1 -0
- data/spec/support/content/test/testfile.txt +5 -0
- data/spec/support/content/test/unknown.tmp +1 -0
- data/spec/support/parsers/test_parsers.rb +20 -0
- metadata +147 -0
@@ -0,0 +1,146 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BinderCore::Config do
|
4
|
+
describe "setter methods" do
|
5
|
+
let(:context) { BinderCore::FolderContext.new }
|
6
|
+
let(:config) { BinderCore::Config.new context }
|
7
|
+
let(:mockcontext) { double("ContextMock") }
|
8
|
+
|
9
|
+
it "should set the path of the contexts dir object" do
|
10
|
+
config.set_path BINDER_DEFAULT_DIR
|
11
|
+
context.file.path.should === BINDER_DEFAULT_DIR
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should add an array of definitions to its rules collection" do
|
15
|
+
context.rules.should == []
|
16
|
+
context.rules = [1,2,3]
|
17
|
+
config.set_rules [4,5,6]
|
18
|
+
context.rules.should == [1,2,3,4,5,6]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should add an array of definitions to its parsers collection" do
|
22
|
+
context.parsers.should == []
|
23
|
+
context.parsers = [1,2,3]
|
24
|
+
config.set_parsers [4,5,6]
|
25
|
+
context.parsers.should == [1,2,3,4,5,6]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create a definition, add it to the front of the parser list and return it" do
|
29
|
+
config.set_parsers []
|
30
|
+
Parsr = Class.new
|
31
|
+
defn = config.add_parser Parsr do |fcnxt|
|
32
|
+
true
|
33
|
+
end
|
34
|
+
context.parsers.first.should == defn
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should create a definition, add it to the front of the rule list and return it" do
|
38
|
+
config.set_rules []
|
39
|
+
Parsr = Class.new
|
40
|
+
defn = config.add_rule Parsr do |fcnxt|
|
41
|
+
true
|
42
|
+
end
|
43
|
+
context.rules.first.should == defn
|
44
|
+
end
|
45
|
+
|
46
|
+
# the route needs to get passed in from the parent
|
47
|
+
## If there is no extension how are we going to deal with files of the same names but different
|
48
|
+
## extensions. (replace dot in extension with undescore? I think leaving the dot in is not a good idea)
|
49
|
+
|
50
|
+
it "should add and configure the route array" do
|
51
|
+
config.set_route ["test"]
|
52
|
+
context.route.should == ["test"]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should add a blank data object to the context object" do
|
56
|
+
data = {}
|
57
|
+
config.set_data data
|
58
|
+
context.data.should === data
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should set an array as asset to the context object" do
|
62
|
+
assets = []
|
63
|
+
config.set_assets assets
|
64
|
+
context.assets.should === assets
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should set the console" do
|
68
|
+
console = double("Console")
|
69
|
+
context.should_receive(:console=).with(console)
|
70
|
+
config.set_console console
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should add a params to the params object without over-writing it" do
|
74
|
+
config.add_params :test => "value"
|
75
|
+
config.add_params :test2 => "value2"
|
76
|
+
config.params[:test3] = "value3"
|
77
|
+
config.params.should == {:test => "value", :test2 => "value2", :test3 => "value3"}
|
78
|
+
context.params.should == {:test => "value", :test2 => "value2", :test3 => "value3"}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
describe "#verify_context" do
|
84
|
+
let(:file) { double("FileMock", :path => "some/path/", ) }
|
85
|
+
let(:context) { double("FileContextMock", :file => file) }
|
86
|
+
let(:console) { BinderCore::Console.new double("SettingsMock").as_null_object }
|
87
|
+
let(:config) { BinderCore::Config.new context }
|
88
|
+
|
89
|
+
before(:each) do
|
90
|
+
context.should_receive(:console=).with(console)
|
91
|
+
config.set_console console
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should raise an error when content does not validate" do
|
95
|
+
expect { config.verify_context }.to raise_error(BinderCore::InvalidContextError)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should provide detailed error message when the context does not validate" do
|
99
|
+
expect { config.verify_context }.to raise_error(BinderCore::InvalidContextError,"Invalid file at path:some/path/")
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#valid_file?" do
|
103
|
+
it "should accept a valid file/folder" do
|
104
|
+
console.should_receive(:defaults).with(:folder_size_limit_mb).and_return(100)
|
105
|
+
config.send( :valid_file?, BINDER_DEFAULT_DIR)#.should be_true
|
106
|
+
console.errors.should == []
|
107
|
+
console.continue?.should be_true
|
108
|
+
end
|
109
|
+
it "should reject a non-existent file/folder" do
|
110
|
+
path = "/path/to/non/existent/folder/"
|
111
|
+
config.send( :valid_file?, path).should be_false
|
112
|
+
console.errors[0][:message].should == "File path:#{path} does not exist"""
|
113
|
+
console.continue?.should be_false
|
114
|
+
end
|
115
|
+
it "should reject a file/folder you do not have permission to access" do
|
116
|
+
unreadable_file_path = "/var/root"
|
117
|
+
if !File.exists?(unreadable_file_path)
|
118
|
+
raise "This test will not run on your system, change '/var/root' to an unreadable folder or file on YOUR system"
|
119
|
+
end
|
120
|
+
config.send( :valid_file?, unreadable_file_path ).should be_false
|
121
|
+
console.errors[0][:message].should == "You do not have permission to access the file at path:#{unreadable_file_path}"
|
122
|
+
console.continue?.should be_false
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should ensure the folder overall size is not larger than the max size" do
|
126
|
+
path = BINDER_DEFAULT_DIR
|
127
|
+
console.should_receive(:defaults).with(:folder_size_limit_mb).and_return(100)
|
128
|
+
config.send( :valid_file?, path).should be_true
|
129
|
+
console.should_receive(:defaults).with(:folder_size_limit_mb).and_return(0.001)
|
130
|
+
config.send( :valid_file?, path).should be_false
|
131
|
+
console.errors[0][:message].should == "File contents at path:#{path} is larger then the limit of 0.001MB"
|
132
|
+
console.continue?.should be_false
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#file_within_size_limit?" do
|
137
|
+
it "should return true for 5000 bytes" do
|
138
|
+
config.send(:file_within_size_limit?, 5000, BINDER_DEFAULT_DIR).should be_true
|
139
|
+
end
|
140
|
+
it "should return false for 1000 bytes" do
|
141
|
+
config.send(:file_within_size_limit?, 1000, BINDER_DEFAULT_DIR).should be_false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BinderCore::Console do
|
4
|
+
let(:asset_url) { "http://www.example.com/" }
|
5
|
+
let(:content_folder) { "/path/to/content/folder/" }
|
6
|
+
let(:settings) do
|
7
|
+
c = BinderCore::Settings::Config.new
|
8
|
+
c.base_asset_url = asset_url
|
9
|
+
c.content_folder = content_folder
|
10
|
+
c.folder_size_limit_mb = 100
|
11
|
+
c
|
12
|
+
end
|
13
|
+
let(:console) { BinderCore::Console.new settings }
|
14
|
+
|
15
|
+
# get/set defaults
|
16
|
+
it "should provide access to default values through default method" do
|
17
|
+
console.defaults( :base_asset_url ).should == asset_url
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should allow a default property be updated by passing a hash to the default method" do
|
21
|
+
newurl = "http://example.com/binder/"
|
22
|
+
newpath = "/new/path/to/content/"
|
23
|
+
console.defaults :base_asset_url => newurl,
|
24
|
+
:content_folder => newpath
|
25
|
+
|
26
|
+
console.defaults( :base_asset_url ).should == newurl
|
27
|
+
console.defaults( :content_folder ).should == newpath
|
28
|
+
end
|
29
|
+
|
30
|
+
# log message
|
31
|
+
it "should add to the log when .log is called with a param and return the log array when no params" do
|
32
|
+
console.log "log"
|
33
|
+
console.log "captains"
|
34
|
+
console.log.should == ["captains","log"]
|
35
|
+
end
|
36
|
+
|
37
|
+
# log warning
|
38
|
+
it "should add to the warning log and return the warnings log array" do
|
39
|
+
console.warnings.should == []
|
40
|
+
console.warn "now"
|
41
|
+
console.warn "careful"
|
42
|
+
console.warnings.should == ["careful","now"]
|
43
|
+
end
|
44
|
+
|
45
|
+
# log error and stop process
|
46
|
+
it "should log and error and change continue? to false" do
|
47
|
+
console.continue?.should be_true
|
48
|
+
console.errors.should == []
|
49
|
+
console.error "oh crap!"
|
50
|
+
console.errors.should == [ :message => "oh crap!",:stack => [] ]
|
51
|
+
console.continue?.should be_false
|
52
|
+
end
|
53
|
+
|
54
|
+
# stack object > add, trace, clear
|
55
|
+
it "shoud have a stack object" do
|
56
|
+
console.stack.should be_kind_of BinderCore::Debug::Stack
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BinderCore::Debug::Stack do
|
4
|
+
let(:stack) { BinderCore::Debug::Stack.new }
|
5
|
+
let(:route) { ["example","route"] }
|
6
|
+
let(:path) { "arbitary/path/to/file/or/folder" }
|
7
|
+
let(:file_ref) { double("FileRef", :path => path) }
|
8
|
+
let(:folder) { double("FolderContext", :file => file_ref, :class => "FolderContext" ) }
|
9
|
+
let(:file) { double("FileContext", :file => file_ref, :class => "FileContext" ) }
|
10
|
+
let(:parser) { double("Parser", :file => file_ref, :class => "Parser" ) }
|
11
|
+
|
12
|
+
describe "creating entries from folder, file and parser objects" do
|
13
|
+
it "should add a folder, file and parser and return a configured entry object" do
|
14
|
+
def test_entry(e,cl)
|
15
|
+
e.route.should == route
|
16
|
+
e.file_path.should == path
|
17
|
+
e.class_name.should == cl
|
18
|
+
end
|
19
|
+
|
20
|
+
entry = stack.add_folder route, folder
|
21
|
+
test_entry entry, "FolderContext"
|
22
|
+
entry = stack.add_file route, file
|
23
|
+
test_entry entry, "FileContext"
|
24
|
+
entry = stack.add_file route, parser
|
25
|
+
test_entry entry, "Parser"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#trace" do
|
30
|
+
before(:each) do
|
31
|
+
cur_rt = []
|
32
|
+
["a","b"].each do |e|
|
33
|
+
cur_rt << e
|
34
|
+
stack.add_folder cur_rt, folder
|
35
|
+
stack.add_file cur_rt, file
|
36
|
+
stack.add_parser cur_rt, parser
|
37
|
+
end
|
38
|
+
cur_rt = ["a","c"]
|
39
|
+
stack.add_folder cur_rt, folder
|
40
|
+
stack.add_file cur_rt, file
|
41
|
+
stack.add_parser cur_rt, parser
|
42
|
+
|
43
|
+
@trace = stack.trace
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should provide a stack trace of the right length" do
|
47
|
+
@trace.length.should == 6
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should order them most recent first" do
|
51
|
+
# first check the routes are in the correct order
|
52
|
+
@trace.slice(0,3).each { |e| e.route.should == ["a","c"] }
|
53
|
+
@trace.slice(3,3).each { |e| e.route.should == ["a"] }
|
54
|
+
# now check the classes
|
55
|
+
class_order = [parser.class, file.class, folder.class]
|
56
|
+
count = 0
|
57
|
+
@trace.each do |e|
|
58
|
+
e.class_name.should == class_order[ count%class_order.length ]
|
59
|
+
count += 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe BinderCore::Debug::Stack::Entry do
|
66
|
+
let(:entry) { BinderCore::Debug::Stack::Entry.new }
|
67
|
+
|
68
|
+
context "has required properties" do
|
69
|
+
subject { entry }
|
70
|
+
it { should respond_to(:route) }
|
71
|
+
it { should respond_to(:file_path) }
|
72
|
+
it { should respond_to(:class_name) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "formating for display" do
|
76
|
+
let(:route) { ["example","work","gallery"] }
|
77
|
+
let(:path) { "/path/to/some/file" }
|
78
|
+
let(:clname) { "BinderCore::FileContext" }
|
79
|
+
|
80
|
+
before(:each) do
|
81
|
+
entry.route = route
|
82
|
+
entry.file_path = path
|
83
|
+
entry.class_name = clname
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should override to_s with pretty output" do
|
87
|
+
entry.to_s.should == "#{clname} at route:(#{route.join(',')}) to file:#{path}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BinderCore::Default do
|
4
|
+
describe "#settings" do
|
5
|
+
it "should set the default values to all the settings" do
|
6
|
+
config = double("MockConfig")
|
7
|
+
BinderCore::Settings.should_receive(:config).exactly(4).times.and_return(config)
|
8
|
+
config.should_receive(:base_asset_folder=).with("")
|
9
|
+
config.should_receive(:base_asset_url=).with("")
|
10
|
+
config.should_receive(:content_folder=).with("")
|
11
|
+
config.should_receive(:folder_size_limit_mb=).with(100)
|
12
|
+
BinderCore::Default.settings
|
13
|
+
end
|
14
|
+
end
|
15
|
+
describe "#config" do
|
16
|
+
let(:config) { double("ContextConfig").as_null_object }
|
17
|
+
let(:config_proc) { BinderCore::Default.config}
|
18
|
+
|
19
|
+
after(:each) do
|
20
|
+
config_proc.call( config )
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should add a null parser object" do
|
24
|
+
config.should_receive(:add_parser).with(BinderCore::NullParser)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should add a text parser object" do
|
28
|
+
config.should_receive(:add_parser).with(BinderCore::TextParser)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should add a folder parser object" do
|
32
|
+
config.should_receive(:add_parser).with(BinderCore::FolderParser)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should add an asset parser object for images" do
|
36
|
+
config.should_receive(:add_parser).with(BinderCore::AssetParser)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should add a null parser object for files to be skipped" do
|
40
|
+
config.should_receive(:add_rule).with(BinderCore::NullParser)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BinderCore::Definition do
|
4
|
+
let(:klass) { Class.new }
|
5
|
+
let(:test) { lambda { |context| true } }
|
6
|
+
let(:definition) { BinderCore::Definition.new klass, test }
|
7
|
+
|
8
|
+
it "should have a test method" do
|
9
|
+
definition.should respond_to(:test)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return a the Class from the test method, since the test returned true" do
|
13
|
+
definition.test(nil).should == klass
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return nothing if the test proc eval'd to false" do
|
17
|
+
defn = BinderCore::Definition.new klass, lambda { |context| false }
|
18
|
+
defn.test(nil).should be_nil
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BinderCore::FileContext do
|
4
|
+
|
5
|
+
let(:raw) { {:data => {:test => "value"}, :assets => {"work/gallery/image_1" => "pathto/image.jpg"}} }
|
6
|
+
let(:context) do
|
7
|
+
BinderCore::FileContext.new
|
8
|
+
end
|
9
|
+
let(:defaults) { {:base_asset_url => ASSET_BASE_URL } }
|
10
|
+
let(:console) { double("ConsoleMock" ).as_null_object }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
context.file = BinderCore::FileRef.new File.join( BINDER_DEFAULT_DIR,"work", "gallery", "image.jpg")
|
14
|
+
context.route = %w{work gallery}
|
15
|
+
context.console = console
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have a data property which is nil by default" do
|
19
|
+
context.should respond_to(:data)
|
20
|
+
context.data.should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have an empty array for assets by default" do
|
24
|
+
context.assets.should == []
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should descent with a config block and call correct methods on the config class" do
|
28
|
+
cnfg = double("FolderConfig")
|
29
|
+
context.rules = ["rules"]
|
30
|
+
context.parsers = ["parsers"]
|
31
|
+
BinderCore::Scanner.should_receive(:descend) do |config|
|
32
|
+
config.call(cnfg)
|
33
|
+
raw
|
34
|
+
end
|
35
|
+
cnfg.should_receive(:set_rules).with(["rules"]).ordered
|
36
|
+
cnfg.should_receive(:set_parsers).with(["parsers"]).ordered
|
37
|
+
cnfg.should_receive(:set_assets).with([]).ordered
|
38
|
+
cnfg.should_receive(:set_console).with(console).ordered
|
39
|
+
cnfg.should_receive(:add_params).with({}).ordered
|
40
|
+
cnfg.should_receive(:set_path).with(context.file.path).ordered
|
41
|
+
cnfg.should_receive(:set_route).with(context.route.dup << context.file.name).ordered
|
42
|
+
cnfg.should_receive(:test).with("test").ordered
|
43
|
+
cnfg.should_receive(:verify_context).ordered
|
44
|
+
resp = context.descend { |config| config.test "test" }
|
45
|
+
resp.should == raw
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should pass its assets array on through the config object for population" do
|
49
|
+
cnfg = double("FolderConfig").as_null_object
|
50
|
+
BinderCore::Scanner.should_receive(:descend) do |config|
|
51
|
+
config.call(cnfg)
|
52
|
+
raw
|
53
|
+
end
|
54
|
+
cnfg.should_receive(:set_assets) do |arr|
|
55
|
+
arr << "test"
|
56
|
+
end
|
57
|
+
context.descend { |c| }
|
58
|
+
context.assets.should == ["test"]
|
59
|
+
end
|
60
|
+
context "when registering an asset" do
|
61
|
+
let(:path) { "pathto/image.jpg" }
|
62
|
+
let(:name) { "image" }
|
63
|
+
let(:feed_path) { "#{context.route.join('/')}/#{name}" }
|
64
|
+
let(:asset) { asset = BinderCore::Asset.new path }
|
65
|
+
|
66
|
+
it "should register an asset" do
|
67
|
+
context.register_asset( asset ).feed_path.should == feed_path
|
68
|
+
context.assets.should include asset
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should configure an asset" do
|
72
|
+
console.should_receive(:defaults) { |prop| defaults[prop] }
|
73
|
+
asset.should_receive(:route=).with(context.route)
|
74
|
+
asset.should_receive(:base_url=).with(defaults[:base_asset_url])
|
75
|
+
|
76
|
+
context.register_asset( asset )
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BinderCore::FileRef do
|
4
|
+
|
5
|
+
describe "instance methods" do
|
6
|
+
let(:filename) { "testfile" }
|
7
|
+
let(:ext) { ".txt" }
|
8
|
+
let(:path) { File.join( BINDER_DEFAULT_DIR, "test", "#{filename}#{ext}" ) }
|
9
|
+
let(:file) { BinderCore::FileRef.new path }
|
10
|
+
|
11
|
+
it "should have a path property set to path" do
|
12
|
+
file.path.should == path
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have a name of 'file'" do
|
16
|
+
file.name.should == filename
|
17
|
+
end
|
18
|
+
|
19
|
+
it "shoudl have a full_name wiht the file name including the extension" do
|
20
|
+
file.full_name.should == filename+ext
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have an extension of '.txt'" do
|
24
|
+
file.ext.should == ext
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should show it is not a directory" do
|
28
|
+
file.dir?.should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should show the current directory as a directory" do
|
32
|
+
file.path = BINDER_DEFAULT_DIR
|
33
|
+
file.dir?.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should provide an array of files contained within, empty array if none or file is not a directory" do
|
37
|
+
file.files.should == []
|
38
|
+
file.path = BINDER_DEFAULT_DIR
|
39
|
+
file.files.length.should == 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "support/parsers/test_parsers"
|
3
|
+
|
4
|
+
describe BinderCore::FolderContext do
|
5
|
+
describe "Initialization" do
|
6
|
+
context "properties" do
|
7
|
+
subject { BinderCore::FolderContext.new }
|
8
|
+
it { should respond_to(:parsers) }
|
9
|
+
it { should respond_to(:rules) }
|
10
|
+
it { should respond_to(:assets) }
|
11
|
+
it { subject.assets.should == [] }
|
12
|
+
it { should respond_to(:console) }
|
13
|
+
it { should respond_to(:console=) }
|
14
|
+
it { should respond_to(:data) }
|
15
|
+
it { subject.data.should be_nil }
|
16
|
+
it { should respond_to(:route) }
|
17
|
+
it { subject.route.should == [] }
|
18
|
+
it { should respond_to(:params) }
|
19
|
+
it { subject.params.should == {} }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "present its data" do
|
23
|
+
let(:context) { BinderCore::FolderContext.new }
|
24
|
+
it "should provide a native hash with data and assets through the raw method" do
|
25
|
+
context.data = data = {:test => "hash"}
|
26
|
+
context.assets = assets = []
|
27
|
+
context.raw[:data].should == data
|
28
|
+
context.raw[:assets].should == assets
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should expand array values in a hash which have only one member" do
|
32
|
+
hash = {:key => ["value"], :key2 => ["value", "value2"]}
|
33
|
+
context.send(:expand_single_keys, hash).should == {:key => "value", :key2 => ["value", "value2"]}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe "Parsing Folder Files" do
|
38
|
+
let(:context) { BinderCore::FolderContext.new }
|
39
|
+
let(:file_list) { ["test.txt"] }
|
40
|
+
let(:file) { double("FileRefMock", :files => file_list, :path => "some/path", ) }
|
41
|
+
let(:console) { double("ConsoleMock", :continue? => true) }
|
42
|
+
let(:file_context) { double("MockFileContext").as_null_object }
|
43
|
+
|
44
|
+
before(:each) do
|
45
|
+
context.file = file
|
46
|
+
context.console = console
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should iterate through files" do
|
50
|
+
files = double("MockFilesList")
|
51
|
+
file.should_receive(:files).and_return(files)
|
52
|
+
files.should_receive(:each)
|
53
|
+
context.parse_files
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should stop loop if console.continue? flag is false" do
|
57
|
+
file.should_receive(:files).and_return(["test.txt", "test2.txt"])
|
58
|
+
BinderCore::Scanner.should_receive(:scan).at_least(:once).and_return(file_context)
|
59
|
+
console.should_receive(:continue?).twice.and_return( true )
|
60
|
+
context.parse_files
|
61
|
+
console.should_receive(:continue?).once.and_return( false )
|
62
|
+
context.parse_files
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should create a config proc and pass it to the scanner" do
|
66
|
+
config = double("ConfigMock")
|
67
|
+
|
68
|
+
config.should_receive(:set_route).with([])
|
69
|
+
config.should_receive(:set_path).with(File.join(file.path,"test.txt"))
|
70
|
+
config.should_receive(:add_params).with({})
|
71
|
+
config.should_receive(:set_console).with(console)
|
72
|
+
config.should_receive(:set_rules).with([])
|
73
|
+
config.should_receive(:set_parsers).with([])
|
74
|
+
config.should_receive(:set_assets).with([])
|
75
|
+
config.should_receive(:verify_context)
|
76
|
+
|
77
|
+
BinderCore::Scanner.should_receive(:scan) do |cbl|
|
78
|
+
cbl.call config
|
79
|
+
context
|
80
|
+
end
|
81
|
+
context.parse_files
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should add data from the returned parsed file context" do
|
85
|
+
context.should_receive(:add_data_from).with(file_context)
|
86
|
+
file_context.should_receive(:data).and_return({})
|
87
|
+
BinderCore::Scanner.should_receive(:scan).and_return(file_context)
|
88
|
+
context.parse_files
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should call expand single keys with the data hash once the file loop has completed" do
|
92
|
+
file.should_receive(:files).and_return([])
|
93
|
+
context.data = {}
|
94
|
+
context.should_receive(:expand_single_keys).once
|
95
|
+
context.parse_files
|
96
|
+
end
|
97
|
+
it "should return the raw data at the end" do
|
98
|
+
file.should_receive(:files).and_return([])
|
99
|
+
context.data = {:key => "value", }
|
100
|
+
context.assets = ["assets"]
|
101
|
+
context.parse_files.should == {:data => {:key => "value"}, :assets => ["assets"] }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BinderCore::Parser do
|
4
|
+
let(:context) { double( "FileContext" ).as_null_object}
|
5
|
+
let(:parser) { BinderCore::Parser.new context }
|
6
|
+
|
7
|
+
it "should add data to the File Context" do
|
8
|
+
fdata = "test_content"
|
9
|
+
context.should_receive(:data=).with(fdata)
|
10
|
+
parser.add fdata
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set the data key value when a second arg is sent to the add method" do
|
14
|
+
fdata = "test_value"
|
15
|
+
fkey = "test_key"
|
16
|
+
context.should_receive(:name=).with(fkey)
|
17
|
+
context.should_receive(:data=).with(fdata)
|
18
|
+
parser.add fdata, fkey
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should set the name of the context when key= is called" do
|
22
|
+
context.should_receive(:name=).with("key")
|
23
|
+
parser.key = "key"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should provide access to the context file reference through the file method" do
|
27
|
+
context.should_receive(:file)
|
28
|
+
parser.file
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have access to a params hash" do
|
32
|
+
context.should_receive(:params).and_return({:test => "test_value"})
|
33
|
+
parser.params[:test].should == "test_value"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "shoule have access to the context console" do
|
37
|
+
context.console = double("MockConsole")
|
38
|
+
parser.console.should == context.console
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create a new asset" do
|
42
|
+
context.should_receive(:register_asset) do |a|
|
43
|
+
a.set_route %w{work gallery}
|
44
|
+
a
|
45
|
+
end
|
46
|
+
new_asset = parser.new_asset("/realpathto/image.jpg").with_name("image_1")
|
47
|
+
new_asset.should be_kind_of(BinderCore::Asset)
|
48
|
+
new_asset.feed_path.should == "work/gallery/image_1"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should create a new asset with the default values for name and path" do
|
52
|
+
path = "pathto/image.jpg"
|
53
|
+
context.should_receive(:file).and_return( BinderCore::FileRef.new( path ))
|
54
|
+
context.should_receive(:register_asset) { |a| a }
|
55
|
+
new_asset = parser.new_asset
|
56
|
+
new_asset.file.path.should == path
|
57
|
+
new_asset.name.should == "image"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should call descend with a config block and return data" do
|
61
|
+
bucket = {}
|
62
|
+
path = "path/to/folder/"
|
63
|
+
config = double("FolderConfig")
|
64
|
+
context.should_receive(:descend).and_yield(config).and_return({:data => bucket})
|
65
|
+
config.should_receive(:set_path).with(path)
|
66
|
+
resp = parser.descend do |c|
|
67
|
+
c.set_path path
|
68
|
+
end
|
69
|
+
resp.should == bucket
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BinderCore::AssetParser do
|
4
|
+
let(:path) { File.join(BINDER_DEFAULT_DIR, "test", "testfile.txt") }
|
5
|
+
let(:file) { BinderCore::FileRef.new path }
|
6
|
+
let(:context) { double("FileContext", :file => file ) }
|
7
|
+
|
8
|
+
it "should call descend into a folder and add the response to to file context data" do
|
9
|
+
parser = BinderCore::AssetParser.new context
|
10
|
+
context.should_receive(:register_asset).with(instance_of(BinderCore::Asset)) { |a| a }
|
11
|
+
context.should_receive(:data=).with(instance_of(BinderCore::Asset))
|
12
|
+
parser.parse
|
13
|
+
end
|
14
|
+
end
|