ruby_speech 2.1.2-java → 2.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.travis.yml +1 -2
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +23 -0
  4. data/ext/ruby_speech/extconf.rb +3 -1
  5. data/ext/ruby_speech/ruby_speech.c +4 -1
  6. data/lib/ruby_speech/generic_element.rb +141 -29
  7. data/lib/ruby_speech/grxml/element.rb +6 -6
  8. data/lib/ruby_speech/grxml/grammar.rb +29 -12
  9. data/lib/ruby_speech/grxml/item.rb +13 -0
  10. data/lib/ruby_speech/grxml/matcher.rb +5 -1
  11. data/lib/ruby_speech/grxml/one_of.rb +4 -0
  12. data/lib/ruby_speech/grxml/rule.rb +10 -0
  13. data/lib/ruby_speech/grxml/token.rb +3 -0
  14. data/lib/ruby_speech/grxml.rb +16 -22
  15. data/lib/ruby_speech/nlsml.rb +3 -9
  16. data/lib/ruby_speech/ruby_speech.jar +0 -0
  17. data/lib/ruby_speech/ssml/audio.rb +17 -0
  18. data/lib/ruby_speech/ssml/desc.rb +4 -0
  19. data/lib/ruby_speech/ssml/element.rb +5 -3
  20. data/lib/ruby_speech/ssml/emphasis.rb +17 -0
  21. data/lib/ruby_speech/ssml/mark.rb +2 -0
  22. data/lib/ruby_speech/ssml/p.rb +21 -0
  23. data/lib/ruby_speech/ssml/phoneme.rb +2 -0
  24. data/lib/ruby_speech/ssml/prosody.rb +15 -0
  25. data/lib/ruby_speech/ssml/s.rb +20 -0
  26. data/lib/ruby_speech/ssml/say_as.rb +2 -0
  27. data/lib/ruby_speech/ssml/speak.rb +19 -1
  28. data/lib/ruby_speech/ssml/sub.rb +2 -0
  29. data/lib/ruby_speech/ssml/voice.rb +19 -0
  30. data/lib/ruby_speech/ssml.rb +20 -22
  31. data/lib/ruby_speech/version.rb +1 -1
  32. data/lib/ruby_speech.rb +6 -19
  33. data/ruby_speech.gemspec +2 -3
  34. data/spec/ruby_speech/grxml/grammar_spec.rb +35 -30
  35. data/spec/ruby_speech/grxml/item_spec.rb +8 -6
  36. data/spec/ruby_speech/grxml/one_of_spec.rb +7 -3
  37. data/spec/ruby_speech/grxml/rule_spec.rb +14 -12
  38. data/spec/ruby_speech/grxml/ruleref_spec.rb +5 -3
  39. data/spec/ruby_speech/grxml/tag_spec.rb +6 -2
  40. data/spec/ruby_speech/grxml/token_spec.rb +6 -2
  41. data/spec/ruby_speech/grxml_spec.rb +57 -69
  42. data/spec/ruby_speech/ssml/audio_spec.rb +20 -16
  43. data/spec/ruby_speech/ssml/break_spec.rb +14 -10
  44. data/spec/ruby_speech/ssml/desc_spec.rb +9 -5
  45. data/spec/ruby_speech/ssml/emphasis_spec.rb +17 -13
  46. data/spec/ruby_speech/ssml/mark_spec.rb +7 -3
  47. data/spec/ruby_speech/ssml/p_spec.rb +18 -14
  48. data/spec/ruby_speech/ssml/phoneme_spec.rb +10 -6
  49. data/spec/ruby_speech/ssml/prosody_spec.rb +29 -25
  50. data/spec/ruby_speech/ssml/s_spec.rb +17 -13
  51. data/spec/ruby_speech/ssml/say_as_spec.rb +11 -7
  52. data/spec/ruby_speech/ssml/speak_spec.rb +48 -32
  53. data/spec/ruby_speech/ssml/sub_spec.rb +9 -5
  54. data/spec/ruby_speech/ssml/voice_spec.rb +23 -19
  55. data/spec/ruby_speech/ssml_spec.rb +64 -63
  56. data/spec/spec_helper.rb +0 -3
  57. metadata +12 -35
  58. data/lib/ruby_speech/xml.rb +0 -11
