pidgin2adium 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +22 -0
- data/.gitignore +7 -0
- data/{History.txt → ChangeLog} +11 -0
- data/Gemfile +1 -9
- data/README.rdoc +38 -39
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/bin/pidgin2adium +63 -54
- data/ext/balance_tags_c/balance_tags_c.c +161 -161
- data/lib/pidgin2adium.rb +97 -97
- data/lib/pidgin2adium/balance_tags.rb +2 -2
- data/lib/pidgin2adium/basic_parser.rb +412 -0
- data/lib/pidgin2adium/html_log_parser.rb +125 -0
- data/lib/pidgin2adium/log_converter.rb +12 -13
- data/lib/pidgin2adium/log_file.rb +1 -1
- data/lib/pidgin2adium/log_parser.rb +3 -618
- data/lib/pidgin2adium/message.rb +97 -0
- data/lib/pidgin2adium/text_log_parser.rb +39 -0
- data/pidgin2adium.gemspec +31 -9
- data/spec/balance_tags_c_extn_spec.rb +47 -0
- data/spec/basic_parser_spec.rb +217 -0
- data/spec/html_log_parser_spec.rb +150 -0
- data/spec/log_converter_spec.rb +48 -0
- data/spec/log_file_spec.rb +168 -0
- data/spec/logfiles/2006-12-21.223606.txt +3 -0
- data/spec/logfiles/2008-01-15.071445-0500PST.htm +5 -0
- data/spec/logfiles/2008-01-15.071445-0500PST.html +5 -0
- data/spec/pidgin2adium_spec.rb +248 -3
- data/spec/spec_helper.rb +69 -16
- data/spec/test-output/README.md +1 -0
- data/spec/test-output/html_log_output.xml +6 -0
- data/spec/test-output/text_log_output.xml +4 -0
- data/spec/text_log_parser_spec.rb +42 -0
- data/tasks/extconf/balance_tags_c.rake +5 -1
- metadata +40 -26
- data/bin/pidgin2adium_profiler +0 -1
- data/tasks/build_profiler.rake +0 -49
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "HtmlLogParser" do
|
4
|
+
before(:each) do
|
5
|
+
# @year, @am, and @pm are not required. @time is.
|
6
|
+
# So @year + @time is a valid time,
|
7
|
+
# as is @time, and @year + @time + @am.
|
8
|
+
@year = '2007-10-28 '
|
9
|
+
@time = '4:46:20'
|
10
|
+
@am = ' AM'
|
11
|
+
@pm = ' PM'
|
12
|
+
@hlp = Pidgin2Adium::HtmlLogParser.new(@html_logfile_path,
|
13
|
+
@aliases)
|
14
|
+
@clean = "clean"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have Pidgin2Adium.balance_tags_c available" do
|
18
|
+
Pidgin2Adium.should respond_to(:balance_tags_c)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#cleanup" do
|
22
|
+
it "should remove html, body, and font tags" do
|
23
|
+
dirty_text = %Q{<html><body type="ichat"><font color="red">#{@clean}</font></body></html>}
|
24
|
+
@hlp.cleanup(dirty_text).should == @clean
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should remove those weird <FONT HSPACE> tags" do
|
28
|
+
dirty = %Q{</FONT HSPACE='2'>#{@clean}}
|
29
|
+
@hlp.cleanup(dirty).should == @clean
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should remove \\r" do
|
33
|
+
dirty = [@clean, @clean, @clean].join("\r")
|
34
|
+
@hlp.cleanup(dirty).should == @clean * 3
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should remove empty lines" do
|
38
|
+
dirty = "#{@clean}\n\n"
|
39
|
+
@hlp.cleanup(dirty).should == @clean
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should replace newlines with <br/>" do
|
43
|
+
dirty = "\n#{@clean}"
|
44
|
+
@hlp.cleanup(dirty).should == "<br/>#{@clean}"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should remove empty links" do
|
48
|
+
dirty = %Q{<a href="awesomelink"> </a>#{@clean}}
|
49
|
+
dirty += %Q{<a href='awesomelink'></a>#{@clean}}
|
50
|
+
@hlp.cleanup(dirty).should == @clean + @clean
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "with <span>s" do
|
54
|
+
it "should remove font-family" do
|
55
|
+
dirty = %Q{<span style='font-family: Helvetica;'>#{@clean}</span>}
|
56
|
+
@hlp.cleanup(dirty).should == @clean
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should remove font-size" do
|
60
|
+
dirty = %Q{<span style="font-size: 6;">#{@clean}</span>}
|
61
|
+
@hlp.cleanup(dirty).should == @clean
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should remove background" do
|
65
|
+
dirty = %Q{<span style="background: #00afaf;">#{@clean}</span>}
|
66
|
+
@hlp.cleanup(dirty).should == @clean
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should remove color=#00000" do
|
70
|
+
dirty = %Q{<span style="color: #000000;">#{@clean}</span>}
|
71
|
+
@hlp.cleanup(dirty).should == @clean
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not remove color != #00000" do
|
75
|
+
dirty = %Q{<span style="color: #01ABcdef;">#{@clean}</span>}
|
76
|
+
@hlp.cleanup(dirty).should == dirty
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should remove improperly-formatted colors" do
|
80
|
+
dirty = %Q{<span style="color: #0;">#{@clean}</span>}
|
81
|
+
@hlp.cleanup(dirty).should == @clean
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should replace <em> with italic font-style" do
|
85
|
+
dirty = "<em>#{@clean}</em>"
|
86
|
+
clean = %Q{<span style="font-style: italic;">#{@clean}</span>}
|
87
|
+
@hlp.cleanup(dirty).should == clean
|
88
|
+
end
|
89
|
+
|
90
|
+
it "shouldn't modify clean text" do
|
91
|
+
@hlp.cleanup(@clean).should == @clean
|
92
|
+
end
|
93
|
+
|
94
|
+
# This implicitly tests a lot of other things, but they've been tested
|
95
|
+
# before this too.
|
96
|
+
it "should remove a trailing space after style declaration and replace double quotes" do
|
97
|
+
dirty_span_open = "<span style='color: #afaf00; font-size: 14pt; font-weight: bold; '>"
|
98
|
+
# Replaced double quotes, removed space before ">"
|
99
|
+
clean_span_open = '<span style="color: #afaf00;">'
|
100
|
+
dirty = dirty_span_open + @clean + "</span>"
|
101
|
+
@hlp.cleanup(dirty).should == clean_span_open + @clean + "</span>"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#parse" do
|
107
|
+
before(:each) do
|
108
|
+
@logfile = @hlp.parse()
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should return a LogFile instance" do
|
112
|
+
@logfile.should be_instance_of(Pidgin2Adium::LogFile)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should return a LogFile with the correct number of chat_lines" do
|
116
|
+
@logfile.chat_lines.size.should == 3
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return a LogFile with the correct message type" do
|
120
|
+
@logfile.chat_lines.map{|x| x.class }.should == [Pidgin2Adium::XMLMessage] * 3
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return a LogFile with the correct data" do
|
124
|
+
first_msg = @logfile.chat_lines[0]
|
125
|
+
second_msg = @logfile.chat_lines[1]
|
126
|
+
third_msg = @logfile.chat_lines[2]
|
127
|
+
|
128
|
+
first_msg.sender.should == "aolsystemmsg"
|
129
|
+
first_msg.buddy_alias.should == "AOL System Msg"
|
130
|
+
# Use regex to ignore time zone
|
131
|
+
first_msg.time.should =~ /^2008-01-15T07:14:45[-+]\d{2}00$/
|
132
|
+
# This fails due to balance_tags_c().
|
133
|
+
good_body = %Q{Your screen name (otherSN) is now signed into AOL(R) Instant Messenger (TM) in 2 locations.} + " " +
|
134
|
+
%Q{To sign off the other location(s), reply to this message with the number 1.} + " " +
|
135
|
+
%Q{Click <a href="http://www.aim.com/password/routing.adp">here</a> for more information.}
|
136
|
+
first_msg.body.should == good_body
|
137
|
+
|
138
|
+
second_msg.sender.should == "othersn"
|
139
|
+
second_msg.buddy_alias.should == "Gabe B-W"
|
140
|
+
second_msg.time.should =~ /^2008-01-15T07:14:48[-+]\d{2}00$/
|
141
|
+
second_msg.body.should == "1"
|
142
|
+
|
143
|
+
third_msg.sender.should == "aolsystemmsg"
|
144
|
+
third_msg.buddy_alias.should == "AOL System Msg"
|
145
|
+
# Use regex to ignore time zone
|
146
|
+
third_msg.time.should =~ /^2008-01-15T07:14:48[-+]\d{2}00$/
|
147
|
+
third_msg.body.should == "Your other AIM sessions have been signed-off. You are now signed-on from 1 location(s)."
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pidgin2adium/log_converter'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
describe "LogConverter" do
|
6
|
+
before(:each) do
|
7
|
+
@converter = Pidgin2Adium::LogConverter.new(@logfile_path,
|
8
|
+
@aliases,
|
9
|
+
{ :output_dir => @output_dir })
|
10
|
+
Pidgin2Adium::LogConverter.stub!(:puts).and_return(nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "with non-existent input dir" do
|
14
|
+
it "should raise ENOENT with correct error message" do
|
15
|
+
lambda do
|
16
|
+
converter = Pidgin2Adium::LogConverter.new("nonexistent-dir",
|
17
|
+
@aliases)
|
18
|
+
end.should raise_error(Errno::ENOENT)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have correct output when files don't exist" do
|
23
|
+
FileUtils.rm_f(File.join(@output_dir, '*'))
|
24
|
+
# Will only convert 2 files because the .htm file == the .html file
|
25
|
+
Pidgin2Adium.should_receive(:log_msg).with(/Converted 2 files of 3 total/)
|
26
|
+
@converter.start()
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have correct output when files do exist" do
|
30
|
+
@converter.start() # create files
|
31
|
+
Pidgin2Adium.should_receive(:log_msg).with(/Converted 0 files of 3 total/)
|
32
|
+
@converter.start()
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#get_all_chat_files" do
|
36
|
+
it "should return correct listings" do
|
37
|
+
files = @converter.get_all_chat_files
|
38
|
+
dir = File.join(File.dirname(File.expand_path(__FILE__)),
|
39
|
+
'logfiles')
|
40
|
+
|
41
|
+
expected_files = %w{2006-12-21.223606.txt
|
42
|
+
2008-01-15.071445-0500PST.htm
|
43
|
+
2008-01-15.071445-0500PST.html}.map!{|f| File.join(dir, f) }
|
44
|
+
|
45
|
+
files.sort.should == expected_files.sort
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "LogFile" do
|
4
|
+
before(:each) do
|
5
|
+
@user_SN = "gabebw"
|
6
|
+
@user_alias = "Gabe B-W"
|
7
|
+
|
8
|
+
@partner_SN = "matz"
|
9
|
+
@partner_alias = "Yukihiro Matsumoto"
|
10
|
+
|
11
|
+
@start_time = "2010-08-10T22:55:07-0500"
|
12
|
+
times = [@start_time,
|
13
|
+
"2010-08-10T22:55:12-0500",
|
14
|
+
"2010-08-10T22:55:17-0500",
|
15
|
+
"2010-08-10T22:55:22-0500"]
|
16
|
+
|
17
|
+
@messages = [
|
18
|
+
Pidgin2Adium::XMLMessage.new(@user_SN,
|
19
|
+
@start_time,
|
20
|
+
@user_alias,
|
21
|
+
"Hello!"),
|
22
|
+
Pidgin2Adium::StatusMessage.new(@partner_SN,
|
23
|
+
times[1],
|
24
|
+
@partner_alias,
|
25
|
+
"Matz has gone away"),
|
26
|
+
Pidgin2Adium::Event.new(@user_SN,
|
27
|
+
times[2],
|
28
|
+
@user_alias,
|
29
|
+
"gabebw logged in.",
|
30
|
+
'online'),
|
31
|
+
Pidgin2Adium::AutoReplyMessage.new(@partner_SN,
|
32
|
+
times[3],
|
33
|
+
@partner_alias,
|
34
|
+
"This is an away message")
|
35
|
+
]
|
36
|
+
@logfile = Pidgin2Adium::LogFile.new(@messages,
|
37
|
+
'aim',
|
38
|
+
@user_SN,
|
39
|
+
@partner_SN,
|
40
|
+
@start_time)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "attributes" do
|
44
|
+
it "should have chat_lines readable" do
|
45
|
+
@logfile.should respond_to(:chat_lines)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have service readable" do
|
49
|
+
@logfile.should respond_to(:service)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have user_SN readable" do
|
53
|
+
@logfile.should respond_to(:user_SN)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have partner_SN readable" do
|
57
|
+
@logfile.should respond_to(:partner_SN)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have adium_chat_time_start readable" do
|
61
|
+
@logfile.should respond_to(:adium_chat_time_start)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#to_s" do
|
66
|
+
it "should return the correct string" do
|
67
|
+
output = @logfile.to_s
|
68
|
+
output.should == @messages.map{|m| m.to_s}.join
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#each" do
|
73
|
+
it "should yield the messages" do
|
74
|
+
n = 0
|
75
|
+
@logfile.each do |x|
|
76
|
+
x.should == @messages[n]
|
77
|
+
n += 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#write_out" do
|
83
|
+
before(:each) do
|
84
|
+
@output_file_path = File.join(@output_dir,
|
85
|
+
'AIM.gabebw',
|
86
|
+
'matz',
|
87
|
+
"matz (#{@start_time}).chatlog",
|
88
|
+
"matz (#{@start_time}).xml")
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "when file does not exist" do
|
92
|
+
before(:each) do
|
93
|
+
FileUtils.rm_r(File.join(@output_dir, 'AIM.gabebw'),
|
94
|
+
:force => true)
|
95
|
+
@output_file = @logfile.write_out(false, @output_dir)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should write out the correct content" do
|
99
|
+
IO.read(@output_file).include?(@logfile.to_s).should be_true
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should write out the correct header" do
|
103
|
+
header = sprintf('<?xml version="1.0" encoding="UTF-8" ?>'+"\n"+
|
104
|
+
'<chat xmlns="http://purl.org/net/ulf/ns/0.4-02" account="gabebw" service="AIM">'+"\n")
|
105
|
+
IO.read(@output_file).should =~ /^#{Regexp.escape(header)}/
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should write out the closing </chat> tag" do
|
109
|
+
IO.read(@output_file).should =~ %r{</chat>$}
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should write to the correct path" do
|
113
|
+
@output_file.should == @output_file_path
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "when file exists" do
|
118
|
+
before(:each) do
|
119
|
+
FileUtils.mkdir_p(File.dirname(@output_file_path))
|
120
|
+
File.new(@output_file_path, 'w').close
|
121
|
+
end
|
122
|
+
it "should return FILE_EXISTS" do
|
123
|
+
output_file = @logfile.write_out(false, @output_dir)
|
124
|
+
output_file.should == Pidgin2Adium::FILE_EXISTS
|
125
|
+
end
|
126
|
+
it "should return output file path if overwrite is true" do
|
127
|
+
output_file = @logfile.write_out(true, @output_dir)
|
128
|
+
output_file.should == @output_file_path
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "permissions problems" do
|
133
|
+
describe "with output dir" do
|
134
|
+
before(:each) do
|
135
|
+
FileUtils.rm_r(@output_dir, :force => true)
|
136
|
+
`chmod -w #{File.dirname(@output_dir)}`
|
137
|
+
end
|
138
|
+
|
139
|
+
after(:each) do
|
140
|
+
`chmod +w #{File.dirname(@output_dir)}`
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should return false if it can't create the output dir" do
|
144
|
+
@logfile.write_out(false, @output_dir).should be_false
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "with output file" do
|
149
|
+
before(:each) do
|
150
|
+
# Make parent dir unwriteable because creating the
|
151
|
+
# file itself and making it unwriteable returns
|
152
|
+
# FILE_EXISTS
|
153
|
+
@output_file_parent_dir = File.dirname(@output_file_path)
|
154
|
+
FileUtils.mkdir_p(@output_file_parent_dir)
|
155
|
+
`chmod -w '#{@output_file_parent_dir}'`
|
156
|
+
end
|
157
|
+
|
158
|
+
after(:each) do
|
159
|
+
`chmod +w '#{@output_file_parent_dir}'`
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return false if it can't open the output file for writing" do
|
163
|
+
@logfile.write_out(false, @output_dir).should be_false
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Conversation with aolsystemmsg at 1/15/2008 7:14:45 AM on otherSN (aim)</title></head><h3>Conversation with aolsystemmsg at 1/15/2008 7:14:45 AM on otherSN (aim)</h3>
|
2
|
+
<font color="#A82F2F"><font size="2">(2008-01-15 07:14:45)</font> <b>AOL System Msg:</b></font> Your screen name (otherSN) is now signed into AOL(R) Instant Messenger (TM) in 2 locations. To sign off the other location(s), reply to this message with the number 1. Click <a href='http://www.aim.com/password/routing.adp'>here</a> for more information.<br/>
|
3
|
+
<font color="#16569E"><font size="2">(2008-01-15 07:14:48)</font> <b>Gabe B-W:</b></font> <span style='color: #000000;'>1</span><br/>
|
4
|
+
<font color="#A82F2F"><font size="2">(2008-01-15 07:14:48)</font> <b>AOL System Msg:</b></font> Your other AIM sessions have been signed-off. You are now signed-on from 1 location(s).<br/>
|
5
|
+
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Conversation with aolsystemmsg at 1/15/2008 7:14:45 AM on otherSN (aim)</title></head><h3>Conversation with aolsystemmsg at 1/15/2008 7:14:45 AM on otherSN (aim)</h3>
|
2
|
+
<font color="#A82F2F"><font size="2">(2008-01-15 07:14:45)</font> <b>AOL System Msg:</b></font> Your screen name (otherSN) is now signed into AOL(R) Instant Messenger (TM) in 2 locations. To sign off the other location(s), reply to this message with the number 1. Click <a href='http://www.aim.com/password/routing.adp'>here</a> for more information.<br/>
|
3
|
+
<font color="#16569E"><font size="2">(2008-01-15 07:14:48)</font> <b>Gabe B-W:</b></font> <span style='color: #000000;'>1</span><br/>
|
4
|
+
<font color="#A82F2F"><font size="2">(2008-01-15 07:14:48)</font> <b>AOL System Msg:</b></font> Your other AIM sessions have been signed-off. You are now signed-on from 1 location(s).<br/>
|
5
|
+
|
data/spec/pidgin2adium_spec.rb
CHANGED
@@ -1,7 +1,252 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
3
|
+
describe "Pidgin2Adium" do
|
4
|
+
before(:all) do
|
5
|
+
@nonexistent_logfile_path = "./nonexistent_logfile_path/"
|
6
6
|
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
# "Kernel gets mixed in to an object, so you need to stub [its methods] on the object
|
10
|
+
# itself." - http://www.ruby-forum.com/topic/128619
|
11
|
+
Pidgin2Adium.stub!(:puts).and_return(nil) # Doesn't work in the before(:all) block
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "constants" do
|
15
|
+
it "should set ADIUM_LOG_DIR correctly" do
|
16
|
+
Pidgin2Adium::ADIUM_LOG_DIR.should == File.expand_path('~/Library/Application Support/Adium 2.0/Users/Default/Logs/') + '/'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should set BAD_DIRS correctly" do
|
20
|
+
Pidgin2Adium::BAD_DIRS.should == %w{. .. .DS_Store Thumbs.db .system}
|
21
|
+
end
|
22
|
+
end # constants
|
23
|
+
|
24
|
+
describe "utility methods" do
|
25
|
+
before(:each) do
|
26
|
+
Pidgin2Adium.stub!(:log_msg).and_return(nil)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "::oops()" do
|
30
|
+
it "should add a message to @@oops_messages" do
|
31
|
+
message = "Oops! I messed up!"
|
32
|
+
Pidgin2Adium.oops(message)
|
33
|
+
Pidgin2Adium.send(:class_variable_get, :@@oops_messages).include?(message).should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "::error()" do
|
38
|
+
it "should add a message to @@error_messages" do
|
39
|
+
err_message = "Error! I *really* messed up!"
|
40
|
+
Pidgin2Adium.error(err_message)
|
41
|
+
Pidgin2Adium.send(:class_variable_get, :@@error_messages).include?(err_message).should be_true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#delete_search_indexes" do
|
46
|
+
before(:each) do
|
47
|
+
@dirty_file = File.expand_path("~/Library/Caches/Adium/Default/DirtyLogs.plist")
|
48
|
+
@log_index_file = File.expand_path("~/Library/Caches/Adium/Default/Logs.index")
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "when search indices exist" do
|
52
|
+
before(:each) do
|
53
|
+
`touch #{@dirty_file}`
|
54
|
+
`touch #{@log_index_file}`
|
55
|
+
end
|
56
|
+
|
57
|
+
after(:each) do
|
58
|
+
# Recreate search indices
|
59
|
+
`touch #{@dirty_file}`
|
60
|
+
`touch #{@log_index_file}`
|
61
|
+
[@dirty_file, @log_index_file].each do |f|
|
62
|
+
`chmod +w #{f}` # make writeable
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should delete the search indices when they are writeable" do
|
67
|
+
[@dirty_file, @log_index_file].each do |f|
|
68
|
+
`chmod +w #{f}` # make writeable
|
69
|
+
end
|
70
|
+
Pidgin2Adium.delete_search_indexes()
|
71
|
+
File.exist?(@dirty_file).should be_false
|
72
|
+
File.exist?(@log_index_file).should be_false
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should give an error message when they are not writable" do
|
76
|
+
[@dirty_file, @log_index_file].each do |f|
|
77
|
+
`chmod -w #{f}` # make unwriteable
|
78
|
+
end
|
79
|
+
Pidgin2Adium.should_receive(:error).with("File exists but is not writable. Please delete it yourself: #{@dirty_file}")
|
80
|
+
Pidgin2Adium.should_receive(:error).with("File exists but is not writable. Please delete it yourself: #{@log_index_file}")
|
81
|
+
Pidgin2Adium.should_receive(:log_msg).with("...done.")
|
82
|
+
Pidgin2Adium.should_receive(:log_msg).with("When you next start the Adium Chat Transcript Viewer, " +
|
83
|
+
"it will re-index the logs, which may take a while.")
|
84
|
+
Pidgin2Adium.delete_search_indexes()
|
85
|
+
File.exist?(@dirty_file).should be_true
|
86
|
+
File.exist?(@log_index_file).should be_true
|
87
|
+
end
|
88
|
+
end # when search indices exist
|
89
|
+
end # delete_search_indexes
|
90
|
+
end # utility methods
|
91
|
+
|
92
|
+
describe "#parse" do
|
93
|
+
describe "failure" do
|
94
|
+
before(:each) do
|
95
|
+
@weird_logfile_path = File.join(@current_dir, 'logfile.foobar')
|
96
|
+
end
|
97
|
+
it "should give an error when file is not text or html" do
|
98
|
+
Pidgin2Adium.should_receive(:error).with(/Doing nothing, logfile is not a text or html file/)
|
99
|
+
Pidgin2Adium.parse(@weird_logfile_path, @aliases).should be_false
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should gracefully handle nonexistent files" do
|
103
|
+
Pidgin2Adium.parse("i_do_not_exist.html", @aliases).should be_false
|
104
|
+
Pidgin2Adium.parse("i_do_not_exist.txt", @aliases).should be_false
|
105
|
+
end
|
106
|
+
end # failure
|
107
|
+
|
108
|
+
describe "success" do
|
109
|
+
context "for a text file" do
|
110
|
+
specify { Pidgin2Adium.parse(@text_logfile_path, @aliases).should be_instance_of(Pidgin2Adium::LogFile) }
|
111
|
+
end
|
112
|
+
context "for an htm file" do
|
113
|
+
specify { Pidgin2Adium.parse(@htm_logfile_path, @aliases).should be_instance_of(Pidgin2Adium::LogFile) }
|
114
|
+
end
|
115
|
+
context "for an html file" do
|
116
|
+
specify { Pidgin2Adium.parse(@html_logfile_path, @aliases).should be_instance_of(Pidgin2Adium::LogFile) }
|
117
|
+
end
|
118
|
+
end # success
|
119
|
+
end # parse
|
120
|
+
|
121
|
+
describe "#parse_and_generate" do
|
122
|
+
before(:each) do
|
123
|
+
# text logfile has screenname awesomeSN,
|
124
|
+
# and html logfiles have screenname otherSN
|
125
|
+
@text_output_file_path = File.join(@output_dir,
|
126
|
+
"AIM.awesomeSN",
|
127
|
+
"BUDDY_PERSON",
|
128
|
+
"BUDDY_PERSON (2006-12-21T22.36.06-0700).chatlog",
|
129
|
+
"BUDDY_PERSON (2006-12-21T22.36.06-0700).xml")
|
130
|
+
@htm_output_file_path = File.join(@output_dir,
|
131
|
+
"AIM.otherSN",
|
132
|
+
"aolsystemmsg",
|
133
|
+
"aolsystemmsg (2008-01-15T07.14.45-0500).chatlog",
|
134
|
+
"aolsystemmsg (2008-01-15T07.14.45-0500).xml")
|
135
|
+
@html_output_file_path = @htm_output_file_path
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "failure" do
|
139
|
+
describe "when output_dir does not exist" do
|
140
|
+
before(:each) do
|
141
|
+
@opts = { :output_dir => @nonexistent_output_dir }
|
142
|
+
FileUtils.rm_r(@nonexistent_output_dir, :force => true)
|
143
|
+
end
|
144
|
+
|
145
|
+
after(:each) do
|
146
|
+
# In case the test fails
|
147
|
+
`chmod +w #{@current_dir}`
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should return false when it can't create the output dir" do
|
151
|
+
`chmod -w #{@current_dir}` # prevent creation of output_dir
|
152
|
+
Pidgin2Adium.parse_and_generate(@text_logfile_path,
|
153
|
+
@aliases,
|
154
|
+
@opts).should be_false
|
155
|
+
`chmod +w #{@current_dir}`
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "when output_dir does exist" do
|
160
|
+
before(:each) do
|
161
|
+
@opts = { :output_dir => @output_dir }
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "when file already exists" do
|
165
|
+
describe "when :force is not set" do
|
166
|
+
context "for a text file" do
|
167
|
+
before(:each) do
|
168
|
+
FileUtils.mkdir_p(File.dirname(@text_output_file_path))
|
169
|
+
File.new(@text_output_file_path, 'w').close # create file
|
170
|
+
end
|
171
|
+
it "should return FILE_EXISTS" do
|
172
|
+
Pidgin2Adium.parse_and_generate(@text_logfile_path,
|
173
|
+
@aliases,
|
174
|
+
@opts).should == Pidgin2Adium::FILE_EXISTS
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "for an HTM file" do
|
179
|
+
before(:each) do
|
180
|
+
FileUtils.mkdir_p(File.dirname(@htm_output_file_path))
|
181
|
+
File.new(@htm_output_file_path, 'w').close # create file
|
182
|
+
end
|
183
|
+
it "should return FILE_EXISTS" do
|
184
|
+
Pidgin2Adium.parse_and_generate(@htm_logfile_path,
|
185
|
+
@aliases,
|
186
|
+
@opts).should == Pidgin2Adium::FILE_EXISTS
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "for an HTML file" do
|
191
|
+
before(:each) do
|
192
|
+
FileUtils.mkdir_p(File.dirname(@html_output_file_path))
|
193
|
+
File.new(@html_output_file_path, 'w').close # create file
|
194
|
+
end
|
195
|
+
it "should return FILE_EXISTS" do
|
196
|
+
Pidgin2Adium.parse_and_generate(@html_logfile_path,
|
197
|
+
@aliases,
|
198
|
+
@opts).should == Pidgin2Adium::FILE_EXISTS
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end # failure
|
205
|
+
|
206
|
+
describe "success" do
|
207
|
+
describe "when output_dir does not exist" do
|
208
|
+
before(:each) do
|
209
|
+
@opts = { :output_dir => @nonexistent_output_dir }
|
210
|
+
FileUtils.rm_r(@nonexistent_output_dir, :force => true)
|
211
|
+
end
|
212
|
+
|
213
|
+
context "for a text file" do
|
214
|
+
specify { Pidgin2Adium.parse_and_generate(@text_logfile_path, @aliases, @opts).should be_true }
|
215
|
+
end
|
216
|
+
context "for an htm file" do
|
217
|
+
specify { Pidgin2Adium.parse_and_generate(@htm_logfile_path, @aliases, @opts).should be_true }
|
218
|
+
end
|
219
|
+
context "for an html file" do
|
220
|
+
specify { Pidgin2Adium.parse_and_generate(@html_logfile_path, @aliases, @opts).should be_true }
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "when output_dir does exist" do
|
225
|
+
before(:each) do
|
226
|
+
@opts = { :output_dir => @output_dir }
|
227
|
+
end
|
228
|
+
context "for a text file" do
|
229
|
+
specify do
|
230
|
+
Pidgin2Adium.parse_and_generate(@text_logfile_path,
|
231
|
+
@aliases,
|
232
|
+
@opts).should be_true
|
233
|
+
end
|
234
|
+
end
|
235
|
+
context "for an htm file" do
|
236
|
+
specify do
|
237
|
+
Pidgin2Adium.parse_and_generate(@htm_logfile_path,
|
238
|
+
@aliases,
|
239
|
+
@opts).should be_true
|
240
|
+
end
|
241
|
+
end
|
242
|
+
context "for an html file" do
|
243
|
+
specify do
|
244
|
+
Pidgin2Adium.parse_and_generate(@html_logfile_path,
|
245
|
+
@aliases,
|
246
|
+
@opts).should be_true
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end # success
|
251
|
+
end # parse_and_generate
|
7
252
|
end
|