runoff 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/.gitignore +17 -17
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +42 -45
- data/Rakefile +7 -7
- data/bin/runoff +34 -7
- data/lib/runoff/commands/all.rb +36 -0
- data/lib/runoff/commands/chat.rb +37 -0
- data/lib/runoff/commands/command.rb +85 -0
- data/lib/runoff/composition.rb +105 -103
- data/lib/runoff/file_writer.rb +53 -132
- data/lib/runoff/location.rb +39 -60
- data/lib/runoff/skype_data_format.rb +104 -0
- data/lib/runoff/version.rb +2 -2
- data/lib/runoff.rb +10 -7
- data/runoff.gemspec +26 -26
- data/test/all_test.rb +25 -0
- data/test/chat_test.rb +9 -0
- data/test/command_test.rb +29 -0
- data/test/{runoff_composition_test.rb → composition_test.rb} +52 -55
- data/test/file_writer_test.rb +80 -0
- data/test/{runoff_locations_test.rb → location_test.rb} +18 -30
- data/test/skype_data_format_test.rb +70 -0
- metadata +25 -16
- data/lib/runoff/source.rb +0 -171
- data/test/runoff_file_writer_test.rb +0 -115
- data/test/runoff_source_test.rb +0 -35
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'minitest/unit'
|
2
|
+
require 'runoff'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
describe Runoff::FileWriter do
|
6
|
+
before do
|
7
|
+
@incorrect_chat_record = {
|
8
|
+
chatname: '#john/$;521357125362',
|
9
|
+
timestamp: 1366280218,
|
10
|
+
from_dispname: 'Aidzis',
|
11
|
+
body_xml: 'This is a text'
|
12
|
+
}
|
13
|
+
|
14
|
+
@chat_record = {
|
15
|
+
chatname: '#braun/$drake;521357125362',
|
16
|
+
timestamp: 1366280218,
|
17
|
+
from_dispname: 'Aidzis',
|
18
|
+
body_xml: 'This is a text.'
|
19
|
+
}
|
20
|
+
|
21
|
+
correct_format = MiniTest::Mock.new
|
22
|
+
|
23
|
+
correct_format.expect :get_filename, 'something-more', [Hash]
|
24
|
+
correct_format.expect :get_filename, 'something-more', [Hash]
|
25
|
+
correct_format.expect :build_entry, '[2013-04-18 13:16:58] Aidzis: This is a text.', [Hash]
|
26
|
+
correct_format.expect :build_entry, '[2013-04-18 13:16:58] Aidzis: This is a text.', [Hash]
|
27
|
+
|
28
|
+
@correct_file_writer = Runoff::FileWriter.new correct_format
|
29
|
+
|
30
|
+
incorrect_format = MiniTest::Mock.new
|
31
|
+
|
32
|
+
incorrect_format.expect :get_filename, 'something', [Hash]
|
33
|
+
incorrect_format.expect :build_entry, '[2013-04-18 13:16:58] Aidzis: This is a text.', [Hash]
|
34
|
+
|
35
|
+
@incorrect_file_writer = Runoff::FileWriter.new incorrect_format
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#save_to_file" do
|
39
|
+
after do
|
40
|
+
FileUtils.rm_rf 'test/tmp'
|
41
|
+
Dir.glob('test/*.zip').each do |archive|
|
42
|
+
File.delete archive
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'must write chat content to file' do
|
47
|
+
@correct_file_writer.save_to_file @chat_record, 'test/tmp'
|
48
|
+
@incorrect_file_writer.save_to_file @incorrect_chat_record, 'test/tmp'
|
49
|
+
Dir.glob('test/tmp/*.txt').count.must_equal 2
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'must append to a file if the filename already exists' do
|
53
|
+
@additional_chat_record = @chat_record
|
54
|
+
|
55
|
+
@correct_file_writer.save_to_file @chat_record, 'test/tmp'
|
56
|
+
@incorrect_file_writer.save_to_file @incorrect_chat_record, 'test/tmp'
|
57
|
+
@correct_file_writer.save_to_file @additional_chat_record, 'test/tmp'
|
58
|
+
Dir.glob('test/tmp/*.txt').count.must_equal 2
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'must create a Zip file of the file output directory' do
|
63
|
+
output_directory = 'test/tmp'
|
64
|
+
files = %w[first.txt second.txt]
|
65
|
+
|
66
|
+
Dir.mkdir(output_directory) unless File.exists?(output_directory)
|
67
|
+
files.each do |filename|
|
68
|
+
File.new "#{output_directory}/#{filename}", 'w'
|
69
|
+
end
|
70
|
+
|
71
|
+
Runoff::FileWriter.archive output_directory
|
72
|
+
Dir["test/*.zip"].length.must_equal 1
|
73
|
+
|
74
|
+
Dir.glob('test/*.zip').each do |archive|
|
75
|
+
File.delete archive
|
76
|
+
end
|
77
|
+
|
78
|
+
FileUtils.rm_rf 'test/tmp'
|
79
|
+
end
|
80
|
+
end
|
@@ -1,31 +1,19 @@
|
|
1
|
-
require 'minitest/spec'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require 'runoff'
|
4
|
-
|
5
|
-
describe Runoff::Location do
|
6
|
-
describe '.default_skype_data_location' do
|
7
|
-
it 'must return a default path depending on the operating system' do
|
8
|
-
path = Runoff::Location.default_skype_data_location 'aidzis_skype'
|
9
|
-
|
10
|
-
if RbConfig::CONFIG['host_os'] =~ /mingw/
|
11
|
-
path.must_match /\/Users\/[a-zA-Z0-9]+\/AppData\/Roaming\/Skype\/aidzis_skype\/main\.db/
|
12
|
-
elsif RbConfig::CONFIG['host_os'] =~ /linux/
|
13
|
-
path.must_match /\/home\/[a-zA-Z0-9]+\/\.Skype\/aidzis_skype\/main\.db/
|
14
|
-
else
|
15
|
-
path.must_match /~\/Library\/Application Support\/Skype\/aidzis_skype\/main\.db/
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '.home_path' do
|
21
|
-
it 'must return a path to the user home directory depending on the operating system' do
|
22
|
-
path = Runoff::Location.home_path
|
23
|
-
|
24
|
-
if RbConfig::CONFIG['host_os'] =~ /mingw/
|
25
|
-
path.must_match /[A-Z]:\\Users\\[a-zA-Z0-9]+/
|
26
|
-
else
|
27
|
-
path.must_match /\/home\/[a-zA-Z0-9]+/
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'runoff'
|
4
|
+
|
5
|
+
describe Runoff::Location do
|
6
|
+
describe '.default_skype_data_location' do
|
7
|
+
it 'must return a default path depending on the operating system' do
|
8
|
+
path = Runoff::Location.default_skype_data_location 'aidzis_skype'
|
9
|
+
|
10
|
+
if RbConfig::CONFIG['host_os'] =~ /mingw/
|
11
|
+
path.must_match /\/Users\/[a-zA-Z0-9]+\/AppData\/Roaming\/Skype\/aidzis_skype\/main\.db/
|
12
|
+
elsif RbConfig::CONFIG['host_os'] =~ /linux/
|
13
|
+
path.must_match /\/home\/[a-zA-Z0-9]+\/\.Skype\/aidzis_skype\/main\.db/
|
14
|
+
else
|
15
|
+
path.must_match /~\/Library\/Application Support\/Skype\/aidzis_skype\/main\.db/
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
31
19
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'runoff'
|
4
|
+
|
5
|
+
describe Runoff::SkypeDataFormat do
|
6
|
+
before do
|
7
|
+
@format = Runoff::SkypeDataFormat.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'must return a valid filename from a hash (single record in a database)' do
|
11
|
+
record = { chatname: '#brian/$john;521357125362' }
|
12
|
+
filename = @format.get_filename record
|
13
|
+
|
14
|
+
filename.must_equal 'brian-john.txt'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'must build a string from the necessary database record columns' do
|
18
|
+
record = {
|
19
|
+
chatname: '#brian/$john;521357125362',
|
20
|
+
timestamp: 1366280218,
|
21
|
+
from_dispname: 'Aidzis',
|
22
|
+
body_xml: 'This is a text.'
|
23
|
+
}
|
24
|
+
entry = @format.build_entry record
|
25
|
+
|
26
|
+
entry.must_equal '[2013-04-18 13:16:58] Aidzis: This is a text.'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'must return a valid and readable name from a raw chatname' do
|
30
|
+
raw_chatname = '#something/$else;521357125362'
|
31
|
+
chatname = @format.parse_chatname raw_chatname
|
32
|
+
|
33
|
+
chatname.must_equal 'something-else'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'must return a valid and readable name from broken chatname records' do
|
37
|
+
raw_chatname = '#something/$521357125362'
|
38
|
+
chatname = @format.parse_chatname raw_chatname
|
39
|
+
|
40
|
+
chatname.must_equal 'something'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'must return a chatname without the extra symbols' do
|
44
|
+
raw_chatname = '#something/$else;521357125362'
|
45
|
+
chatname = @format.partly_parse_chatname raw_chatname
|
46
|
+
|
47
|
+
chatname.must_equal '#something/$else;'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'must return a chatname without the extra symbols for broken chatname records' do
|
51
|
+
raw_chatname = '#something/$521357125362'
|
52
|
+
chatname = @format.partly_parse_chatname raw_chatname
|
53
|
+
|
54
|
+
chatname.must_equal '#something/$'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'must return a string without Skype emotion XML tags' do
|
58
|
+
string = 'Some text <ss type="laugh">:D</ss>'
|
59
|
+
clean_string = @format.send :parse_body_xml, string
|
60
|
+
|
61
|
+
clean_string.must_equal 'Some text :D'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'must remove all starting and ending dashes from a string' do
|
65
|
+
string = '---example--'
|
66
|
+
valid_name = @format.send :trim_dashes, string
|
67
|
+
|
68
|
+
valid_name.must_equal 'example'
|
69
|
+
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runoff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aigars Dzerviniks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: commander
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: sequel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '>='
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rubyzip
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '>='
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
@@ -82,16 +82,22 @@ files:
|
|
82
82
|
- Rakefile
|
83
83
|
- bin/runoff
|
84
84
|
- lib/runoff.rb
|
85
|
+
- lib/runoff/commands/all.rb
|
86
|
+
- lib/runoff/commands/chat.rb
|
87
|
+
- lib/runoff/commands/command.rb
|
85
88
|
- lib/runoff/composition.rb
|
86
89
|
- lib/runoff/file_writer.rb
|
87
90
|
- lib/runoff/location.rb
|
88
|
-
- lib/runoff/
|
91
|
+
- lib/runoff/skype_data_format.rb
|
89
92
|
- lib/runoff/version.rb
|
90
93
|
- runoff.gemspec
|
91
|
-
- test/
|
92
|
-
- test/
|
93
|
-
- test/
|
94
|
-
- test/
|
94
|
+
- test/all_test.rb
|
95
|
+
- test/chat_test.rb
|
96
|
+
- test/command_test.rb
|
97
|
+
- test/composition_test.rb
|
98
|
+
- test/file_writer_test.rb
|
99
|
+
- test/location_test.rb
|
100
|
+
- test/skype_data_format_test.rb
|
95
101
|
- test/test_db.sqlite
|
96
102
|
homepage: https://github.com/aidzis/runoff
|
97
103
|
licenses:
|
@@ -113,13 +119,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
119
|
version: '0'
|
114
120
|
requirements: []
|
115
121
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.0.
|
122
|
+
rubygems_version: 2.0.2
|
117
123
|
signing_key:
|
118
124
|
specification_version: 4
|
119
125
|
summary: Tool to export Skype chat history from the SQLite database to text files
|
120
126
|
test_files:
|
121
|
-
- test/
|
122
|
-
- test/
|
123
|
-
- test/
|
124
|
-
- test/
|
127
|
+
- test/all_test.rb
|
128
|
+
- test/chat_test.rb
|
129
|
+
- test/command_test.rb
|
130
|
+
- test/composition_test.rb
|
131
|
+
- test/file_writer_test.rb
|
132
|
+
- test/location_test.rb
|
133
|
+
- test/skype_data_format_test.rb
|
125
134
|
- test/test_db.sqlite
|
data/lib/runoff/source.rb
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
|
3
|
-
# Public: Provides the functionality to back up Skype chat history.
|
4
|
-
#
|
5
|
-
# Examples
|
6
|
-
#
|
7
|
-
# runoff all skype_username
|
8
|
-
# # => Finished: 8 files were exported
|
9
|
-
module Runoff
|
10
|
-
|
11
|
-
# Public: Entry point for the executable. Processes the CLI input from the user.
|
12
|
-
class Source < Thor
|
13
|
-
desc 'all [SKYPE_USERNAME] [OPTIONS]', 'Export all chat history'
|
14
|
-
|
15
|
-
long_desc <<-LONGDESC
|
16
|
-
runoff all [SKYPE_USERNAME] [OPTIONS] will export all your Skype chat history as text files.
|
17
|
-
|
18
|
-
SKYPE_USERNAME - the Skype account username, which data you want to access
|
19
|
-
LONGDESC
|
20
|
-
|
21
|
-
method_option :from, aliases: '-f', desc: 'Specify the location of the main.db file'
|
22
|
-
method_option :to, aliases: '-t', desc: 'Specify where to put export files'
|
23
|
-
method_option :archive, aliases: '-a', type: :boolean, default: true,
|
24
|
-
desc: 'Specify whether to save files in a Zip archive'
|
25
|
-
|
26
|
-
# Public: Exports all chat history from the Skype database.
|
27
|
-
#
|
28
|
-
# skype_username - A String that contains a username of the Skype account,
|
29
|
-
# which database we want to access.
|
30
|
-
#
|
31
|
-
# Examples
|
32
|
-
#
|
33
|
-
# all 'skype_username'
|
34
|
-
# # => Finished: 8 files were exported
|
35
|
-
def all(skype_username = nil)
|
36
|
-
composition = get_composition skype_username
|
37
|
-
destination = get_destination
|
38
|
-
|
39
|
-
print_result composition.export(destination)
|
40
|
-
try_to_archive composition, destination
|
41
|
-
|
42
|
-
rescue IOError => e
|
43
|
-
puts e
|
44
|
-
rescue StandardError => e
|
45
|
-
puts e
|
46
|
-
end
|
47
|
-
|
48
|
-
desc 'chat [SKYPE_USERNAME] [OPTIONS]', 'Export pecified chats history'
|
49
|
-
|
50
|
-
long_desc <<-LONGDESC
|
51
|
-
runoff chat [SKYPE_USERNAME] [OPTIONS] will export all your Skype chat history as text files.
|
52
|
-
|
53
|
-
SKYPE_USERNAME - the Skype account username, which data you want to access
|
54
|
-
LONGDESC
|
55
|
-
|
56
|
-
method_option :from, aliases: '-f', desc: 'Specify the location of the main.db file'
|
57
|
-
method_option :to, aliases: '-t', desc: 'Specify where to put export files'
|
58
|
-
method_option :archive, aliases: '-a', type: :boolean, default: true,
|
59
|
-
desc: 'Specify whether to save files in a Zip archive'
|
60
|
-
|
61
|
-
# Public: Exports specified chats from the Skype database.
|
62
|
-
#
|
63
|
-
# skype_username - A String that contains a username of the Skype account,
|
64
|
-
# which database we want to access.
|
65
|
-
#
|
66
|
-
# Examples
|
67
|
-
#
|
68
|
-
# chat 'skype_username'
|
69
|
-
# # => Finished: 3 files were exported
|
70
|
-
def chat(skype_username = nil)
|
71
|
-
composition = get_composition skype_username
|
72
|
-
destination = get_destination
|
73
|
-
chatnames, raw_chatnames = composition.get_chatnames
|
74
|
-
|
75
|
-
list_chatnames chatnames
|
76
|
-
indecies = ask 'Which chats do you want to export? (Enter indecies) '
|
77
|
-
indecies = indecies.split.map { |index| index.to_i }
|
78
|
-
selected_chatnames = []
|
79
|
-
|
80
|
-
indecies.each { |index| selected_chatnames << raw_chatnames[index] }
|
81
|
-
print_result composition.export_chats(selected_chatnames, destination)
|
82
|
-
try_to_archive composition, destination
|
83
|
-
|
84
|
-
rescue IOError => e
|
85
|
-
puts e
|
86
|
-
rescue StandardError => e
|
87
|
-
puts e
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
# Internal: Gets a Composition object.
|
93
|
-
#
|
94
|
-
# skype_username - A String that contains a username of the Skype account,
|
95
|
-
# which database we want to access.
|
96
|
-
#
|
97
|
-
# Examples
|
98
|
-
#
|
99
|
-
# get_composition 'skype_username'
|
100
|
-
# # => #<Composition:0x00002324212>
|
101
|
-
#
|
102
|
-
# Returns a Composition object with a reference to a specific Skype database.
|
103
|
-
# Raises StandardError if no Skype username or --from option is provided.
|
104
|
-
def get_composition(skype_username)
|
105
|
-
unless skype_username || options[:from]
|
106
|
-
raise StandardError, 'You must provide a Skype username or a --from option'
|
107
|
-
end
|
108
|
-
|
109
|
-
main_db_file_location = options[:from] || Location.default_skype_data_location(skype_username)
|
110
|
-
Composition.new main_db_file_location
|
111
|
-
end
|
112
|
-
|
113
|
-
# Internal: Gets a destination path depending on the entered options.
|
114
|
-
#
|
115
|
-
# Examples
|
116
|
-
#
|
117
|
-
# get_destination
|
118
|
-
# # => '~/skype_backup'
|
119
|
-
#
|
120
|
-
# Returns a String containing a path to the destination directory.
|
121
|
-
def get_destination
|
122
|
-
options[:to] || "#{Location.home_path}/skype-backup"
|
123
|
-
end
|
124
|
-
|
125
|
-
# Internal: Informs the user that the application has finished running.
|
126
|
-
#
|
127
|
-
# count - A number of files that have been exported
|
128
|
-
#
|
129
|
-
# Examples
|
130
|
-
#
|
131
|
-
# print_result 4
|
132
|
-
# # => Finished: 4 files were exported
|
133
|
-
def print_result(count)
|
134
|
-
if count == 1
|
135
|
-
puts 'Finished: 1 file was exported'
|
136
|
-
elsif count > 1
|
137
|
-
puts "Finished: #{count} files were exported"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# Internal: Prints available chatnames.
|
142
|
-
#
|
143
|
-
# chatnames - An Array containing the chatname strings
|
144
|
-
#
|
145
|
-
# Examples
|
146
|
-
#
|
147
|
-
# list_chatnames ['something-more', 'something-else']
|
148
|
-
# # => [0] something-more
|
149
|
-
# [1] something-else
|
150
|
-
def list_chatnames(chatnames)
|
151
|
-
chatnames.each_with_index { |n, i| puts "[#{i}] #{n}" }
|
152
|
-
puts
|
153
|
-
end
|
154
|
-
|
155
|
-
# Internal: performs archiving if an --archive option is provided
|
156
|
-
#
|
157
|
-
# composition - A Compositon object
|
158
|
-
# destination - A String containing a path to the export directory.
|
159
|
-
#
|
160
|
-
# Examples
|
161
|
-
#
|
162
|
-
# try_to_archive composition, '/home/username/skype-backup'
|
163
|
-
def try_to_archive(composition, destination)
|
164
|
-
if options[:archive]
|
165
|
-
composition.archive destination
|
166
|
-
end
|
167
|
-
rescue StandardError
|
168
|
-
puts 'Faild to create an archive'
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'minitest/spec'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require 'runoff'
|
4
|
-
|
5
|
-
describe Runoff::FileWriter do
|
6
|
-
before do
|
7
|
-
@incorrect_chat_record = {
|
8
|
-
chatname: '#something/$;521357125362',
|
9
|
-
timestamp: 1366280218,
|
10
|
-
from_dispname: 'Aidzis',
|
11
|
-
body_xml: ''
|
12
|
-
}
|
13
|
-
@chat_record = {
|
14
|
-
chatname: '#something/$more;521357125362',
|
15
|
-
timestamp: 1366280218,
|
16
|
-
from_dispname: 'Aidzis',
|
17
|
-
body_xml: 'This is a text.'
|
18
|
-
}
|
19
|
-
|
20
|
-
class ClassWithFileWriterMixin
|
21
|
-
include Runoff::FileWriter
|
22
|
-
end
|
23
|
-
|
24
|
-
@test_object = ClassWithFileWriterMixin.new
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'must return a string without Skype emotion XML tags' do
|
28
|
-
string = 'Some text <ss type="laugh">:D</ss>'
|
29
|
-
clean_string = @test_object.parse_body_xml string
|
30
|
-
|
31
|
-
clean_string.must_equal 'Some text :D'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'must remove all starting and ending dashes from a string' do
|
35
|
-
string = '---example--'
|
36
|
-
valid_name = @test_object.trim_dashes string
|
37
|
-
|
38
|
-
valid_name.must_equal 'example'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'must return a valid and readable name from a raw chatname' do
|
42
|
-
raw_chatname = '#something/$else;521357125362'
|
43
|
-
chatname = @test_object.parse_chatname raw_chatname
|
44
|
-
|
45
|
-
chatname.must_equal 'something-else'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'must return a valid and readable name from broken chatname records' do
|
49
|
-
raw_chatname = '#something/$521357125362'
|
50
|
-
chatname = @test_object.parse_chatname raw_chatname
|
51
|
-
|
52
|
-
chatname.must_equal 'something'
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'must return a chatname without the extra symbols' do
|
56
|
-
raw_chatname = '#something/$else;521357125362'
|
57
|
-
chatname = @test_object.partly_parse_chatname raw_chatname
|
58
|
-
|
59
|
-
chatname.must_equal '#something/$else;'
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'must return a chatname without the extra symbols for broken chatname records' do
|
63
|
-
raw_chatname = '#something/$521357125362'
|
64
|
-
chatname = @test_object.partly_parse_chatname raw_chatname
|
65
|
-
|
66
|
-
chatname.must_equal '#something/$'
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'must build a chat entry from a database record' do
|
70
|
-
entry = @test_object.build_entry @chat_record
|
71
|
-
|
72
|
-
entry.must_equal '[2013-04-18 13:16:58] Aidzis: This is a text.'
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "#save_to_file" do
|
76
|
-
after do
|
77
|
-
FileUtils.rm_rf 'test/tmp/.'
|
78
|
-
Dir.glob('test/*.zip').each do |archive|
|
79
|
-
File.delete archive
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'must write chat content to file' do
|
84
|
-
@test_object.save_to_file @chat_record, 'test/tmp'
|
85
|
-
@test_object.save_to_file @incorrect_chat_record, 'test/tmp'
|
86
|
-
Dir['test/tmp/**/*'].length.must_equal 2
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'must append to a file if the filename already exists' do
|
90
|
-
@additional_chat_record = @chat_record
|
91
|
-
|
92
|
-
@test_object.save_to_file @chat_record, 'test/tmp'
|
93
|
-
@test_object.save_to_file @incorrect_chat_record, 'test/tmp'
|
94
|
-
@test_object.save_to_file @additional_chat_record, 'test/tmp'
|
95
|
-
Dir['test/tmp/**/*'].length.must_equal 2
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'must create a Zip file of the file output directory' do
|
100
|
-
output_directory = 'test/tmp'
|
101
|
-
files = %w[first.txt second.txt]
|
102
|
-
|
103
|
-
Dir.mkdir(output_directory) unless File.exists?(output_directory)
|
104
|
-
files.each do |filename|
|
105
|
-
File.new "#{output_directory}/#{filename}", 'w'
|
106
|
-
end
|
107
|
-
|
108
|
-
@test_object.archive output_directory
|
109
|
-
Dir["test/*.zip"].length.must_equal 1
|
110
|
-
|
111
|
-
Dir.glob('test/*.zip').each do |archive|
|
112
|
-
File.delete archive
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
data/test/runoff_source_test.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'minitest/spec'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require 'runoff'
|
4
|
-
|
5
|
-
describe Runoff::Source do
|
6
|
-
before { @source = Runoff::Source.new }
|
7
|
-
|
8
|
-
after do
|
9
|
-
FileUtils.rm_rf 'test/tmp/.'
|
10
|
-
Dir.glob('test/*.zip').each do |archive|
|
11
|
-
File.delete archive
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'must export all the chats from a Skype database into text files and print a count of the exported files' do
|
16
|
-
command = 'all -f test/test_db.sqlite -t test/tmp'
|
17
|
-
|
18
|
-
->{ Runoff::Source.start command.split }.must_output "Finished: 2 files were exported\n"
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'must raise a StandardError if no Skype username or --form option is provided' do
|
22
|
-
->{ @source.send :get_composition, nil }.must_raise StandardError
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'must print how many files were exported' do
|
26
|
-
->{ @source.send :print_result, 1 }.must_output "Finished: 1 file was exported\n"
|
27
|
-
->{ @source.send :print_result, 5 }.must_output "Finished: 5 files were exported\n"
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'must print all available chatnames' do
|
31
|
-
chatnames = ['something-more', 'something-else']
|
32
|
-
|
33
|
-
->{ @source.send :list_chatnames, chatnames }.must_output "[0] something-more\n[1] something-else\n\n"
|
34
|
-
end
|
35
|
-
end
|