@@ -3,10 +3,14 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module SSML
5
5
  describe P do
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { described_class.new doc }
9
+
6
10
  its(:name) { should == 'p' }
7
11
 
8
12
  describe "setting options in initializers" do
9
- subject { P.new :language => 'jp' }
13
+ subject { P.new doc, :language => 'jp' }
10
14
 
11
15
  its(:language) { should == 'jp' }
12
16
  end
@@ -26,18 +30,18 @@ module RubySpeech
26
30
 
27
31
  describe "comparing objects" do
28
32
  it "should be equal if the content and language are the same" do
29
- P.new(:language => 'jp', :content => "Hello there").should == P.new(:language => 'jp', :content => "Hello there")
33
+ P.new(doc, :language => 'jp', :content => "Hello there").should == P.new(doc, :language => 'jp', :content => "Hello there")
30
34
  end
31
35
 
32
36
  describe "when the content is different" do
33
37
  it "should not be equal" do
34
- P.new(:content => "Hello").should_not == P.new(:content => "Hello there")
38
+ P.new(doc, :content => "Hello").should_not == P.new(doc, :content => "Hello there")
35
39
  end
36
40
  end
37
41
 
38
42
  describe "when the language is different" do
39
43
  it "should not be equal" do
40
- P.new(:language => 'jp').should_not == P.new(:language => 'en')
44
+ P.new(doc, :language => 'jp').should_not == P.new(doc, :language => 'en')
41
45
  end
42
46
  end
43
47
  end
@@ -48,43 +52,43 @@ module RubySpeech
48
52
  end
49
53
 
50
54
  it "should accept Audio" do
51
- lambda { subject << Audio.new }.should_not raise_error
55
+ lambda { subject << Audio.new(doc) }.should_not raise_error
52
56
  end
53
57
 
54
58
  it "should accept Break" do
55
- lambda { subject << Break.new }.should_not raise_error
59
+ lambda { subject << Break.new(doc) }.should_not raise_error
56
60
  end
57
61
 
58
62
  it "should accept Emphasis" do
59
- lambda { subject << Emphasis.new }.should_not raise_error
63
+ lambda { subject << Emphasis.new(doc) }.should_not raise_error
60
64
  end
61
65
 
62
66
  it "should accept Mark" do
63
- lambda { subject << Mark.new }.should_not raise_error
67
+ lambda { subject << Mark.new(doc) }.should_not raise_error
64
68
  end
65
69
 
66
70
  it "should accept Phoneme" do
67
- lambda { subject << Phoneme.new }.should_not raise_error
71
+ lambda { subject << Phoneme.new(doc) }.should_not raise_error
68
72
  end
69
73
 
70
74
  it "should accept Prosody" do
71
- lambda { subject << Prosody.new }.should_not raise_error
75
+ lambda { subject << Prosody.new(doc) }.should_not raise_error
72
76
  end
73
77
 
74
78
  it "should accept SayAs" do
75
- lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
79
+ lambda { subject << SayAs.new(doc, :interpret_as => :foo) }.should_not raise_error
76
80
  end
77
81
 
78
82
  it "should accept Sub" do
79
- lambda { subject << Sub.new }.should_not raise_error
83
+ lambda { subject << Sub.new(doc) }.should_not raise_error
80
84
  end
81
85
 
82
86
  it "should accept S" do
83
- lambda { subject << S.new }.should_not raise_error
87
+ lambda { subject << S.new(doc) }.should_not raise_error
84
88
  end
85
89
 
86
90
  it "should accept Voice" do
87
- lambda { subject << Voice.new }.should_not raise_error
91
+ lambda { subject << Voice.new(doc) }.should_not raise_error
88
92
  end
89
93
 
90
94
  it "should raise InvalidChildError with non-acceptable objects" do
@@ -3,10 +3,14 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module SSML
5
5
  describe Phoneme do
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { described_class.new doc }
9
+
6
10
  its(:name) { should == 'phoneme' }
