mtif 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/mtif.rb +30 -0
- data/lib/mtif/posts.rb +167 -0
- data/lib/mtif/version.rb +3 -0
- data/mtif.gemspec +25 -0
- data/spec/mtif/post_spec.rb +149 -0
- data/spec/mtif_spec.rb +71 -0
- data/spec/spec_helper.rb +103 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44c470cee7b56a046a34966a7b58929cdb0e621b
|
4
|
+
data.tar.gz: a945fa44a90c6b21eca02c4e6004a42ddb85f81d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 651394118662adddc2c3a75fa986e92c6d6512c42b6b12a0bbfd1a4a285ba081484f0ec2f25f29107f5bef57994cc7670a8f47000644f450851e1e507dd477d0
|
7
|
+
data.tar.gz: ab362a64ae4119711fe172d93554a86234df3cd24be0b91390c1f5e5db5aee8d5f7bd59f8c42dc7d0ccec6dba66ab63f0807c37421fc226b23d0a0f08cf8eddc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Jim Meyer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# MTIF
|
2
|
+
|
3
|
+
A gem to read Movable Type Import Format
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mtif'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mtif
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/mtif/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/mtif.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "mtif/version"
|
2
|
+
require "mtif/posts"
|
3
|
+
|
4
|
+
# Based on https://movabletype.org/documentation/appendices/import-export-format.html
|
5
|
+
|
6
|
+
class MTIF
|
7
|
+
attr_accessor :posts
|
8
|
+
|
9
|
+
def initialize(content)
|
10
|
+
@posts = content.slice_after(/^--------$/).map {|raw_post| MTIF::Post.new(raw_post)}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load_file(filename)
|
14
|
+
mtif_file = File.open(filename)
|
15
|
+
mtif = MTIF.new(mtif_file.readlines)
|
16
|
+
mtif_file.close
|
17
|
+
|
18
|
+
mtif
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_mtif
|
22
|
+
posts.map(&:to_mtif).join
|
23
|
+
end
|
24
|
+
|
25
|
+
def save_file(filename)
|
26
|
+
mtif_file = File.open(filename, 'w')
|
27
|
+
mtif_file << self.to_mtif
|
28
|
+
mtif_file.close
|
29
|
+
end
|
30
|
+
end
|
data/lib/mtif/posts.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
require "time"
|
2
|
+
|
3
|
+
class MTIF
|
4
|
+
class Post
|
5
|
+
attr_accessor :source, :data
|
6
|
+
|
7
|
+
SINGLE_VALUE_KEYS = %w(author title status basename date unique_url body extended_body excerpt
|
8
|
+
keywords allow_comments allow_pings convert_breaks no_entry).map(&:to_sym)
|
9
|
+
|
10
|
+
MULTILINE_KEYS = %w(body extended_body excerpt keywords comment ping).map(&:to_sym)
|
11
|
+
|
12
|
+
MULTIVALUE_KEYS = %w(category tag comment ping).map(&:to_sym)
|
13
|
+
|
14
|
+
VALID_KEYS = (SINGLE_VALUE_KEYS + MULTILINE_KEYS + MULTIVALUE_KEYS).sort.uniq
|
15
|
+
|
16
|
+
DATE_FORMAT = "%m/%d/%Y %I:%M:%S %p"
|
17
|
+
|
18
|
+
def valid_keys
|
19
|
+
VALID_KEYS
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid_key?(key)
|
23
|
+
valid_keys.include?(key.to_sym)
|
24
|
+
end
|
25
|
+
|
26
|
+
def single_line_single_value_keys
|
27
|
+
SINGLE_VALUE_KEYS - MULTILINE_KEYS
|
28
|
+
end
|
29
|
+
|
30
|
+
def single_line_multivalue_keys
|
31
|
+
MULTIVALUE_KEYS - MULTILINE_KEYS
|
32
|
+
end
|
33
|
+
|
34
|
+
def multiline_single_value_keys
|
35
|
+
MULTILINE_KEYS & SINGLE_VALUE_KEYS
|
36
|
+
end
|
37
|
+
|
38
|
+
def multiline_multivalue_keys
|
39
|
+
MULTILINE_KEYS & MULTIVALUE_KEYS
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize(content)
|
43
|
+
@source = content
|
44
|
+
@data = {}
|
45
|
+
|
46
|
+
MULTIVALUE_KEYS.each do |key|
|
47
|
+
@data[key] = []
|
48
|
+
end
|
49
|
+
|
50
|
+
parse_source
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_mtif
|
54
|
+
result = []
|
55
|
+
single_line_single_value_keys.each do |key|
|
56
|
+
value = self.send(key)
|
57
|
+
next if value.nil? || (value.respond_to?(:empty) && value.empty?)
|
58
|
+
|
59
|
+
result << "#{mtif_key(key)}: #{mtif_value(value)}"
|
60
|
+
end
|
61
|
+
|
62
|
+
single_line_multivalue_keys.each do |key|
|
63
|
+
values = self.send(key)
|
64
|
+
next if values.nil? || (values.respond_to?(:empty) && values.empty?)
|
65
|
+
|
66
|
+
values.each do |value|
|
67
|
+
result << "#{mtif_key(key)}: #{mtif_value(value)}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
multiline_single_value_keys.each do |key|
|
72
|
+
value = self.send(key)
|
73
|
+
next if value.nil? || (value.respond_to?(:empty) && value.empty?)
|
74
|
+
|
75
|
+
result << '-----'
|
76
|
+
result << "#{mtif_key(key)}:\n#{mtif_value(value)}"
|
77
|
+
end
|
78
|
+
|
79
|
+
multiline_multivalue_keys.each do |key|
|
80
|
+
values = self.send(key)
|
81
|
+
next if values.nil? || (values.respond_to?(:empty) && values.empty?)
|
82
|
+
|
83
|
+
values.each do |value|
|
84
|
+
result << '-----'
|
85
|
+
result << "#{mtif_key(key)}:\n#{mtif_value(value)}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
result << '-----' unless result.last == '-----' #close the final field
|
91
|
+
result << '--------' # close the post
|
92
|
+
result.join("\n") + "\n"
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
def method_missing(method, *args, &block)
|
97
|
+
key = method.to_s.chomp('=').to_sym
|
98
|
+
|
99
|
+
if valid_key?(key)
|
100
|
+
if key = method
|
101
|
+
data[key]
|
102
|
+
else
|
103
|
+
data[key] = args.first
|
104
|
+
end
|
105
|
+
else
|
106
|
+
super
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def respond_to_missing?(method, include_all)
|
111
|
+
key = method.to_s.chomp('=').to_sym
|
112
|
+
|
113
|
+
valid_key?(key) || super
|
114
|
+
end
|
115
|
+
|
116
|
+
def mtif_key_to_key(raw_key)
|
117
|
+
raw_key.strip.downcase.tr(' ','_').to_sym unless raw_key.nil?
|
118
|
+
end
|
119
|
+
|
120
|
+
def mtif_key(key)
|
121
|
+
key.to_s.tr('_', ' ').upcase
|
122
|
+
end
|
123
|
+
|
124
|
+
def mtif_value(value)
|
125
|
+
value.kind_of?(Time) ? value.strftime(DATE_FORMAT) : value
|
126
|
+
end
|
127
|
+
|
128
|
+
def convert_to_native_type(raw_value)
|
129
|
+
case raw_value
|
130
|
+
when /^\d+$/
|
131
|
+
raw_value.to_i
|
132
|
+
when /^\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2} [AP]M/
|
133
|
+
Time.strptime(raw_value, DATE_FORMAT)
|
134
|
+
else
|
135
|
+
raw_value
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def store_data(raw_key, raw_value)
|
140
|
+
key = mtif_key_to_key(raw_key)
|
141
|
+
value = convert_to_native_type(raw_value)
|
142
|
+
|
143
|
+
if MULTIVALUE_KEYS.include?(key)
|
144
|
+
self.data[key] << value unless value.empty?
|
145
|
+
else
|
146
|
+
self.data[key] = value
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def parse_source
|
151
|
+
source.slice_before(/-----/).each do |lines|
|
152
|
+
if lines.first =~ /^-----/ && lines.size > 1
|
153
|
+
# Multiline data
|
154
|
+
store_data(lines.shift(2).last.chomp(":\n"), lines.join.strip)
|
155
|
+
elsif lines.first =~ /^[A-Z ]+: /
|
156
|
+
# Single-line data
|
157
|
+
lines.each do |line|
|
158
|
+
unless line.strip.empty?
|
159
|
+
key, value = line.strip.split(": ", 2)
|
160
|
+
store_data(key, value)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/lib/mtif/version.rb
ADDED
data/mtif.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mtif/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mtif"
|
8
|
+
spec.version = MTIF::VERSION
|
9
|
+
spec.authors = ["Jim Meyer"]
|
10
|
+
spec.email = ["jim@geekdaily.org"]
|
11
|
+
spec.summary = %q{Read, parse, and write Movable Type Import Format files.}
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = "https://geekdaily.org/projects/mtif"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "simplecov"
|
25
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
RSpec.describe MTIF::Post do
|
2
|
+
it 'should have accessors for source and data' do
|
3
|
+
expect(MTIF::Post.new([])).to respond_to(:source, :data)
|
4
|
+
end
|
5
|
+
|
6
|
+
context 'valid keys' do
|
7
|
+
it 'should have a list of valid single-value keys' do
|
8
|
+
expect(MTIF::Post).to have_constant('SINGLE_VALUE_KEYS')
|
9
|
+
expect(MTIF::Post::SINGLE_VALUE_KEYS).not_to be_empty
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have a list of valid keys which can have multiple values' do
|
13
|
+
expect(MTIF::Post).to have_constant('MULTIVALUE_KEYS')
|
14
|
+
expect(MTIF::Post::MULTIVALUE_KEYS).not_to be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have a list of valid multiline keys' do
|
18
|
+
expect(MTIF::Post).to have_constant('MULTILINE_KEYS')
|
19
|
+
expect(MTIF::Post::MULTILINE_KEYS).not_to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should not have any multivalue keys in the list of single-value keys or vice versa' do
|
23
|
+
expect((MTIF::Post::MULTIVALUE_KEYS & MTIF::Post::SINGLE_VALUE_KEYS)).to be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have a list of valid keys which is proper superset of these' do
|
27
|
+
expect(MTIF::Post).to have_constant('VALID_KEYS')
|
28
|
+
expect(MTIF::Post::VALID_KEYS).to match_array((MTIF::Post::SINGLE_VALUE_KEYS + MTIF::Post::MULTILINE_KEYS + MTIF::Post::MULTIVALUE_KEYS).uniq)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'key methods' do
|
32
|
+
before :each do
|
33
|
+
@post = MTIF::Post.new([])
|
34
|
+
end
|
35
|
+
|
36
|
+
subject {@post}
|
37
|
+
|
38
|
+
it {should respond_to(:valid_keys)}
|
39
|
+
context '#valid_keys' do
|
40
|
+
subject {@post.valid_keys}
|
41
|
+
|
42
|
+
it {should == MTIF::Post::VALID_KEYS}
|
43
|
+
end
|
44
|
+
|
45
|
+
it {should respond_to(:valid_key?)}
|
46
|
+
context '#valid_key?' do
|
47
|
+
it 'should be true when valid, false otherwise' do
|
48
|
+
valid_key = @post.valid_keys.first.to_sym
|
49
|
+
invalid_key = valid_key.to_s.reverse.to_sym
|
50
|
+
|
51
|
+
expect(@post.valid_key?(valid_key)).to be_truthy
|
52
|
+
expect(@post.valid_key?(valid_key.to_s)).to be_truthy
|
53
|
+
expect(@post.valid_key?(invalid_key)).to be_falsey
|
54
|
+
expect(@post.valid_key?(invalid_key.to_s)).to be_falsey
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'returning lists' do
|
59
|
+
it {should respond_to(:single_line_single_value_keys)}
|
60
|
+
context '#single_line_single_value_keys' do
|
61
|
+
subject {@post.single_line_single_value_keys}
|
62
|
+
|
63
|
+
it {should_not include(*MTIF::Post::MULTILINE_KEYS)}
|
64
|
+
it {should_not include(*MTIF::Post::MULTIVALUE_KEYS)}
|
65
|
+
it {should include(*(MTIF::Post::SINGLE_VALUE_KEYS - MTIF::Post::MULTILINE_KEYS))}
|
66
|
+
end
|
67
|
+
|
68
|
+
it {should respond_to(:single_line_multivalue_keys)}
|
69
|
+
context '#single_line_multivalue_keys' do
|
70
|
+
subject {@post.single_line_multivalue_keys}
|
71
|
+
|
72
|
+
it {should_not include(*MTIF::Post::MULTILINE_KEYS)}
|
73
|
+
it {should_not include(*MTIF::Post::SINGLE_VALUE_KEYS)}
|
74
|
+
it {should include(*(MTIF::Post::MULTIVALUE_KEYS - MTIF::Post::MULTILINE_KEYS))}
|
75
|
+
end
|
76
|
+
|
77
|
+
it {should respond_to(:multiline_single_value_keys)}
|
78
|
+
context '#multiline_single_value_keys' do
|
79
|
+
subject {@post.multiline_single_value_keys}
|
80
|
+
|
81
|
+
it {should_not include(*MTIF::Post::MULTIVALUE_KEYS)}
|
82
|
+
it {should include(*(MTIF::Post::MULTILINE_KEYS & MTIF::Post::SINGLE_VALUE_KEYS))}
|
83
|
+
end
|
84
|
+
|
85
|
+
it {should respond_to(:multiline_multivalue_keys)}
|
86
|
+
context '#multiline_multivalue_keys' do
|
87
|
+
subject {@post.multiline_multivalue_keys}
|
88
|
+
|
89
|
+
it {should_not include(*MTIF::Post::SINGLE_VALUE_KEYS)}
|
90
|
+
it {should include(*(MTIF::Post::MULTILINE_KEYS & MTIF::Post::MULTIVALUE_KEYS))}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'fetching data' do
|
97
|
+
subject {MTIF::Post.new([])}
|
98
|
+
|
99
|
+
MTIF::Post::VALID_KEYS.each do |key|
|
100
|
+
it {should respond_to(key)}
|
101
|
+
it {should respond_to("#{key}=")}
|
102
|
+
end
|
103
|
+
|
104
|
+
it {should_not respond_to(:this_is_not_a_valid_key)}
|
105
|
+
it {should_not respond_to(:this_is_not_a_valid_key=)}
|
106
|
+
|
107
|
+
it 'should default to arrays for multivalue keys' do
|
108
|
+
post = MTIF::Post.new([])
|
109
|
+
|
110
|
+
MTIF::Post::MULTIVALUE_KEYS.each do |key|
|
111
|
+
expect(post.send(key)) == []
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context '#to_mtif' do
|
117
|
+
before :each do
|
118
|
+
# TODO: refactor to remove ordering dependency
|
119
|
+
@content = [
|
120
|
+
"AUTHOR: The Meyer Kids\n",
|
121
|
+
"TITLE: Crazy Parents: A Primer\n",
|
122
|
+
"DATE: 06/19/1999 07:00:00 PM\n",
|
123
|
+
"ALLOW COMMENTS: 0\n",
|
124
|
+
"CATEGORY: Fun!\n",
|
125
|
+
"-----\n",
|
126
|
+
"BODY:\n",
|
127
|
+
"Start singing an obnoxious song and never stop.\n",
|
128
|
+
"-----\n",
|
129
|
+
"COMMENT:\n",
|
130
|
+
"AUTHOR: Jim Meyer\n",
|
131
|
+
"EMAIL: \n",
|
132
|
+
"IP: 67.180.21.185\n",
|
133
|
+
"URL: http://profile.typepad.com/purp\n",
|
134
|
+
"DATE: 08/26/2010 10:32:04 AM\n",
|
135
|
+
"Yeah, that works.\n",
|
136
|
+
"-----\n",
|
137
|
+
"--------\n"
|
138
|
+
]
|
139
|
+
|
140
|
+
@post = MTIF::Post.new(@content)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should return concise MTIF containing only keys which are set' do
|
144
|
+
expect(@post).to respond_to(:to_mtif)
|
145
|
+
expect(@post.to_mtif).to eq(@content.join)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
data/spec/mtif_spec.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
RSpec.describe MTIF do
|
2
|
+
it 'should have a version number' do
|
3
|
+
expect {MTIF::VERSION}.not_to raise_error
|
4
|
+
end
|
5
|
+
|
6
|
+
context "#initialize" do
|
7
|
+
context 'without content' do
|
8
|
+
it 'should fail' do
|
9
|
+
expect {MTIF.new}.to raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with content' do
|
14
|
+
it 'should divide the content into posts' do
|
15
|
+
expect(MTIF::Post).to receive(:new).exactly(3).times.and_return(instance_double("MTIF::Post"))
|
16
|
+
|
17
|
+
mtif = MTIF.new(['-' * 8] * 3)
|
18
|
+
|
19
|
+
expect {mtif.posts}.not_to raise_error
|
20
|
+
expect mtif.posts.size == 3
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should convert itself back to MTIF' do
|
24
|
+
post_mtif = "THIS IS: not valid MTIF\n--------\n"
|
25
|
+
|
26
|
+
post = instance_double("MTIF::Post")
|
27
|
+
expect(post).to receive(:to_mtif).once.and_return(post_mtif)
|
28
|
+
|
29
|
+
mtif = MTIF.new([])
|
30
|
+
mtif.posts = [post]
|
31
|
+
|
32
|
+
expect {@mtif_output = mtif.to_mtif}.not_to raise_error
|
33
|
+
expect @mtif_output == post_mtif
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context ".load_file" do
|
38
|
+
it 'should return an MTIF object' do
|
39
|
+
expect(MTIF::Post).to receive(:new).twice.and_return(instance_double("MTIF::Post"))
|
40
|
+
|
41
|
+
file_instance = instance_double("File")
|
42
|
+
expect(file_instance).to receive(:readlines).once.and_return(['-' * 8, '-' * 8])
|
43
|
+
expect(file_instance).to receive(:close).once
|
44
|
+
|
45
|
+
expect(File).to receive(:open).once.and_return(file_instance)
|
46
|
+
|
47
|
+
expect {mtif = MTIF.load_file('/youre/in/a/maze/of/twisty/passages/all/alike')}.not_to raise_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "#save_file" do
|
52
|
+
it 'should create a file with the content in it' do
|
53
|
+
mtif_output = "THIS IS: not valid MTIF\n--------\n"
|
54
|
+
|
55
|
+
post = instance_double("MTIF::Post")
|
56
|
+
expect(post).to receive(:to_mtif).once.and_return(mtif_output)
|
57
|
+
|
58
|
+
mtif = MTIF.new([])
|
59
|
+
mtif.posts = [post]
|
60
|
+
|
61
|
+
file_instance = instance_double("File")
|
62
|
+
expect(file_instance).to receive(:<<).with(mtif_output).once
|
63
|
+
expect(file_instance).to receive(:close).once
|
64
|
+
|
65
|
+
expect(File).to receive(:open).once.and_return(file_instance)
|
66
|
+
|
67
|
+
expect {mtif.save_file('/youre/in/a/maze/of/twisty/passages/all/different')}.not_to raise_error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start
|
6
|
+
|
7
|
+
require 'mtif'
|
8
|
+
|
9
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
10
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
11
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
12
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
13
|
+
# files.
|
14
|
+
#
|
15
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
16
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
17
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
18
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
19
|
+
# a separate helper file that requires the additional dependencies and performs
|
20
|
+
# the additional setup, and require it from the spec files that actually need
|
21
|
+
# it.
|
22
|
+
#
|
23
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
24
|
+
# users commonly want.
|
25
|
+
#
|
26
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
27
|
+
RSpec.configure do |config|
|
28
|
+
# rspec-expectations config goes here. You can use an alternate
|
29
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
30
|
+
# assertions if you prefer.
|
31
|
+
config.expect_with :rspec do |expectations|
|
32
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
33
|
+
# and `failure_message` of custom matchers include text for helper methods
|
34
|
+
# defined using `chain`, e.g.:
|
35
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
36
|
+
# # => "be bigger than 2 and smaller than 4"
|
37
|
+
# ...rather than:
|
38
|
+
# # => "be bigger than 2"
|
39
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
43
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
44
|
+
config.mock_with :rspec do |mocks|
|
45
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
46
|
+
# a real object. This is generally recommended, and will default to
|
47
|
+
# `true` in RSpec 4.
|
48
|
+
mocks.verify_partial_doubles = true
|
49
|
+
end
|
50
|
+
|
51
|
+
# The settings below are suggested to provide a good initial experience
|
52
|
+
# with RSpec, but feel free to customize to your heart's content.
|
53
|
+
# These two settings work together to allow you to limit a spec run
|
54
|
+
# to individual examples or groups you care about by tagging them with
|
55
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
56
|
+
# get run.
|
57
|
+
config.filter_run :focus
|
58
|
+
config.run_all_when_everything_filtered = true
|
59
|
+
|
60
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
61
|
+
# recommended. For more details, see:
|
62
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
63
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
64
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
65
|
+
config.disable_monkey_patching!
|
66
|
+
|
67
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
68
|
+
# be too noisy due to issues in dependencies.
|
69
|
+
config.warnings = true
|
70
|
+
|
71
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
72
|
+
# file, and it's useful to allow more verbose output when running an
|
73
|
+
# individual spec file.
|
74
|
+
if config.files_to_run.one?
|
75
|
+
# Use the documentation formatter for detailed output,
|
76
|
+
# unless a formatter has already been configured
|
77
|
+
# (e.g. via a command-line flag).
|
78
|
+
config.default_formatter = 'doc'
|
79
|
+
end
|
80
|
+
|
81
|
+
# Print the 10 slowest examples and example groups at the
|
82
|
+
# end of the spec run, to help surface which specs are running
|
83
|
+
# particularly slow.
|
84
|
+
# config.profile_examples = 10
|
85
|
+
|
86
|
+
# Run specs in random order to surface order dependencies. If you find an
|
87
|
+
# order dependency and want to debug it, you can fix the order by providing
|
88
|
+
# the seed, which is printed after each run.
|
89
|
+
# --seed 1234
|
90
|
+
config.order = :random
|
91
|
+
|
92
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
93
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
94
|
+
# test failures related to randomization by passing the same `--seed` value
|
95
|
+
# as the one that triggered the failure.
|
96
|
+
Kernel.srand config.seed
|
97
|
+
end
|
98
|
+
|
99
|
+
RSpec::Matchers.define :have_constant do |constant|
|
100
|
+
match do |thing|
|
101
|
+
thing.const_defined?(constant)
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mtif
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jim Meyer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- jim@geekdaily.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/mtif.rb
|
83
|
+
- lib/mtif/posts.rb
|
84
|
+
- lib/mtif/version.rb
|
85
|
+
- mtif.gemspec
|
86
|
+
- spec/mtif/post_spec.rb
|
87
|
+
- spec/mtif_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: https://geekdaily.org/projects/mtif
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.5
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Read, parse, and write Movable Type Import Format files.
|
113
|
+
test_files:
|
114
|
+
- spec/mtif/post_spec.rb
|
115
|
+
- spec/mtif_spec.rb
|
116
|
+
- spec/spec_helper.rb
|