From 45aeb3ca204fed03ae8f76e3658b9466b2cf5798 Mon Sep 17 00:00:00 2001 From: Will Drexler Date: Fri, 20 Jun 2014 14:43:14 -0400 Subject: [PATCH] Add specs to cover method calls inside nested blocks --- spec/ruby_speech/grxml_spec.rb | 40 +++++++++++++++++++++++++--------- spec/ruby_speech/ssml_spec.rb | 29 +++++++++++++++++++----- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/spec/ruby_speech/grxml_spec.rb b/spec/ruby_speech/grxml_spec.rb index f36038e..3343c1c 100644 --- a/spec/ruby_speech/grxml_spec.rb +++ b/spec/ruby_speech/grxml_spec.rb @@ -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 diff --git a/spec/ruby_speech/ssml_spec.rb b/spec/ruby_speech/ssml_spec.rb index 5dc4bb9..9a3adb1 100644 --- a/spec/ruby_speech/ssml_spec.rb +++ b/spec/ruby_speech/ssml_spec.rb @@ -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