7
11
 
8
12
  describe "setting options in initializers" do
9
- subject { Phoneme.new :alphabet => 'foo', :ph => 'bar' }
13
+ subject { Phoneme.new doc, :alphabet => 'foo', :ph => 'bar' }
10
14
 
11
15
  its(:alphabet) { should == 'foo' }
12
16
  its(:ph) { should == 'bar' }
@@ -29,24 +33,24 @@ module RubySpeech
29
33
 
30
34
  describe "comparing objects" do
31
35
  it "should be equal if the content, ph and alphabet are the same" do
32
- Phoneme.new(:alphabet => 'jp', :ph => 'foo', :content => "Hello there").should == Phoneme.new(:alphabet => 'jp', :ph => 'foo', :content => "Hello there")
36
+ Phoneme.new(doc, :alphabet => 'jp', :ph => 'foo', :content => "Hello there").should == Phoneme.new(doc, :alphabet => 'jp', :ph => 'foo', :content => "Hello there")
33
37
  end
34
38
 
35
39
  describe "when the content is different" do
36
40
  it "should not be equal" do
37
- Phoneme.new(:content => "Hello").should_not == Phoneme.new(:content => "Hello there")
41
+ Phoneme.new(doc, :content => "Hello").should_not == Phoneme.new(doc, :content => "Hello there")
38
42
  end
39
43
  end
40
44
 
41
45
  describe "when the ph is different" do
42
46
  it "should not be equal" do
43
- Phoneme.new(:ph => 'jp').should_not == Phoneme.new(:ph => 'en')
47
+ Phoneme.new(doc, :ph => 'jp').should_not == Phoneme.new(doc, :ph => 'en')
44
48
  end
45
49
  end
46
50
 
47
51
  describe "when the alphabet is different" do
48
52
  it "should not be equal" do
49
- Phoneme.new(:alphabet => 'jp').should_not == Phoneme.new(:alphabet => 'en')
53
+ Phoneme.new(doc, :alphabet => 'jp').should_not == Phoneme.new(doc, :alphabet => 'en')
50
54
  end
51
55
  end
52
56
  end
@@ -57,7 +61,7 @@ module RubySpeech
57
61
  end
58
62
 
59
63
  it "should raise InvalidChildError with non-acceptable objects" do
60
- lambda { subject << Voice.new }.should raise_error(InvalidChildError, "A Phoneme can only accept Strings as children")
64
+ lambda { subject << Voice.new(doc) }.should raise_error(InvalidChildError, "A Phoneme can only accept Strings as children")
61
65
  end
62
66
  end
63
67
  end # Desc
@@ -3,16 +3,20 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module SSML
5
5
  describe Prosody do
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { described_class.new doc }
9
+
6
10
  its(:name) { should == 'prosody' }
7
11
 
8
12
  describe "setting options in initializers" do
9
- subject { Prosody.new :pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10.seconds, :volume => :loud }
13
+ subject { Prosody.new doc, :pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10, :volume => :loud }
10
14
 
11
15
  its(:pitch) { should == :medium }
12
16
  its(:contour) { should == 'something' }
13
17
  its(:range) { should == '20Hz' }
14
18
  its(:rate) { should == 2 }
15
- its(:duration) { should == 10.seconds }
19
+ its(:duration) { should == 10 }
16
20
  its(:volume) { should == :loud }
17
21
  end
18
22
 
@@ -31,7 +35,7 @@ module RubySpeech
31
35
  its(:contour) { should == 'something' }
32
36
  its(:range) { should == '20Hz' }
33
37
  its(:rate) { should == 2 }
34
- its(:duration) { should == 10.seconds }
38
+ its(:duration) { should == 10 }
35
39
  its(:volume) { should == :loud }
36
40
  end
37
41
 
@@ -150,14 +154,14 @@ module RubySpeech
150
154
 
151
155
  describe "#duration" do
152
156
  context "with a valid value" do
153
- before { subject.duration = 3.seconds }
157
+ before { subject.duration = 3 }
154
158
 
155
- its(:duration) { should == 3.seconds }
159
+ its(:duration) { should == 3 }
156
160
  end
