eim_xml 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +339 -0
- data/lib/eim_xml/assertions.rb +14 -14
- data/lib/eim_xml/dsl.rb +104 -96
- data/lib/eim_xml/formatter/element_wrapper.rb +8 -6
- data/lib/eim_xml/formatter.rb +105 -106
- data/lib/eim_xml/matcher.rb +23 -20
- data/lib/eim_xml/parser.rb +68 -70
- data/lib/eim_xml/xhtml/dsl.rb +16 -14
- data/lib/eim_xml/xhtml.rb +156 -152
- data/lib/eim_xml.rb +202 -202
- metadata +31 -61
- data/Rakefile +0 -26
- data/Rakefile.utirake +0 -374
- data/spec/assertions_test.rb +0 -30
- data/spec/dsl_spec.rb +0 -217
- data/spec/eim_xml_spec.rb +0 -441
- data/spec/formatter_spec.rb +0 -260
- data/spec/parser_spec.rb +0 -102
- data/spec/xhtml_spec.rb +0 -524
data/Rakefile.utirake
DELETED
@@ -1,374 +0,0 @@
|
|
1
|
-
# Utility for Rake
|
2
|
-
#
|
3
|
-
# Copyright (C) 2008, KURODA Hiraku <hiraku@hinet.mydns.jp>
|
4
|
-
# You can redistribute it and/or modify it under GPL3.
|
5
|
-
|
6
|
-
require "rake/clean"
|
7
|
-
require "rake/testtask"
|
8
|
-
require "rdoc/task"
|
9
|
-
require "rake/contrib/rubyforgepublisher"
|
10
|
-
require "rubygems/package_task"
|
11
|
-
|
12
|
-
class UtiRake
|
13
|
-
include Rake::DSL
|
14
|
-
|
15
|
-
def self.setup(opt={}, &proc)
|
16
|
-
ur = new
|
17
|
-
ur.setup(opt, &proc)
|
18
|
-
rescue
|
19
|
-
puts $!.class, $!.message, $!.backtrace
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_reader :opt, :spec_proc, :cucumber_proc, :rdoc_proc, :gemspec_proc, :package_proc, :rcov_spec_proc
|
23
|
-
|
24
|
-
def setup(opt={}, &proc)
|
25
|
-
@opt = opt
|
26
|
-
directory "external"
|
27
|
-
CLEAN << "coverage" << "coverage.spec" << "coverage.cuke" << "doc"
|
28
|
-
CLOBBER << "external"
|
29
|
-
|
30
|
-
instance_eval(&proc) if proc
|
31
|
-
|
32
|
-
if need_spec?
|
33
|
-
begin
|
34
|
-
@rspec2_flg = false
|
35
|
-
require "rspec/core/rake_task"
|
36
|
-
@rspec2_flg = true
|
37
|
-
rescue LoadError
|
38
|
-
require "spec/rake/spectask"
|
39
|
-
end
|
40
|
-
define_spec_task
|
41
|
-
end
|
42
|
-
|
43
|
-
if need_cucumber?
|
44
|
-
require "cucumber/rake/task"
|
45
|
-
define_cucumber_task
|
46
|
-
end
|
47
|
-
|
48
|
-
define_rdoc_task
|
49
|
-
define_rcov_task
|
50
|
-
define_package_task
|
51
|
-
define_here_dependency
|
52
|
-
define_alias_task if @alias_task
|
53
|
-
end
|
54
|
-
|
55
|
-
def rspec2?; @rspec2_flg; end
|
56
|
-
|
57
|
-
def spec_task
|
58
|
-
rspec2? ? RSpec::Core::RakeTask : Spec::Rake::SpecTask
|
59
|
-
end
|
60
|
-
|
61
|
-
def need_spec?
|
62
|
-
File.directory?("spec")
|
63
|
-
end
|
64
|
-
|
65
|
-
def need_cucumber?
|
66
|
-
File.directory?("features")
|
67
|
-
end
|
68
|
-
|
69
|
-
def spec(&proc)
|
70
|
-
@spec_proc = proc
|
71
|
-
end
|
72
|
-
|
73
|
-
def cucumber(&proc)
|
74
|
-
@cucumber_proc = proc
|
75
|
-
end
|
76
|
-
|
77
|
-
def rdoc(&proc)
|
78
|
-
@rdoc_proc = proc
|
79
|
-
end
|
80
|
-
|
81
|
-
def gemspec(&proc)
|
82
|
-
@gemspec_proc = proc
|
83
|
-
end
|
84
|
-
|
85
|
-
def rcov_spec(&proc)
|
86
|
-
@rcov_spec_proc = proc
|
87
|
-
end
|
88
|
-
|
89
|
-
def package(&proc)
|
90
|
-
@package_proc = proc
|
91
|
-
end
|
92
|
-
|
93
|
-
def no_here(task)
|
94
|
-
@no_here_task = task
|
95
|
-
end
|
96
|
-
|
97
|
-
def no_here_task
|
98
|
-
@no_here_task || "spec:lump"
|
99
|
-
end
|
100
|
-
|
101
|
-
def alias_task
|
102
|
-
@alias_task = true
|
103
|
-
end
|
104
|
-
|
105
|
-
def hg(cmd)
|
106
|
-
sh "hg #{cmd.to_s}"
|
107
|
-
end
|
108
|
-
|
109
|
-
def external(base_url, *libs)
|
110
|
-
libs = libs.first if libs.first.is_a?(Array)
|
111
|
-
namespace :external do
|
112
|
-
directory "external/lib"
|
113
|
-
libs.each do |lib|
|
114
|
-
libdir = "external/#{lib}"
|
115
|
-
file libdir => "external/lib" do
|
116
|
-
if File.exist?("../#{lib}")
|
117
|
-
Dir.chdir("external") do
|
118
|
-
ln_s "../../#{lib}", "./", :force=>true
|
119
|
-
end
|
120
|
-
end
|
121
|
-
hg "clone #{File.join(base_url, lib)} #{libdir}" unless File.exist?(libdir)
|
122
|
-
Dir["#{libdir}/lib/*"].each do |f|
|
123
|
-
base = File.basename(f)
|
124
|
-
cd "external/lib" do
|
125
|
-
ln_s "../#{lib}/lib/#{base}", "./"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
if File.exist?(libdir)
|
131
|
-
Dir["#{libdir}/lib/*"].each do |f|
|
132
|
-
base = File.basename(f)
|
133
|
-
file "external/lib/#{base}" => "external/lib" do
|
134
|
-
cd "external/lib" do
|
135
|
-
ln_s "../#{lib}/lib/#{base}", "./"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
task :setup => "external/lib/#{base}"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
desc "Setup external libraries"
|
143
|
-
task :setup=>libdir
|
144
|
-
end
|
145
|
-
|
146
|
-
task :rake => :setup do
|
147
|
-
libs.each do |lib|
|
148
|
-
Dir.chdir "external/#{lib}" do
|
149
|
-
sh "rake"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
@external = true
|
155
|
-
end
|
156
|
-
|
157
|
-
def external?; @external; end
|
158
|
-
|
159
|
-
def define_rdoc_task
|
160
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
161
|
-
rdoc.options << "-S"
|
162
|
-
rdoc.options << "-w" << "3"
|
163
|
-
rdoc.options << "-c" << "UTF-8"
|
164
|
-
rdoc.rdoc_files.include("lib/**/*.rb")
|
165
|
-
rdoc_proc.call(rdoc) if rdoc_proc
|
166
|
-
end
|
167
|
-
task :doc do
|
168
|
-
remove_entry_secure "doc" if File.directory?("doc")
|
169
|
-
sh "rdoc -S -w 3 -c UTF-8 -d -x external"
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def define_package_task
|
174
|
-
spec = Gem::Specification.new do |s|
|
175
|
-
s.platform = Gem::Platform::RUBY
|
176
|
-
s.files = FileList["Rakefile*", "lib/**/*", "spec/**/*"]
|
177
|
-
s.version = "0.0.0.noversion"
|
178
|
-
gemspec_proc.call(s) if gemspec_proc
|
179
|
-
end
|
180
|
-
|
181
|
-
gem = Gem::PackageTask.new(spec) do |t|
|
182
|
-
t.need_tar_gz = true
|
183
|
-
package_proc.call(t) if package_proc
|
184
|
-
end
|
185
|
-
|
186
|
-
task "utirake:copy_for_package" do
|
187
|
-
mv "Rakefile.utirake", "Rakefile.utirake_#{$$}"
|
188
|
-
cp "external/utirake/utirake.rb", "Rakefile.utirake"
|
189
|
-
end
|
190
|
-
|
191
|
-
file gem.package_dir_path => "utirake:copy_for_package"
|
192
|
-
|
193
|
-
task :gem do
|
194
|
-
rm "Rakefile.utirake"
|
195
|
-
mv "Rakefile.utirake_#{$$}", "Rakefile.utirake"
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def publish(project_name, user_id)
|
200
|
-
task :publish => "rdoc" do
|
201
|
-
yield if block_given?
|
202
|
-
Rake::RubyForgePublisher.new(project_name, user_id).upload
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
FILE_SORT = lambda{|a, b| File.mtime(a)<=>File.mtime(b)}
|
207
|
-
|
208
|
-
def spec_files
|
209
|
-
@spec_files ||= FileList["./spec/**/*_spec.rb"].sort(&FILE_SORT).reverse
|
210
|
-
end
|
211
|
-
|
212
|
-
def set_spec_opts(spec)
|
213
|
-
spec.verbose = false
|
214
|
-
if rspec2?
|
215
|
-
spec.rspec_opts ||= []
|
216
|
-
spec.rspec_opts << "-c"
|
217
|
-
spec.rspec_opts << "-I" << "." << "-I" << "./lib" << "-I" << "./external/lib"
|
218
|
-
else
|
219
|
-
spec.spec_opts << "-c"
|
220
|
-
spec.libs << "." << "./lib" << "./external/lib"
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
def define_spec_task
|
225
|
-
task :spec => "spec:apart"
|
226
|
-
namespace :spec do
|
227
|
-
spec_files.each do |f|
|
228
|
-
desc ""
|
229
|
-
spec_task.new(:apart) do |s|
|
230
|
-
if rspec2?
|
231
|
-
s.pattern = f
|
232
|
-
else
|
233
|
-
s.spec_files = FileList[f]
|
234
|
-
end
|
235
|
-
set_spec_opts(s)
|
236
|
-
spec_proc.call(s) if spec_proc
|
237
|
-
end
|
238
|
-
end
|
239
|
-
task(:apart).comment = "Run all specs separately"
|
240
|
-
|
241
|
-
desc "Run all specs in a lump"
|
242
|
-
spec_task.new(:lump) do |s|
|
243
|
-
s.spec_files = spec_files unless rspec2?
|
244
|
-
set_spec_opts(s)
|
245
|
-
spec_proc.call(s) if spec_proc
|
246
|
-
end
|
247
|
-
|
248
|
-
desc "Run all specs to profile"
|
249
|
-
spec_task.new(:profile) do |s|
|
250
|
-
set_spec_opts(s)
|
251
|
-
if rspec2?
|
252
|
-
s.rspec_opts << "-p"
|
253
|
-
else
|
254
|
-
s.spec_opts << "-f" << "profile"
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
`grep -sRn '#[[:space:]]*here\\([[:space:]]\\|$\\)' --include='*.rb' spec`.split(/\n/).map{|l|
|
259
|
-
next nil unless l=~/\A(.*?):(\d+):/
|
260
|
-
[$1, $2.to_i]
|
261
|
-
}.compact.sort{|a, b| FILE_SORT.call(a[0], b[0])}.reverse.each do |file, line|
|
262
|
-
desc ""
|
263
|
-
spec_task.new(:here) do |s|
|
264
|
-
set_spec_opts(s)
|
265
|
-
if rspec2?
|
266
|
-
s.pattern = file
|
267
|
-
s.rspec_opts << "-l#{line}"
|
268
|
-
else
|
269
|
-
s.spec_files = [file]
|
270
|
-
s.spec_opts << "-l#{line}"
|
271
|
-
end
|
272
|
-
spec_proc.call(s) if spec_proc
|
273
|
-
end
|
274
|
-
end
|
275
|
-
task :no_here => no_here_task
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
def set_cucumber_opts(task)
|
280
|
-
task.libs << "."
|
281
|
-
cucumber_proc.call(task) if cucumber_proc
|
282
|
-
end
|
283
|
-
|
284
|
-
def define_cucumber_task
|
285
|
-
Cucumber::Rake::Task.new do |t|
|
286
|
-
set_cucumber_opts(t)
|
287
|
-
end
|
288
|
-
|
289
|
-
unless `grep -sRn '^[[:space:]]*@here$' features`.empty?
|
290
|
-
Cucumber::Rake::Task.new("cucumber:here") do |t|
|
291
|
-
t.cucumber_opts = %w[--tags @here]
|
292
|
-
set_cucumber_opts(t)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
task "cucumber:no_here" => :cucumber
|
296
|
-
end
|
297
|
-
|
298
|
-
def define_here_dependency
|
299
|
-
unless Rake::Task.task_defined?("spec:here") || Rake::Task.task_defined?("cucumber:here")
|
300
|
-
task "spec:here" => "spec:no_here" if need_spec? && !Rake::Task.task_defined?("spec:here")
|
301
|
-
task "cucumber:here" => "cucumber:no_here" if need_cucumber? && !Rake::Task.task_defined?("cucumber:here")
|
302
|
-
end
|
303
|
-
|
304
|
-
task("spec:here").comment = "Run spec only marked '# here'"
|
305
|
-
task("cucumber:here").comment = "only tagged '@here'"
|
306
|
-
end
|
307
|
-
|
308
|
-
def rcov_opts(t, aggregation)
|
309
|
-
t.rcov_opts ||= []
|
310
|
-
t.rcov_opts << "-I" << "./spec:./lib:./external/lib"
|
311
|
-
t.rcov_opts << "--exclude" << "gems\/,features\/,external\/"
|
312
|
-
t.rcov_opts << "--aggregate" << "coverage.data" if aggregation
|
313
|
-
t.rcov = true
|
314
|
-
end
|
315
|
-
|
316
|
-
def define_rcov_each_task(aggregation)
|
317
|
-
if need_spec?
|
318
|
-
spec_task.new do |t|
|
319
|
-
t.verbose = false
|
320
|
-
rcov_opts(t, aggregation)
|
321
|
-
if rspec2?
|
322
|
-
t.rcov_opts << "-o" << "coverage.spec" unless aggregation
|
323
|
-
else
|
324
|
-
set_spec_opts(t)
|
325
|
-
t.spec_files = spec_files
|
326
|
-
t.rcov_dir = "coverage.spec" unless aggregation
|
327
|
-
end
|
328
|
-
rcov_spec_proc.call(t) if rcov_spec_proc
|
329
|
-
end
|
330
|
-
else
|
331
|
-
task "spec"
|
332
|
-
end
|
333
|
-
|
334
|
-
if need_cucumber?
|
335
|
-
Cucumber::Rake::Task.new do |t|
|
336
|
-
set_cucumber_opts(t)
|
337
|
-
rcov_opts(t, aggregation)
|
338
|
-
t.rcov_opts << "-o" << "coverage.cuke" unless aggregation
|
339
|
-
end
|
340
|
-
else
|
341
|
-
task "cucumber"
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
def define_rcov_task
|
346
|
-
namespace :rcov do
|
347
|
-
define_rcov_each_task(false)
|
348
|
-
end
|
349
|
-
|
350
|
-
desc "Run specs and Cucumber using RCov"
|
351
|
-
task "rcov:lump" do
|
352
|
-
rm "coverage.data" if File.exist?("coverage.data")
|
353
|
-
ns = namespace do
|
354
|
-
define_rcov_each_task(true)
|
355
|
-
end
|
356
|
-
ns.tasks.each do |t|
|
357
|
-
t.invoke
|
358
|
-
end
|
359
|
-
rm "coverage.data"
|
360
|
-
end
|
361
|
-
|
362
|
-
task "rcov:all" => %w[rcov:spec rcov:cucumber rcov:lump]
|
363
|
-
end
|
364
|
-
|
365
|
-
def define_alias_task
|
366
|
-
if Rake::Task.task_defined?("spec:apart")
|
367
|
-
task :apart => "spec:apart"
|
368
|
-
task :lump => "spec:lump"
|
369
|
-
task :here => "spec:here"
|
370
|
-
task :profile => "spec:profile"
|
371
|
-
end
|
372
|
-
task :here => "cucumber:here" if Rake::Task.task_defined?("cucumber:here")
|
373
|
-
end
|
374
|
-
end
|
data/spec/assertions_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# Test for eim_xml/assertions.rb
|
2
|
-
#
|
3
|
-
# Copyright (C) 2006, KURODA Hiraku <hiraku@hinet.mydns.jp>
|
4
|
-
# You can redistribute it and/or modify it under GPL2.
|
5
|
-
|
6
|
-
$:.unshift "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/lib"
|
7
|
-
require "test/unit"
|
8
|
-
require "eim_xml/assertions"
|
9
|
-
|
10
|
-
class EimXMLAssertionsTest < Test::Unit::TestCase
|
11
|
-
include EimXML
|
12
|
-
include EimXML::Assertions
|
13
|
-
|
14
|
-
def test_assert_has
|
15
|
-
e = Element.new(:tag) do |e|
|
16
|
-
e <<= Element.new(:sub)
|
17
|
-
end
|
18
|
-
|
19
|
-
assert_nothing_raised do
|
20
|
-
assert_has(:sub, e)
|
21
|
-
end
|
22
|
-
|
23
|
-
a = assert_raises(Test::Unit::AssertionFailedError) do
|
24
|
-
assert_has(:no, e)
|
25
|
-
end
|
26
|
-
assert(!a.backtrace.any?{ |i|
|
27
|
-
i=~/eim_xml\/assertions\.rb/
|
28
|
-
})
|
29
|
-
end
|
30
|
-
end
|
data/spec/dsl_spec.rb
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
require "eim_xml/dsl"
|
2
|
-
|
3
|
-
module Module.new::M
|
4
|
-
include EimXML
|
5
|
-
EDSL = EimXML::DSL
|
6
|
-
|
7
|
-
describe EimXML::DSL do
|
8
|
-
it "scope is in instance of DSL" do
|
9
|
-
outer = inner = nil
|
10
|
-
e3 = e2 = nil
|
11
|
-
block_executed = false
|
12
|
-
e = EDSL.element(:out, :k1=>"v1") do
|
13
|
-
outer = self
|
14
|
-
e2 = element(:in, :k2=>"v2") do
|
15
|
-
block_executed = true
|
16
|
-
inner = self
|
17
|
-
e3 = element(:deep)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
block_executed.should == true
|
22
|
-
outer.should be_kind_of(EDSL)
|
23
|
-
inner.should be_kind_of(EDSL)
|
24
|
-
outer.should be_equal(inner)
|
25
|
-
|
26
|
-
e.name.should == :out
|
27
|
-
e[:k1].should == "v1"
|
28
|
-
e[0].name.should == :in
|
29
|
-
e[0][:k2].should == "v2"
|
30
|
-
e[0][0].name.should == :deep
|
31
|
-
e2.should be_equal(e[0])
|
32
|
-
e3.should be_equal(e[0][0])
|
33
|
-
end
|
34
|
-
|
35
|
-
it "#comment" do
|
36
|
-
Comment.should_receive(:new).with("comment").and_return(:success)
|
37
|
-
EDSL.comment("comment").should == :success
|
38
|
-
end
|
39
|
-
|
40
|
-
it "#import_variables" do
|
41
|
-
d = EDSL.new
|
42
|
-
o = Object.new
|
43
|
-
o.instance_variable_set("@v1", 1)
|
44
|
-
o.instance_variable_set("@v2", "2")
|
45
|
-
o.instance_variable_set("@_v3", :t)
|
46
|
-
o.instance_variable_set("@__v4", 4)
|
47
|
-
o.instance_variable_set("@_container", :t)
|
48
|
-
orig_c = d.instance_variable_get("@_container")
|
49
|
-
|
50
|
-
d.import_variables(o).should be_equal(d)
|
51
|
-
|
52
|
-
d.instance_variable_get("@_container").should == orig_c
|
53
|
-
d.instance_variables.map(&:to_s).sort.should == ["@v1", "@v2", "@__v4"].sort
|
54
|
-
d.instance_variable_get("@v1").should == 1
|
55
|
-
d.instance_variable_get("@v2").should == "2"
|
56
|
-
d.instance_variable_get("@__v4").should == 4
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#_push" do
|
60
|
-
before do
|
61
|
-
m = Module.new
|
62
|
-
class m::D < EimXML::DSL
|
63
|
-
def call_push(c)
|
64
|
-
_push(c) do
|
65
|
-
element(:e)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def exec
|
70
|
-
element(:e) do
|
71
|
-
element(:f)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
@D = m::D
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should return given container" do
|
79
|
-
a = []
|
80
|
-
@D.new.call_push(a).should be_equal(a)
|
81
|
-
a.should == [EimXML::Element.new(:e)]
|
82
|
-
|
83
|
-
@D.new.exec.should == EimXML::Element.new(:e).add(EimXML::Element.new(:f))
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "Subclass of BaseDSL" do
|
89
|
-
class DSL1 < EimXML::BaseDSL
|
90
|
-
register([EimXML::Element, "call"])
|
91
|
-
register(Hash)
|
92
|
-
register(String, Array, Object)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "register" do
|
96
|
-
lambda{EDSL.call(:dummy)}.should raise_error(NoMethodError)
|
97
|
-
lambda{BaseDSL.call(:dummy)}.should raise_error(NoMethodError)
|
98
|
-
lambda{DSL1.element(:dummy)}.should raise_error(NoMethodError)
|
99
|
-
DSL1.call(:dummy).should be_kind_of(Element)
|
100
|
-
DSL1.hash.should be_kind_of(Hash)
|
101
|
-
DSL1.string.should be_kind_of(String)
|
102
|
-
DSL1.array.should be_kind_of(Array)
|
103
|
-
DSL1.object.should be_kind_of(Object)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe EimXML::OpenDSL do
|
108
|
-
it "scope of block is one of outside" do
|
109
|
-
@scope_checker_variable = 1
|
110
|
-
block_executed = false
|
111
|
-
d = OpenDSL.new do |d|
|
112
|
-
block_executed = true
|
113
|
-
d.should be_kind_of(OpenDSL)
|
114
|
-
d.container.should be_nil
|
115
|
-
d.element(:base, :key1=>"v1") do
|
116
|
-
@scope_checker_variable.should == 1
|
117
|
-
self.should_not be_kind_of(Element)
|
118
|
-
d.container.should be_kind_of(Element)
|
119
|
-
d.container.should == Element.new(:base, :key1=>"v1")
|
120
|
-
d.element(:sub, :key2=>"v2") do
|
121
|
-
d.container.should be_kind_of(Element)
|
122
|
-
d.container.should == Element.new(:sub, :key2=>"v2")
|
123
|
-
end
|
124
|
-
d.element(:sub2).should == Element.new(:sub2)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
block_executed.should be_true
|
128
|
-
end
|
129
|
-
|
130
|
-
it "DSL methods return element" do
|
131
|
-
d = OpenDSL.new
|
132
|
-
d.container.should be_nil
|
133
|
-
r = d.element(:base, :key1=>"v1") do
|
134
|
-
d.element(:sub, :key2=>"v2")
|
135
|
-
end
|
136
|
-
r.should == EDSL.element(:base, :key1=>"v1") do
|
137
|
-
element(:sub, :key2=>"v2")
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
it "DSL method's block given instance of OpenDSL" do
|
142
|
-
e = OpenDSL.new.element(:base) do |d|
|
143
|
-
d.should be_kind_of(OpenDSL)
|
144
|
-
d.container.name.should == :base
|
145
|
-
d.element(:sub) do |d2|
|
146
|
-
d2.should be_equal(d)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
e.should == EDSL.element(:base) do
|
151
|
-
element(:sub)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
it "ensure reset container when error raised" do
|
156
|
-
OpenDSL.new do |d|
|
157
|
-
begin
|
158
|
-
d.element(:base) do
|
159
|
-
begin
|
160
|
-
d.element(:sub) do
|
161
|
-
raise "OK"
|
162
|
-
end
|
163
|
-
rescue RuntimeError => e
|
164
|
-
raise unless e.message=="OK"
|
165
|
-
d.container.name.should == :base
|
166
|
-
raise
|
167
|
-
end
|
168
|
-
end
|
169
|
-
rescue RuntimeError => e
|
170
|
-
raise unless e.message=="OK"
|
171
|
-
d.container.should == nil
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
it "respond to add" do
|
177
|
-
r = OpenDSL.new.element(:base) do |d|
|
178
|
-
d.add "text"
|
179
|
-
d.element(:sub) do
|
180
|
-
s = Element.new(:sub)
|
181
|
-
s.add("sub text")
|
182
|
-
d.add("sub text").should == s
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
r.should == EDSL.element(:base) do
|
187
|
-
add "text"
|
188
|
-
element(:sub) do
|
189
|
-
add "sub text"
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
it "respond to <<" do
|
195
|
-
r = OpenDSL.new.element(:base) do |d|
|
196
|
-
b = Element.new(:base)
|
197
|
-
b << "text" << "next"
|
198
|
-
(d << "text" << "next").should == b
|
199
|
-
end
|
200
|
-
r.should == EDSL.element(:base) do
|
201
|
-
add "text"
|
202
|
-
add "next"
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
it "can call directly element method" do
|
207
|
-
r = OpenDSL.element(:base) do |d|
|
208
|
-
d.element(:sub)
|
209
|
-
d.element(:sub2)
|
210
|
-
end
|
211
|
-
r.should == EDSL.element(:base) do
|
212
|
-
element(:sub)
|
213
|
-
element(:sub2)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|