forked from thoughtbot/shakespeare_analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macbeth_analyzer_spec.rb
61 lines (56 loc) · 1.89 KB
/
macbeth_analyzer_spec.rb
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
57
58
59
60
require 'minitest'
require 'minitest/autorun'
require_relative 'lib/macbeth_analyzer'
class TestMacbethAnalyzer < MiniTest::Test
describe '#load_file' do
def setup
@ma = MacbethAnalyzer.new
end
def test_load_file
xml_doc = @ma.load_file
refute_nil(xml_doc)
end
def test_load_file_2
xml_doc = @ma.load_file
assert xml_doc.instance_of?(Nokogiri::HTML::Document), "Expected #{xml_doc.inspect} to be an instance of #{Nokogiri::HTML::Document}, not #{xml_doc.class}"
end
end
describe "#parse_counts" do
def setup
@ma = MacbethAnalyzer.new
end
def test_parse_returns_one_speaker
line_count = @ma.parse_counts(Nokogiri::XML("<scene><speech><speaker>A</speaker><line>B</line></speech></scene>"))
assert_equal( line_count.count, 1 )
end
def test_parse_returns_one_speaker_one_line
line_count = @ma.parse_counts(Nokogiri::XML("<scene><speech><speaker>A</speaker><line>B</line></speech></scene>"))
assert_equal( line_count["A"], 1 )
end
def test_parse_returns_one_speaker_two_lines
line_count = @ma.parse_counts(Nokogiri::XML("<scene><speech><speaker>A</speaker><line>B</line><line>C</line></speech></scene>"))
assert_equal( line_count["A"], 2 )
end
def test_parse_returns_two_speakers
line_count = @ma.parse_counts(Nokogiri::XML("<scene><speech><speaker>A</speaker><line>B</line></speech><speech><speaker>C</speaker><line>D</line></speech></scene>"))
assert_equal( line_count.count, 2 )
end
end
describe "#display" do
def setup
@ma = MacbethAnalyzer.new
end
def test_display
output = capture_io do
@ma.display({'A' => 1})
end
assert_equal ["1 A\n",""], output
end
def test_display_sort
output = capture_io do
@ma.display({'A' => 1, 'B' => 2})
end
assert_equal ["2 B\n1 A\n", ""], output
end
end
end