157
161
 
158
162
  context "with a negative value" do
159
163
  it do
160
- lambda { subject.duration = -3.seconds }.should raise_error(ArgumentError, "You must specify a valid duration (positive float value in seconds)")
164
+ lambda { subject.duration = -3 }.should raise_error(ArgumentError, "You must specify a valid duration (positive float value in seconds)")
161
165
  end
162
166
  end
163
167
 
@@ -205,48 +209,48 @@ module RubySpeech
205
209
 
206
210
  describe "comparing objects" do
207
211
  it "should be equal if the content, strength and base uri are the same" do
208
- Prosody.new(:pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10.seconds, :volume => :loud, :content => "Hello there").should == Prosody.new(:pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10.seconds, :volume => :loud, :content => "Hello there")
212
+ Prosody.new(doc, :pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10, :volume => :loud, :content => "Hello there").should == Prosody.new(doc, :pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10, :volume => :loud, :content => "Hello there")
209
213
  end
210
214
 
211
215
  describe "when the content is different" do
212
216
  it "should not be equal" do
213
- Prosody.new(:content => "Hello").should_not == Prosody.new(:content => "Hello there")
217
+ Prosody.new(doc, :content => "Hello").should_not == Prosody.new(doc, :content => "Hello there")
214
218
  end
215
219
  end
216
220
 
217
221
  describe "when the pitch is different" do
218
222
  it "should not be equal" do
219
- Prosody.new(:pitch => :medium).should_not == Prosody.new(:pitch => :high)
223
+ Prosody.new(doc, :pitch => :medium).should_not == Prosody.new(doc, :pitch => :high)
220
224
  end
221
225
  end
222
226
 
223
227
  describe "when the contour is different" do
224
228
  it "should not be equal" do
225
- Prosody.new(:contour => 'foo').should_not == Prosody.new(:contour => 'bar')
229
+ Prosody.new(doc, :contour => 'foo').should_not == Prosody.new(doc, :contour => 'bar')
226
230
  end
227
231
  end
228
232
 
229
233
  describe "when the range is different" do
230
234
  it "should not be equal" do
231
- Prosody.new(:range => '20Hz').should_not == Prosody.new(:range => '30Hz')
235
+ Prosody.new(doc, :range => '20Hz').should_not == Prosody.new(doc, :range => '30Hz')
232
236
  end
233
237
  end
234
238
 
235
239
  describe "when the rate is different" do
236
240
  it "should not be equal" do
237
- Prosody.new(:rate => 2).should_not == Prosody.new(:rate => 3)
241
+ Prosody.new(doc, :rate => 2).should_not == Prosody.new(doc, :rate => 3)
238
242
  end
239
243
  end
240
244
 
241
245
  describe "when the duration is different" do
242
246
  it "should not be equal" do
243
- Prosody.new(:duration => 10.seconds).should_not == Prosody.new(:duration => 20.seconds)
247
+ Prosody.new(doc, :duration => 10).should_not == Prosody.new(doc, :duration => 20)
244
248
  end
245
249
  end
246
250
 
247
251
  describe "when the volume is different" do
248
252
  it "should not be equal" do
249
- Prosody.new(:volume => :loud).should_not == Prosody.new(:volume => :soft)
253
+ Prosody.new(doc, :volume => :loud).should_not == Prosody.new(doc, :volume => :soft)
250
254
  end
251
255
  end
252
256
  end
@@ -257,47 +261,47 @@ module RubySpeech
257
261
  end
258
262
 
259
263
  it "should accept Audio" do
260
- lambda { subject << Audio.new }.should_not raise_error
264
+ lambda { subject << Audio.new(doc) }.should_not raise_error
261
265
  end
262
266
 
263
267
  it "should accept Break" do
264
- lambda { subject << Break.new }.should_not raise_error
268
+ lambda { subject << Break.new(doc) }.should_not raise_error
265
269
  end
266
270
 
267
271
  it "should accept Emphasis" do
268
- lambda { subject << Emphasis.new }.should_not raise_error
272
+ lambda { subject << Emphasis.new(doc) }.should_not raise_error
269
273
  end
