-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathgrammar_spec.rb
More file actions
56 lines (45 loc) · 1.58 KB
/
grammar_spec.rb
File metadata and controls
56 lines (45 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'spec_helper'
describe Pocketsphinx::Grammar::Jsgf do
it "raises an exception when neither a file or block are given" do
expect { Pocketsphinx::Grammar::Jsgf.new }.to raise_exception "Either a path or block is required to create a JSGF grammar"
end
context "reading a grammar from a file" do
let(:grammar_path) { grammar :goforward }
subject { Pocketsphinx::Grammar::Jsgf.new(grammar_path) }
it "reads a grammar from a file" do
expect(subject.raw.lines.count).to eq(15)
end
context "the grammar file is invalid" do
let(:grammar_path) { grammar :invalid }
it "raises an exception" do
expect { subject }.to raise_exception "Invalid JSGF grammar"
end
end
end
context "building a grammer from a block" do
subject do
Pocketsphinx::Grammar::Jsgf.new do
sentence "Go forward ten meters"
sentence "Go backward ten meters"
end
end
it "builds a grammar from a block" do
expect(subject.raw).to eq(File.read grammar(:sentences))
end
end
context "building a grammar from a string" do
it "stores the string" do
grammar = Pocketsphinx::Grammar::Jsgf.from_string("#JSGF V1.0;\ngrammar turtle;\npublic <turtle> = go forward ten meters;")
expect(grammar.raw.lines.count).to eq(3)
end
context "the grammar string is invalid" do
it "raises an exception" do
expect { Pocketsphinx::Grammar::Jsgf.from_string("") }.to raise_exception "Invalid JSGF grammar"
end
end
end
private
def grammar(name)
"spec/assets/grammars/#{name}.gram"
end
end