Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance methods are not usable inside grammars #32

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions spec/ruby_speech/grxml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,39 @@ module RubySpeech
drawn_doc.should == expected_doc
end

it "should allow accessing methods defined outside the block" do
def foo
'bar'
end
context 'accessing methods defined outside the block' do

it 'should be allowed at the top level' do
def foo
'bar'
end
drawn_doc = GRXML.draw do
rule id: foo
end

drawn_doc = GRXML.draw do
rule :id => foo
expected_doc = GRXML::Grammar.new doc
rule = GRXML::Rule.new(doc, id: foo)
expected_doc << rule
drawn_doc.should == expected_doc
end

expected_doc = GRXML::Grammar.new doc
rule = GRXML::Rule.new(doc, :id => foo)
expected_doc << rule
drawn_doc.should == expected_doc
it 'should be allowed inside nested blocks' do
def foo
'bar'
end
drawn_doc = GRXML.draw do
rule id: 'root' do
item { foo }
end
end

expected_doc = GRXML::Grammar.new doc
rule = GRXML::Rule.new(doc, id: 'root')
item = GRXML::Item.new(doc, content: foo)
rule << item
expected_doc << rule
drawn_doc.should == expected_doc
end
end

it "should raise error if given an empty rule" do
Expand Down
29 changes: 24 additions & 5 deletions spec/ruby_speech/ssml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,32 @@ module RubySpeech
drawn_doc.should == expected_doc
end

it "should allow accessing methods defined outside the block" do
def foo
'bar'
context 'accessing methods defined outside the block' do
it 'should be allowed at the top level' do
def foo
'bar'
end

expected_doc = SSML::Speak.new doc, content: foo
SSML.draw { string foo }.should == expected_doc
end

expected_doc = SSML::Speak.new doc, :content => foo
SSML.draw { string foo }.should == expected_doc
it 'should be allowed inside a nested block' do
def foo
'bar'
end

drawn_doc = SSML.draw do
phoneme alphabet: 'x-sampa', ph: 'b}r' do
string foo
end
end

expected_doc = SSML::Speak.new doc
phoneme = SSML::Phoneme.new doc, alphabet: 'x-sampa', ph: 'b}r', content: foo
expected_doc << phoneme
drawn_doc.should == expected_doc
end
end

describe 'cloning' do
Expand Down