270
274
 
271
275
  it "should accept Mark" do
272
- lambda { subject << Mark.new }.should_not raise_error
276
+ lambda { subject << Mark.new(doc) }.should_not raise_error
273
277
  end
274
278
 
275
279
  it "should accept P" do
276
- lambda { subject << P.new }.should_not raise_error
280
+ lambda { subject << P.new(doc) }.should_not raise_error
277
281
  end
278
282
 
279
283
  it "should accept Phoneme" do
280
- lambda { subject << Phoneme.new }.should_not raise_error
284
+ lambda { subject << Phoneme.new(doc) }.should_not raise_error
281
285
  end
282
286
 
283
287
  it "should accept Prosody" do
284
- lambda { subject << Prosody.new }.should_not raise_error
288
+ lambda { subject << Prosody.new(doc) }.should_not raise_error
285
289
  end
286
290
 
287
291
  it "should accept S" do
288
- lambda { subject << S.new }.should_not raise_error
292
+ lambda { subject << S.new(doc) }.should_not raise_error
289
293
  end
290
294
 
291
295
  it "should accept SayAs" do
292
- lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
296
+ lambda { subject << SayAs.new(doc, :interpret_as => :foo) }.should_not raise_error
293
297
  end
294
298
 
295
299
  it "should accept Sub" do
296
- lambda { subject << Sub.new }.should_not raise_error
300
+ lambda { subject << Sub.new(doc) }.should_not raise_error
297
301
  end
298
302
 
299
303
  it "should accept Voice" do
300
- lambda { subject << Voice.new }.should_not raise_error
304
+ lambda { subject << Voice.new(doc) }.should_not raise_error
301
305
  end
302
306
 
303
307
  it "should raise InvalidChildError with non-acceptable objects" do
@@ -3,10 +3,14 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module SSML
5
5
  describe S do
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { described_class.new doc }
9
+
6
10
  its(:name) { should == 's' }
7
11
 
8
12
  describe "setting options in initializers" do
9
- subject { S.new :language => 'jp' }
13
+ subject { S.new doc, :language => 'jp' }
10
14
 
11
15
  its(:language) { should == 'jp' }
12
16
  end
@@ -26,18 +30,18 @@ module RubySpeech
26
30
 
27
31
  describe "comparing objects" do
28
32
  it "should be equal if the content and language are the same" do
29
- S.new(:language => 'jp', :content => "Hello there").should == S.new(:language => 'jp', :content => "Hello there")
33
+ S.new(doc, :language => 'jp', :content => "Hello there").should == S.new(doc, :language => 'jp', :content => "Hello there")
30
34
  end
31
35
 
32
36
  describe "when the content is different" do
33
37
  it "should not be equal" do
34
- S.new(:content => "Hello").should_not == S.new(:content => "Hello there")
38
+ S.new(doc, :content => "Hello").should_not == S.new(doc, :content => "Hello there")
35
39
  end
36
40
  end
37
41
 
38
42
  describe "when the language is different" do
39
43
  it "should not be equal" do
40
- S.new(:language => 'jp').should_not == S.new(:language => 'en')
44
+ S.new(doc, :language => 'jp').should_not == S.new(doc, :language => 'en')
41
45
  end
42
46
  end
43
47
  end
@@ -48,39 +52,39 @@ module RubySpeech
48
52
  end
49
53
 
50
54
  it "should accept Audio" do
51
- lambda { subject << Audio.new }.should_not raise_error
55
+ lambda { subject << Audio.new(doc) }.should_not raise_error
52
56
  end
53
57
 
54
58
  it "should accept Break" do
55
- lambda { subject << Break.new }.should_not raise_error
59
+ lambda { subject << Break.new(doc) }.should_not raise_error
56
60
  end
57
61
 
58
62
  it "should accept Emphasis" do
59
- lambda { subject << Emphasis.new }.should_not raise_error
63
+ lambda { subject << Emphasis.new(doc) }.should_not raise_error
60
64
  end
61
65
 
62
66
  it "should accept Mark" do
63
- lambda { subject << Mark.new }.should_not raise_error
67
+ lambda { subject << Mark.new(doc) }.should_not raise_error
64
68
  end
65
69
 
66
70
  it "should accept Phoneme" do
67
- lambda { subject << Phoneme.new }.should_not raise_error
71
+ lambda { subject << Phoneme.new(doc) }.should_not raise_error
68
72
  end
69
73
 
70
74
  it "should accept Prosody" do
71
- lambda { subject << Prosody.new }.should_not raise_error
75
+ lambda { subject << Prosody.new(doc) }.should_not raise_error
72
76
  end
73
77
 
74
78
  it "should accept SayAs" do
75
- lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
79
+ lambda { subject << SayAs.new(doc, :interpret_as => :foo) }.should_not raise_error
76
80
  end
77
81
 
78
82
  it "should accept Sub" do
79
- lambda { subject << Sub.new }.should_not raise_error
83
+ lambda { subject << Sub.new(doc) }.should_not raise_error
80
84
  end
81
85
 
82
86
  it "should accept Voice" do
83
- lambda { subject << Voice.new }.should_not raise_error
87
+ lambda { subject << Voice.new(doc) }.should_not raise_error
84
88
  end
85
89
 
86
90
  it "should raise InvalidChildError with non-acceptable objects" do
@@ -3,7 +3,11 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module SSML
5
5
  describe SayAs do
6
- subject { SayAs.new :interpret_as => 'one', :format => 'two', :detail => 'three' }
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { described_class.new doc }
9
+
10
+ subject { SayAs.new doc, :interpret_as => 'one', :format => 'two', :detail => 'three' }
7
11
 
8
12
  its(:name) { should == 'say-as' }
9
13
 
@@ -29,30 +33,30 @@ module RubySpeech
29
33
 
30
34
  describe "comparing objects" do
31
35
  it "should be equal if the content, interpret_as, format, age, variant, name are the same" do
32
- SayAs.new(:interpret_as => 'jp', :format => 'foo', :detail => 'bar', :content => "hello").should == SayAs.new(:interpret_as => 'jp', :format => 'foo', :detail => 'bar', :content => "hello")
36
+ SayAs.new(doc, :interpret_as => 'jp', :format => 'foo', :detail => 'bar', :content => "hello").should == SayAs.new(doc, :interpret_as => 'jp', :format => 'foo', :detail => 'bar', :content => "hello")
33
37
  end
34
38
 
35
39
  describe "when the content is different" do
36
40
  it "should not be equal" do
37
- SayAs.new(:interpret_as => 'jp', :content => "Hello").should_not == SayAs.new(:interpret_as => 'jp', :content => "Hello there")
41
+ SayAs.new(doc, :interpret_as => 'jp', :content => "Hello").should_not == SayAs.new(doc, :interpret_as => 'jp', :content => "Hello there")
38
42
  end
39
43
  end
40
44
 
41
45
  describe "when the interpret_as is different" do
42
46
  it "should not be equal" do
43
- SayAs.new(:interpret_as => "Hello").should_not == SayAs.new(:interpret_as => "Hello there")
47
+ SayAs.new(doc, :interpret_as => "Hello").should_not == SayAs.new(doc, :interpret_as => "Hello there")
44
48
  end
45
49
  end
46
50
 
47
51
  describe "when the format is different" do
48
52
  it "should not be equal" do
49
- SayAs.new(:interpret_as => 'jp', :format => 'foo').should_not == SayAs.new(:interpret_as => 'jp', :format => 'bar')
53
+ SayAs.new(doc, :interpret_as => 'jp', :format => 'foo').should_not == SayAs.new(doc, :interpret_as => 'jp', :format => 'bar')
50
54
  end
51
55
  end
52
56
 
53
57
  describe "when the detail is different" do
54
58
  it "should not be equal" do
55
- SayAs.new(:interpret_as => 'jp', :detail => 'foo').should_not == SayAs.new(:interpret_as => 'jp', :detail => 'bar')
59
+ SayAs.new(doc, :interpret_as => 'jp', :detail => 'foo').should_not == SayAs.new(doc, :interpret_as => 'jp', :detail => 'bar')
56
60
  end
57
61
  end
58
62
  end
@@ -63,7 +67,7 @@ module RubySpeech
63
67
  end
64
68
 
65
69
  it "should raise InvalidChildError with non-acceptable objects" do
66
- lambda { subject << Voice.new }.should raise_error(InvalidChildError, "A SayAs can only accept Strings as children")
70
+ lambda { subject << Voice.new(doc) }.should raise_error(InvalidChildError, "A SayAs can only accept Strings as children")
67
71
  end
68
72
  end
69
73
  end # SayAs
@@ -3,13 +3,17 @@ require 'spec_helper'
3
3
  module RubySpeech
4
4
  module SSML
5
5
  describe Speak do
6
+ let(:doc) { Nokogiri::XML::Document.new }
7
+
8
+ subject { described_class.new doc }
9
+
6
10
  it { should be_a_valid_ssml_document }
7
11
 
8
12
  its(:name) { should == 'speak' }
9
13
  its(:language) { should == 'en-US' }
10
14
 
11
15
  describe "setting options in initializers" do
12
- subject { Speak.new :language => 'jp', :base_uri => 'blah' }
16
+ subject { Speak.new doc, :language => 'jp', :base_uri => 'blah' }
13
17
 
14
18
  its(:language) { should == 'jp' }
15
19
  its(:base_uri) { should == 'blah' }
@@ -44,33 +48,33 @@ module RubySpeech
44
48
 
45
49
  describe "comparing objects" do
46
50
  it "should be equal if the content, language and base uri are the same" do
47
- Speak.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there").should == Speak.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there")
51
+ Speak.new(doc, :language => 'en-GB', :base_uri => 'blah', :content => "Hello there").should == Speak.new(doc, :language => 'en-GB', :base_uri => 'blah', :content => "Hello there")
48
52
  end
49
53
 
50
54
  describe "when the content is different" do
51
55
  it "should not be equal" do
52
- Speak.new(:content => "Hello").should_not == Speak.new(:content => "Hello there")
56
+ Speak.new(doc, :content => "Hello").should_not == Speak.new(doc, :content => "Hello there")
53
57
  end
54
58
  end
55
59
 
56
60
  describe "when the language is different" do
57
61
  it "should not be equal" do
58
- Speak.new(:language => 'en-US').should_not == Speak.new(:language => 'en-GB')
62
+ Speak.new(doc, :language => 'en-US').should_not == Speak.new(doc, :language => 'en-GB')
59
63
  end
60
64
  end
61
65
 
62
66
  describe "when the base URI is different" do
63
67
  it "should not be equal" do
64
- Speak.new(:base_uri => 'foo').should_not == Speak.new(:base_uri => 'bar')
68
+ Speak.new(doc, :base_uri => 'foo').should_not == Speak.new(doc, :base_uri => 'bar')
65
69
  end
66
70
  end
67
71
 
68
72
  describe "when the children are different" do
69
73
  it "should not be equal" do
70
- s1 = Speak.new
71
- s1 << SayAs.new(:interpret_as => 'date')
72
- s2 = Speak.new
73
- s2 << SayAs.new(:interpret_as => 'time')
74
+ s1 = Speak.new doc
75
+ s1 << SayAs.new(doc, :interpret_as => 'date')
76
+ s2 = Speak.new doc
77
+ s2 << SayAs.new(doc, :interpret_as => 'time')
74
78
 
75
79
  s1.should_not == s2
76
80
  end
@@ -78,10 +82,10 @@ module RubySpeech
78
82
  end
79
83
 
80
84
  it "should allow creating child SSML elements" do
81
- s = Speak.new
85
+ s = Speak.new doc
82
86
  s.voice :gender => :male, :content => 'Hello'
83
- expected_s = Speak.new
84
- expected_s << Voice.new(:gender => :male, :content => 'Hello')
87
+ expected_s = Speak.new doc
88
+ expected_s << Voice.new(doc, :gender => :male, :content => 'Hello')
85
89
  s.should == expected_s
86
90
  end
87
91
 
@@ -91,47 +95,47 @@ module RubySpeech
91
95
  end
92
96
 
93
97
  it "should accept Audio" do
94
- lambda { subject << Audio.new }.should_not raise_error
98
+ lambda { subject << Audio.new(doc) }.should_not raise_error
95
99
  end
96
100
 
97
101
  it "should accept Break" do
98
- lambda { subject << Break.new }.should_not raise_error
102
+ lambda { subject << Break.new(doc) }.should_not raise_error
99
103
  end
100
104
 
101
105
  it "should accept Emphasis" do
102
- lambda { subject << Emphasis.new }.should_not raise_error
106
+ lambda { subject << Emphasis.new(doc) }.should_not raise_error
103
107
  end
104
108
 
105
109
  it "should accept Mark" do
106
- lambda { subject << Mark.new }.should_not raise_error
110
+ lambda { subject << Mark.new(doc) }.should_not raise_error
107
111
  end
108
112
 
109
113
  it "should accept P" do
110
- lambda { subject << P.new }.should_not raise_error
114
+ lambda { subject << P.new(doc) }.should_not raise_error
111
115
  end
112
116
 
113
117
  it "should accept Phoneme" do
114
- lambda { subject << Phoneme.new }.should_not raise_error
118
+ lambda { subject << Phoneme.new(doc) }.should_not raise_error
115
119
  end
116
120
 
117
121
  it "should accept Prosody" do
118
- lambda { subject << Prosody.new }.should_not raise_error
122
+ lambda { subject << Prosody.new(doc) }.should_not raise_error
119
123
  end
120
124
 
121
125
  it "should accept SayAs" do
122
- lambda { subject << SayAs.new(:interpret_as => :foo) }.should_not raise_error
126
+ lambda { subject << SayAs.new(doc, :interpret_as => :foo) }.should_not raise_error
123
127
  end
124
128
 
125
129
  it "should accept Sub" do
126
- lambda { subject << Sub.new }.should_not raise_error
130
+ lambda { subject << Sub.new(doc) }.should_not raise_error
127
131
  end
128
132
 
129
133
  it "should accept S" do
130
- lambda { subject << S.new }.should_not raise_error
134
+ lambda { subject << S.new(doc) }.should_not raise_error
131
135
  end
132
136
 
133
137
  it "should accept Voice" do
134
- lambda { subject << Voice.new }.should_not raise_error
138
+ lambda { subject << Voice.new(doc) }.should_not raise_error
135
139
  end
136
140
 
137
141
  it "should raise InvalidChildError with non-acceptable objects" do
@@ -146,19 +150,31 @@ module RubySpeech
146
150
  end
147
151
 
148
152
  it "should allow concatenation" do
149
- speak1 = Speak.new
150
- speak1 << Voice.new(:name => 'frank', :content => "Hi, I'm Frank")
151
- speak2 = Speak.new
152
- speak2 << "Hello there"
153
- speak2 << Voice.new(:name => 'millie', :content => "Hi, I'm Millie")
153
+ speak1 = SSML.draw do
154
+ voice :name => 'frank' do
155
+ "Hi, I'm Frank"
156
+ end
157
+ end
158
+ speak2 = SSML.draw do
159
+ string "Hello there"
160
+ voice :name => 'millie' do
161
+ "Hi, I'm Millie"
162
+ end
163
+ end
154
164
 
155
- expected_concat = Speak.new
156
- expected_concat << Voice.new(:name => 'frank', :content => "Hi, I'm Frank")
157
- expected_concat << "Hello there"
158
- expected_concat << Voice.new(:name => 'millie', :content => "Hi, I'm Millie")
165
+ expected_concat = SSML.draw do
166
+ voice :name => 'frank' do
167
+ "Hi, I'm Frank"
168
+ end
169
+ string "Hello there"
170
+ voice :name => 'millie' do
171
+ "Hi, I'm Millie"
172
+ end
173
+ end
159
174
 
160
175
  concat = (speak1 + speak2)
161
176
  concat.should == expected_concat
177
+ concat.document.root.should == concat
162
178
  concat.to_s.should_not include('default')
163
179
  end
164
180
  end # Speak