rack-blogengine 0.2.4 → 0.2.5
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/.travis.yml +2 -2
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -22
- data/assets/date_test.content +6 -0
- data/assets/operator.content +4 -0
- data/assets/pygment.content +4 -0
- data/features/support/env.rb +2 -2
- data/lib/rack/blogengine/application.rb +8 -3
- data/lib/rack/blogengine/application_router.rb +16 -12
- data/lib/rack/blogengine/command_line_interface.rb +39 -36
- data/lib/rack/blogengine/document_parser.rb +32 -27
- data/lib/rack/blogengine/operator.rb +2 -2
- data/lib/rack/blogengine/version.rb +1 -1
- data/rack-blogengine.gemspec +1 -0
- data/spec/spec_helper.rb +1 -1
- data/tasks/default.rake +5 -0
- data/tasks/floodtest.rake +33 -0
- data/tasks/test.rake +19 -0
- data/test/rack/blogengine/application_router_test.rb +9 -6
- data/test/rack/blogengine/application_test.rb +37 -0
- data/test/rack/blogengine/command_line_interface_test.rb +7 -40
- data/test/rack/blogengine/document_parser_test.rb +37 -122
- data/test/test_helper.rb +4 -1
- metadata +42 -29
- data/test/rack/blogengine/document_test.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a9967ebc1f5812da39b323ccbfab72c1a0ad7d3
|
4
|
+
data.tar.gz: 3df6682117a5998123b822ad64154ac4f397beb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b52f8b93f472e3c98589d7be691dd1959ec2fdc7e0902702196cd5d3ec2907a7779c48422c2c9c521acf2d791db153a1401baa91bc517e48067c0e8e6c69192
|
7
|
+
data.tar.gz: c37ea97848979aefc91bdcc0f029cb9536a3010bb21b762c9faaf5737db462b877b2dd9fcf40c8f83925fcae048e3cb9a391a1efd15d6c1001786e3e17212f96
|
data/.travis.yml
CHANGED
@@ -2,9 +2,9 @@ language: ruby
|
|
2
2
|
cache: bundler
|
3
3
|
|
4
4
|
rvm:
|
5
|
-
- 1.9.3
|
6
5
|
- 2.0.0
|
7
6
|
- 2.1.0
|
7
|
+
- 2.1.1
|
8
8
|
- ruby-head
|
9
9
|
- jruby
|
10
10
|
- rbx
|
@@ -15,4 +15,4 @@ matrix:
|
|
15
15
|
- rvm: jruby
|
16
16
|
- rvm: ruby-head
|
17
17
|
|
18
|
-
script: "env COVERAGE=true bundle exec rake"
|
18
|
+
script: "env COVERAGE=true bundle exec rake"
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -2,27 +2,6 @@ require "bundler/gem_tasks"
|
|
2
2
|
require 'rake/testtask'
|
3
3
|
require 'cucumber/rake/task'
|
4
4
|
|
5
|
+
Dir.glob('tasks/*.rake').each { |r| import r }
|
5
6
|
|
6
|
-
namespace :test do
|
7
|
-
Rake::TestTask.new(:unit) do |t|
|
8
|
-
t.libs << "test" << "bin" << "ext"
|
9
|
-
t.test_files = FileList['test/**/*_test.rb']
|
10
|
-
t.verbose = true
|
11
|
-
end
|
12
7
|
|
13
|
-
Rake::TestTask.new(:spec) do |t|
|
14
|
-
t.libs << "spec" << "bin" << "ext"
|
15
|
-
t.test_files = FileList['spec/**/*_spec.rb']
|
16
|
-
t.verbose = true
|
17
|
-
end
|
18
|
-
|
19
|
-
Cucumber::Rake::Task.new(:feature) do |t|
|
20
|
-
t.cucumber_opts = "features --format pretty"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
task :default do
|
25
|
-
Rake::Task['test:unit'].invoke
|
26
|
-
# Rake::Task['test:spec'].invoke
|
27
|
-
Rake::Task['test:feature'].invoke
|
28
|
-
end
|
data/features/support/env.rb
CHANGED
@@ -14,7 +14,7 @@ SimpleCov.start do
|
|
14
14
|
add_filter '/features/'
|
15
15
|
add_filter '/doc/'
|
16
16
|
add_filter '/assets/'
|
17
|
-
end if ENV[
|
17
|
+
end if ENV['COVERAGE']
|
18
18
|
|
19
19
|
require 'capybara/cucumber'
|
20
20
|
require 'rack/blogengine'
|
@@ -22,4 +22,4 @@ require 'rack/blogengine'
|
|
22
22
|
Rack::Blogengine.documents = [{ html: '<!DOCTYPE html><body><h2>index</h2></body></html>',
|
23
23
|
path: '/' }]
|
24
24
|
|
25
|
-
Capybara.app = Rack::Blogengine::Application
|
25
|
+
Capybara.app = Rack::Blogengine::Application.new
|
@@ -7,14 +7,19 @@ module Rack
|
|
7
7
|
# @author [benny]
|
8
8
|
#
|
9
9
|
class Application
|
10
|
+
# def initialize(app)
|
11
|
+
# @app = app
|
12
|
+
# end
|
10
13
|
# Call Method for run this method as Rack Middleware.
|
11
14
|
# @param env Environment contains information such as path, headers etc...
|
12
15
|
# @return [Array] response Array
|
13
|
-
def
|
16
|
+
def call(env)
|
17
|
+
request = Rack::Request.new(env)
|
18
|
+
|
14
19
|
# Router for map docs to routes
|
15
|
-
route = ApplicationRouter.map_route(
|
20
|
+
route = ApplicationRouter.map_route(request, Rack::Blogengine.documents)
|
16
21
|
|
17
|
-
route['response']
|
22
|
+
route['response'].finish
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -11,17 +11,18 @@ module Rack
|
|
11
11
|
# @param documents Documents which will be looked at
|
12
12
|
# @return [Hash] route Hash {:path => "/foo", :response => [Array]}
|
13
13
|
class << self
|
14
|
-
def map_route(
|
15
|
-
success_status = 200
|
14
|
+
def map_route(request, documents)
|
16
15
|
header = { 'Content-Type' => 'text/html; charset=UTF-8' }
|
17
|
-
path = env['PATH_INFO']
|
18
16
|
|
19
17
|
# Iterate through available docs, if nothing matched return nil
|
20
18
|
documents.each do |doc|
|
21
|
-
if doc[:path] == path
|
19
|
+
if doc[:path] == request.path
|
20
|
+
response = Rack::Response.new(doc[:html], 200, header)
|
21
|
+
|
22
22
|
route_response = {
|
23
|
-
'path' => path,
|
24
|
-
'response' =>
|
23
|
+
'path' => request.path,
|
24
|
+
'response' => response
|
25
|
+
# 'response' => [200, header, [doc[:html]]]
|
25
26
|
}
|
26
27
|
|
27
28
|
return route_response
|
@@ -29,15 +30,18 @@ module Rack
|
|
29
30
|
end
|
30
31
|
|
31
32
|
# if no document matches -> return error page
|
32
|
-
|
33
|
+
errorpage(request, documents)
|
33
34
|
end
|
34
35
|
|
35
|
-
def errorpage(
|
36
|
-
{ '
|
37
|
-
|
38
|
-
|
39
|
-
}
|
36
|
+
def errorpage(request, documents)
|
37
|
+
header = { 'Content-Type' => 'text/html; charset=UTF-8' }
|
38
|
+
response = Rack::Response.new('Page not found', 404, header)
|
39
|
+
|
40
|
+
{ 'path' => request.path, 'response' => response }
|
40
41
|
end
|
42
|
+
|
43
|
+
private :errorpage
|
44
|
+
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
@@ -11,7 +11,7 @@ module Rack
|
|
11
11
|
class CommandLineInterface
|
12
12
|
def method_missing(name, *args)
|
13
13
|
puts "Command #{name} not available"
|
14
|
-
print
|
14
|
+
print "Available Commands are: \n\n"
|
15
15
|
self.class.instance_methods(false).each do |method|
|
16
16
|
print "\t #{method}\n" unless method == :method_missing # || method == :setup || method == :getConfig
|
17
17
|
end
|
@@ -35,38 +35,6 @@ module Rack
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
#
|
39
|
-
# Build rack app via Rack::Builder
|
40
|
-
# @param target String The Targetfolder where all relevant files are located
|
41
|
-
# @param config [type] Config via get_config -> parses in config.yml
|
42
|
-
#
|
43
|
-
# @return [type] [description]
|
44
|
-
def build_rack_app(target, config)
|
45
|
-
app = Rack::Builder.new do
|
46
|
-
map '/assets' do
|
47
|
-
run Rack::Directory.new("#{target}/assets")
|
48
|
-
end
|
49
|
-
|
50
|
-
# use Rack::CommonLogger
|
51
|
-
# use Rack::ShowExceptions
|
52
|
-
# use Rack::Lint
|
53
|
-
|
54
|
-
if config['Usage'] == 'yes'
|
55
|
-
use Rack::Auth::Basic, 'Protected Area' do |username, password|
|
56
|
-
username == config['Username'] && password == config['Password']
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Parse in all Documents in cli.run(target)
|
61
|
-
# -> $documents are parsed in only once and then cached via a global variable
|
62
|
-
# Todo Cache without global variable?
|
63
|
-
# Global Variable replaced with module instance variable
|
64
|
-
Rack::Blogengine.documents = DocumentParser.parse_in_documents(target)
|
65
|
-
|
66
|
-
run Application
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
38
|
# Command to generate the folder skeleton
|
71
39
|
# @param [String] folder
|
72
40
|
def generate(folder)
|
@@ -105,11 +73,37 @@ module Rack
|
|
105
73
|
|
106
74
|
# Display Version
|
107
75
|
# return [String] VERSION
|
108
|
-
def version
|
76
|
+
def version
|
109
77
|
puts "\n\tVERSION: #{Rack::Blogengine::VERSION}\n\tRack::Blogengine releases are all pre-relases, first production release will be VERSION 1.0.0\n\n"
|
110
78
|
end
|
111
79
|
|
112
|
-
|
80
|
+
#
|
81
|
+
# Build rack app via Rack::Builder
|
82
|
+
# @param target String The Targetfolder where all relevant files are located
|
83
|
+
# @param config [type] Config via get_config -> parses in config.yml
|
84
|
+
#
|
85
|
+
# @return [type] [description]
|
86
|
+
def build_rack_app(target, config)
|
87
|
+
Rack::Builder.new do
|
88
|
+
map '/assets' do
|
89
|
+
run Rack::Directory.new("#{target}/assets")
|
90
|
+
end
|
91
|
+
|
92
|
+
if config['Usage'] == 'yes'
|
93
|
+
use Rack::Auth::Basic, 'Protected Area' do |username, password|
|
94
|
+
username == config['Username'] && password == config['Password']
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Parse in all Documents in cli.run(target)
|
99
|
+
# -> $documents are parsed in only once and then cached via a global variable
|
100
|
+
# Todo Cache without global variable?
|
101
|
+
# Global Variable replaced with module instance variable
|
102
|
+
Rack::Blogengine.documents = DocumentParser.parse_in_documents(target)
|
103
|
+
|
104
|
+
run Application.new
|
105
|
+
end
|
106
|
+
end
|
113
107
|
|
114
108
|
# Helper method for generate to set up all essential files
|
115
109
|
# param [String] name
|
@@ -137,8 +131,17 @@ module Rack
|
|
137
131
|
pygments_style = config_yaml['Pygments']['style']
|
138
132
|
pygments_seperator = config_yaml['Pygments']['seperator']
|
139
133
|
|
140
|
-
Rack::Blogengine.config = { 'Port' => port,
|
134
|
+
Rack::Blogengine.config = { 'Port' => port,
|
135
|
+
'Server' => server,
|
136
|
+
'Username' => username,
|
137
|
+
'Password' => password,
|
138
|
+
'Usage' => usage,
|
139
|
+
'pygments_style' => pygments_style,
|
140
|
+
'pygments_seperator' => pygments_seperator }
|
141
141
|
end
|
142
|
+
|
143
|
+
private :get_config, :setup, :build_rack_app
|
144
|
+
|
142
145
|
end
|
143
146
|
end
|
144
147
|
end
|
@@ -10,7 +10,11 @@ module Rack
|
|
10
10
|
#
|
11
11
|
module DocumentParser
|
12
12
|
class << self
|
13
|
-
|
13
|
+
private
|
14
|
+
attr_accessor :path, :title, :content, :date, :html, :layout
|
15
|
+
|
16
|
+
public
|
17
|
+
attr_accessor :target
|
14
18
|
end
|
15
19
|
|
16
20
|
# Parse in .content Documents.
|
@@ -20,32 +24,32 @@ module Rack
|
|
20
24
|
@target = target
|
21
25
|
documents = []
|
22
26
|
|
23
|
-
layout_file = ::File.open("#{
|
24
|
-
|
27
|
+
layout_file = ::File.open("#{target}/assets/layout/layout.html", 'r')
|
28
|
+
layout = layout_file.read
|
25
29
|
|
26
30
|
Dir.foreach("#{target}/") do |item|
|
27
31
|
extension = item.split('.')[1]
|
28
32
|
next if item == '.' || item == '..' || extension != 'content'
|
29
33
|
|
30
34
|
get_file_contents(item)
|
31
|
-
|
35
|
+
html = fill_file_contents(layout, title, content, date)
|
32
36
|
|
33
37
|
@document = Document.new
|
34
|
-
@document.path =
|
35
|
-
@document.html =
|
36
|
-
@document.title =
|
37
|
-
@document.date =
|
38
|
+
@document.path = path
|
39
|
+
@document.html = html
|
40
|
+
@document.title = title
|
41
|
+
@document.date = date
|
38
42
|
|
39
43
|
documents << @document
|
40
44
|
end
|
41
45
|
|
42
|
-
generate_highlight_css(
|
46
|
+
generate_highlight_css(target)
|
43
47
|
sort(documents)
|
44
48
|
|
45
49
|
# Has to exec operator after all docs were read,
|
46
50
|
# so documents are available for operators (list all docs, etc...)
|
47
51
|
documents.each do |document|
|
48
|
-
document.exec_content_operator(documents,
|
52
|
+
document.exec_content_operator(documents, target)
|
49
53
|
end
|
50
54
|
|
51
55
|
documents.map do |document|
|
@@ -56,7 +60,7 @@ module Rack
|
|
56
60
|
# Get File Contents (path, title, content)
|
57
61
|
# @param [String] file
|
58
62
|
def self.get_file_contents(file)
|
59
|
-
content_file = ::File.open("#{
|
63
|
+
content_file = ::File.open("#{target}/#{file}")
|
60
64
|
content = content_file.read
|
61
65
|
|
62
66
|
contentarray = get_content_array(content)
|
@@ -65,27 +69,24 @@ module Rack
|
|
65
69
|
if contentblock.include? '[path]:'
|
66
70
|
contentblock['[path]:'] = ''
|
67
71
|
@path = "/#{contentblock}"
|
68
|
-
end
|
69
72
|
|
70
|
-
|
73
|
+
elsif contentblock.include? '[title]:'
|
71
74
|
contentblock['[title]:'] = ''
|
72
75
|
if contentblock.strip.empty?
|
73
|
-
|
76
|
+
fail "Title in #{file} is empty"
|
74
77
|
else
|
75
78
|
@title = contentblock.strip
|
76
79
|
end
|
77
|
-
end
|
78
80
|
|
79
|
-
|
81
|
+
elsif contentblock.include? '[content]:'
|
80
82
|
contentblock['[content]:'] = ''
|
81
83
|
if contentblock.strip.empty?
|
82
|
-
|
84
|
+
fail "Content in #{file} is empty"
|
83
85
|
else
|
84
86
|
@content = contentblock.strip
|
85
87
|
end
|
86
|
-
end
|
87
88
|
|
88
|
-
|
89
|
+
elsif contentblock.include? '[date]:'
|
89
90
|
contentblock['[date]:'] = ''
|
90
91
|
if /\d/.match( contentblock )
|
91
92
|
datearray = contentblock.split(',')
|
@@ -95,7 +96,7 @@ module Rack
|
|
95
96
|
|
96
97
|
@date = Date.new(datearray[0], datearray[1], datearray[2])
|
97
98
|
else
|
98
|
-
|
99
|
+
fail "Invalid Date in #{file}\n [date]:#{contentblock}[/date]"
|
99
100
|
end
|
100
101
|
end
|
101
102
|
end
|
@@ -119,12 +120,12 @@ module Rack
|
|
119
120
|
highlight_code = { text: html.css(seperator).text, brush: brush }
|
120
121
|
end
|
121
122
|
|
122
|
-
def self.highlight(code, language
|
123
|
-
if language
|
124
|
-
|
125
|
-
else
|
126
|
-
code
|
127
|
-
end
|
123
|
+
def self.highlight(code, language)
|
124
|
+
# if language
|
125
|
+
Pygments.highlight(code, :lexer => language.to_sym)
|
126
|
+
# else
|
127
|
+
# code
|
128
|
+
# end
|
128
129
|
end
|
129
130
|
|
130
131
|
def self.generate_highlight_css(target)
|
@@ -157,7 +158,7 @@ module Rack
|
|
157
158
|
|
158
159
|
html.css(seperator).map do |html|
|
159
160
|
highlight_code = get_highlight_code(html.to_s, seperator)
|
160
|
-
highlighted = highlight(highlight_code[:text], highlight_code[:brush]
|
161
|
+
highlighted = highlight(highlight_code[:text], highlight_code[:brush])
|
161
162
|
|
162
163
|
html.replace(highlighted)
|
163
164
|
end
|
@@ -176,6 +177,10 @@ module Rack
|
|
176
177
|
|
177
178
|
documents
|
178
179
|
end
|
180
|
+
|
181
|
+
class << self
|
182
|
+
private :sort, :fill_file_contents, :generate_highlight_css, :highlight, :get_highlight_code, :get_content_array, :get_file_contents
|
183
|
+
end
|
179
184
|
end
|
180
185
|
end
|
181
186
|
end
|
@@ -6,8 +6,8 @@
|
|
6
6
|
#
|
7
7
|
class Operator
|
8
8
|
def initialize(target)
|
9
|
-
|
10
|
-
Dir["#{target}/operator/*.rb"].each {|file| require file }
|
9
|
+
target = Pathname.new("#{target}").realpath.to_s
|
10
|
+
Dir["#{target}/operator/*.rb"].each { |file| require file }
|
11
11
|
|
12
12
|
extend UserOperator # load user operators
|
13
13
|
end
|
data/rack-blogengine.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "cucumber"
|
24
24
|
spec.add_development_dependency "capybara"
|
25
25
|
spec.add_development_dependency "coveralls"
|
26
|
+
spec.add_development_dependency "rack-test"
|
26
27
|
|
27
28
|
spec.add_runtime_dependency "rack"
|
28
29
|
spec.add_runtime_dependency "pygments.rb"
|
data/spec/spec_helper.rb
CHANGED
data/tasks/default.rake
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
test_runs = if ENV['TESTS']
|
2
|
+
Interger(ENV['TESTS'])
|
3
|
+
else
|
4
|
+
30
|
5
|
+
end
|
6
|
+
|
7
|
+
namespace :floodtest do
|
8
|
+
task :unit do
|
9
|
+
desc 'Run Unit floodtest (default 30 tests, configurable via ENV["TESTS"])'
|
10
|
+
1.upto(test_runs) do |i|
|
11
|
+
puts "Running test #{i} of #{test_runs}"
|
12
|
+
exit(-1) if !system('bundle exec rake test:unit')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
task :spec do
|
17
|
+
desc 'Run Spec floodtest (default 30 tests, configurable via ENV["TESTS"])'
|
18
|
+
1.upto(test_runs) do |i|
|
19
|
+
puts "Running test #{i} of #{test_runs}"
|
20
|
+
exit(-1) if !system('bundle exec rake test:spec ')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
task :feature do
|
25
|
+
desc 'Run Feature floodtest (default 30 tests, configurable via ENV["TESTS"])'
|
26
|
+
1.upto(test_runs) do |i|
|
27
|
+
puts "Running test #{i} of #{test_runs}"
|
28
|
+
exit(-1) if !system('bundle exec rake test:feature')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
namespace :test do
|
2
|
+
Rake::TestTask.new(:unit) do |t|
|
3
|
+
t.libs << "test" << "bin" << "ext" << "controllers" << "helpers" << "models"
|
4
|
+
t.test_files = FileList['test/**/*_test.rb']
|
5
|
+
t.verbose = true
|
6
|
+
end
|
7
|
+
|
8
|
+
Rake::TestTask.new(:spec) do |t|
|
9
|
+
t.libs << "spec" << "bin" << "ext" << "controllers" << "helpers" << "models"
|
10
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
11
|
+
t.verbose = true
|
12
|
+
end
|
13
|
+
|
14
|
+
Cucumber::Rake::Task.new(:feature) do |t|
|
15
|
+
t.cucumber_opts = "features --format pretty"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
@@ -12,10 +12,13 @@ class ApplicationRouterTest < MiniTest::Unit::TestCase
|
|
12
12
|
path: '/' }]
|
13
13
|
|
14
14
|
env_fail = { 'PATH_INFO' => '/fail' }
|
15
|
+
request_fail = Rack::Request.new(env_fail)
|
16
|
+
|
15
17
|
env_success = { 'PATH_INFO' => '/' }
|
18
|
+
request_success = Rack::Request.new(env_success)
|
16
19
|
|
17
|
-
@route_success = Rack::Blogengine::ApplicationRouter.map_route(
|
18
|
-
@route_fail = Rack::Blogengine::ApplicationRouter.map_route(
|
20
|
+
@route_success = Rack::Blogengine::ApplicationRouter.map_route(request_success, documents)
|
21
|
+
@route_fail = Rack::Blogengine::ApplicationRouter.map_route(request_fail, documents)
|
19
22
|
end
|
20
23
|
|
21
24
|
def test_map_route_general
|
@@ -29,16 +32,16 @@ class ApplicationRouterTest < MiniTest::Unit::TestCase
|
|
29
32
|
assert_instance_of(String, @route_success['path'], 'Path should be a string')
|
30
33
|
|
31
34
|
# Check response
|
32
|
-
assert_instance_of(
|
33
|
-
assert_instance_of(Fixnum, @route_success['response']
|
35
|
+
assert_instance_of(Rack::Response, @route_success['response'], 'Response should be an Array')
|
36
|
+
assert_instance_of(Fixnum, @route_success['response'].status, 'Status should be a Fixnum')
|
34
37
|
end
|
35
38
|
|
36
39
|
def test_map_route_on_success
|
37
|
-
assert_equal(200, @route_success['response']
|
40
|
+
assert_equal(200, @route_success['response'].status, 'Status should be 200')
|
38
41
|
end
|
39
42
|
|
40
43
|
def test_map_route_on_fail
|
41
|
-
assert_equal(404, @route_fail['response']
|
44
|
+
assert_equal(404, @route_fail['response'].status, 'Status should be 404')
|
42
45
|
end
|
43
46
|
|
44
47
|
def teardown
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
#
|
4
|
+
# TestClass for ApplicationRouter
|
5
|
+
#
|
6
|
+
# @author [benny]
|
7
|
+
#
|
8
|
+
class ApplicationTest < MiniTest::Unit::TestCase
|
9
|
+
include Rack::Test::Methods
|
10
|
+
|
11
|
+
class MockApp
|
12
|
+
def call(env = nil)
|
13
|
+
[200, {}, ["hello"]]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def app
|
18
|
+
Rack::Blogengine::Application.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
@cli = Rack::Blogengine::CommandLineInterface.new
|
23
|
+
capture_stdout { @cli.generate(testpath) }
|
24
|
+
Rack::Blogengine.config = @cli.send(:get_config, testpath)
|
25
|
+
Rack::Blogengine.documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_application_is_callable
|
29
|
+
get '/'
|
30
|
+
|
31
|
+
assert(last_response.body.include?('This is the Index Page'))
|
32
|
+
end
|
33
|
+
|
34
|
+
def teardown
|
35
|
+
system("rm -rf #{testpath}")
|
36
|
+
end
|
37
|
+
end
|
@@ -14,7 +14,7 @@ class CommandLineInterfaceTest < MiniTest::Unit::TestCase
|
|
14
14
|
assert(@cli.respond_to?(:method_missing), 'CLI should respond to :method_missing method')
|
15
15
|
assert(@cli.respond_to?(:run), 'CLI should respond to :run method')
|
16
16
|
assert(@cli.respond_to?(:generate), 'CLI should respond to :generate method')
|
17
|
-
assert(@cli.respond_to?(:version
|
17
|
+
assert(@cli.respond_to?(:version), 'CLI should respond to :version? method')
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_methods_missing
|
@@ -23,13 +23,12 @@ class CommandLineInterfaceTest < MiniTest::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_version?
|
26
|
-
result = capture_stdout { @cli.send(:version
|
26
|
+
result = capture_stdout { @cli.send(:version) }
|
27
27
|
assert(result.include?('VERSION'), ':version? should output the current VERSION')
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_generate
|
31
31
|
capture_stdout { @cli.send(:generate, testpath) }
|
32
|
-
|
33
32
|
assert(Dir.exist?(testpath), 'Test Directory should exist after generate method')
|
34
33
|
assert(Dir.exist?("#{testpath}/assets"), 'assets Directory should exist after generate method')
|
35
34
|
assert(Dir.exist?("#{testpath}/assets/layout"), 'assets/layout Directory should exist after generate method')
|
@@ -37,14 +36,12 @@ class CommandLineInterfaceTest < MiniTest::Unit::TestCase
|
|
37
36
|
assert(Dir.exist?("#{testpath}/assets/js"), 'assets/js Directory should exist after generate method')
|
38
37
|
assert(Dir.exist?("#{testpath}/assets/images"), 'assets/images Directory should exist after generate method')
|
39
38
|
assert(Dir.exist?("#{testpath}/operator"), 'operator Directory should exist after generate method')
|
40
|
-
|
41
39
|
assert(File.exist?("#{testpath}/operator/operator.rb"), 'operator.rb should exist after generate method')
|
42
40
|
assert(File.exist?("#{testpath}/config.yml"), 'config.yml should exist after generate method')
|
43
41
|
assert(File.exist?("#{testpath}/index.content"), 'index.content should exist after generate method')
|
44
42
|
assert(File.exist?("#{testpath}/assets/layout/layout.html"), 'layout.html should exist after generate method')
|
45
43
|
assert(File.exist?("#{testpath}/assets/style/style.css"), 'style.css should exist after generate method')
|
46
44
|
assert(File.exist?("#{testpath}/assets/js/script.js"), 'script.js should exist after generate method')
|
47
|
-
|
48
45
|
system("rm -rf #{testpath}")
|
49
46
|
end
|
50
47
|
|
@@ -58,47 +55,17 @@ class CommandLineInterfaceTest < MiniTest::Unit::TestCase
|
|
58
55
|
assert_equal('/not_a_directory is not a folder!', result, 'run method should output "Target is not a folder!" when folderstring is not a directory')
|
59
56
|
end
|
60
57
|
|
61
|
-
# def test_run
|
62
|
-
# capture_stdout { @cli.send(:generate, testpath) }
|
63
|
-
|
64
|
-
# server_thread = Thread.new do
|
65
|
-
# capture_stdout { @cli.send(:run, testpath) }
|
66
|
-
# end
|
67
|
-
|
68
|
-
# sleep(2) # wait a sec for the server to be booted
|
69
|
-
|
70
|
-
# Thread.list.each {|t| t.exit }
|
71
|
-
# Thread.list.each {|t| p t }
|
72
|
-
|
73
|
-
# system("rm -rf #{testpath}")
|
74
|
-
# end
|
75
|
-
|
76
58
|
def test_build_rack_app
|
77
|
-
capture_stdout { @cli.
|
78
|
-
|
59
|
+
capture_stdout { @cli.generate(testpath) }
|
79
60
|
config = @cli.send(:get_config, testpath)
|
80
61
|
config['Usage'] = 'yes'
|
81
|
-
config[
|
82
|
-
config['Password'] = '
|
83
|
-
|
62
|
+
config['Username'] = 'Benny'
|
63
|
+
config['Password'] = 'Bensn'
|
64
|
+
|
84
65
|
app = @cli.send(:build_rack_app, testpath, config)
|
85
66
|
|
86
|
-
assert_instance_of(Rack::Builder, app, '
|
87
|
-
# @todo : add better tests
|
88
|
-
|
67
|
+
assert_instance_of(Rack::Builder, app, 'Rack app should be instance of Rack::Builder')
|
89
68
|
system("rm -rf #{testpath}")
|
90
69
|
end
|
91
70
|
|
92
|
-
def test_get_config
|
93
|
-
capture_stdout { @cli.send(:generate, testpath) }
|
94
|
-
config = @cli.send(:get_config, testpath)
|
95
|
-
|
96
|
-
assert_equal(3000, config['Port'], 'Default Port should be 3000')
|
97
|
-
assert_equal('webrick', config['Server'], 'Default Server should be webrick')
|
98
|
-
assert_equal('', config['Username'], 'Default Username should not be set')
|
99
|
-
assert_equal('', config['Password'], 'Default Password should not be set')
|
100
|
-
assert_equal('no', config['Usage'], 'Default HTTP Auth Usage should be no')
|
101
|
-
|
102
|
-
system("rm -rf #{testpath}")
|
103
|
-
end
|
104
71
|
end
|
@@ -6,147 +6,62 @@ require 'test_helper'
|
|
6
6
|
# @author [benny]
|
7
7
|
#
|
8
8
|
class DocumentParserTest < MiniTest::Unit::TestCase
|
9
|
-
# parallelize_me!
|
10
|
-
|
11
9
|
def setup
|
12
|
-
cli = Rack::Blogengine::CommandLineInterface.new
|
13
|
-
capture_stdout { cli.generate(testpath) }
|
14
|
-
cli.send(:get_config, testpath)
|
10
|
+
@cli = Rack::Blogengine::CommandLineInterface.new
|
11
|
+
capture_stdout { @cli.generate(testpath) }
|
12
|
+
@cli.send(:get_config, testpath)
|
15
13
|
end
|
16
14
|
|
17
|
-
# Test DocumentParser.parse_in_documents(path)
|
18
15
|
def test_parse_in_documents
|
19
|
-
|
16
|
+
documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath)
|
20
17
|
|
21
|
-
|
18
|
+
documents.each do |document|
|
22
19
|
# Check Hash keys
|
23
|
-
assert(document.key?(:html), 'Documents should contain
|
24
|
-
assert(document.key?(:path), 'Documents should contain a
|
20
|
+
assert(document.key?(:html), 'Documents should contain content')
|
21
|
+
assert(document.key?(:path), 'Documents should contain a path')
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
title = 'testtitle'
|
33
|
-
content = 'testcontent'
|
34
|
-
date = Date.new
|
35
|
-
|
36
|
-
html = Rack::Blogengine::DocumentParser.fill_file_contents(layout, title, content, date)
|
37
|
-
|
38
|
-
assert(html.include?(title), 'Parsed and filled in HTML should contain Title')
|
39
|
-
assert(html.include?(content), 'Parsed and filled in HTML should contain Content')
|
40
|
-
assert(html.include?(date.strftime('%d.%m.%Y')), 'Parsed and filled in HTML should contain Date')
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_fill_file_contents_with_pygments
|
44
|
-
layout_file = ::File.open("#{testpath}/assets/layout/layout.html", 'r')
|
45
|
-
layout = layout_file.read
|
46
|
-
title = 'testtitle'
|
47
|
-
content = '<pre class="brush:ruby">def TestMethod</pre>'
|
48
|
-
date = Date.new
|
49
|
-
|
50
|
-
html = Rack::Blogengine::DocumentParser.fill_file_contents(layout, title, content, date)
|
51
|
-
|
52
|
-
assert(html.include?(title), 'Parsed and filled in HTML should contain Title')
|
53
|
-
assert(html.include?("highlight"), 'Parsed and filled in HTML with pygment handling should contain .highlight class')
|
54
|
-
assert(html.include?(date.strftime('%d.%m.%Y')), 'Parsed and filled in HTML should contain Date')
|
55
|
-
end
|
56
|
-
|
57
|
-
# Test DocumentParser.get_file_contents('file.content')
|
58
|
-
def test_get_file_contents
|
59
|
-
Rack::Blogengine::DocumentParser.title = ''
|
60
|
-
Rack::Blogengine::DocumentParser.content = ''
|
61
|
-
Rack::Blogengine::DocumentParser.date = ''
|
62
|
-
|
63
|
-
Rack::Blogengine::DocumentParser.target = "#{Rack::Blogengine.root}/assets"
|
64
|
-
Rack::Blogengine::DocumentParser.get_file_contents('index.content')
|
65
|
-
|
66
|
-
assert_equal('INDEX', Rack::Blogengine::DocumentParser.title, 'Parsed in Title should eql Title in test .content file')
|
67
|
-
assert_equal('<h2>This is the Index Page</h2>', Rack::Blogengine::DocumentParser.content, 'Parsed in Content should eql Content in test .content file')
|
68
|
-
assert_instance_of(Date, Rack::Blogengine::DocumentParser.date, 'Parsed in Date should be of Class Date')
|
25
|
+
def test_invalid_date
|
26
|
+
system("rm #{testpath}/index.content")
|
27
|
+
capture_stdout { @cli.send(:setup, "date_error.content", "#{testpath}", true) }
|
28
|
+
assert_raises(RuntimeError) { documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath) }
|
69
29
|
end
|
70
30
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
31
|
+
def test_invalid_content
|
32
|
+
system("rm #{testpath}/index.content")
|
33
|
+
capture_stdout { @cli.send(:setup, "content_error.content", "#{testpath}", true) }
|
34
|
+
assert_raises(RuntimeError) { documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath) }
|
74
35
|
end
|
75
36
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
37
|
+
def test_invalid_title
|
38
|
+
system("rm #{testpath}/index.content")
|
39
|
+
capture_stdout { @cli.send(:setup, "title_error.content", "#{testpath}", true) }
|
40
|
+
assert_raises(RuntimeError) { documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath) }
|
79
41
|
end
|
80
42
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def test_get_content_array
|
89
|
-
content = '[path]:[/path]
|
90
|
-
[title]:INDEX[/title]
|
91
|
-
[date]:2013,01,01[/date]
|
92
|
-
[content]:
|
93
|
-
<h2>This is the Index Page</h2>
|
94
|
-
[/content]'
|
95
|
-
contentarray = Rack::Blogengine::DocumentParser.get_content_array(content)
|
96
|
-
|
97
|
-
assert_equal(4, contentarray.length, 'The content Array should contain 4 members (Path, Title, Date, Content)')
|
98
|
-
assert(contentarray[0].include?('path'), 'First Entry should contain the path')
|
99
|
-
assert(contentarray[1].include?('title'), 'Second Entry should contain the title')
|
100
|
-
assert(contentarray[2].include?('date'), 'Third Entry should contain the date')
|
101
|
-
assert(contentarray[3].include?('content'), 'Fourth Entry should contain the content')
|
102
|
-
end
|
103
|
-
|
104
|
-
# Test DocumentParser.sort(documents)
|
105
|
-
def test_sort
|
106
|
-
documents = []
|
107
|
-
|
108
|
-
document1 = Rack::Blogengine::Document.new
|
109
|
-
document1.date = Date.new(2013, 12, 12)
|
110
|
-
|
111
|
-
document2 = Rack::Blogengine::Document.new
|
112
|
-
document2.date = Date.new(2012, 12, 12)
|
113
|
-
|
114
|
-
documents << document1 << document2
|
115
|
-
documents = Rack::Blogengine::DocumentParser.sort(documents)
|
116
|
-
|
117
|
-
assert_equal(Date.new(2012, 12, 12), documents[0].date, 'Documents should be sorted by date (earlier first)')
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_highlight
|
121
|
-
content = "def TestMethod"
|
122
|
-
|
123
|
-
highlighted = Rack::Blogengine::DocumentParser.highlight(content, 'ruby', testpath)
|
124
|
-
assert_match(/.highlight/, highlighted, "Highlighted html should contain a element with class highlight")
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_highlight_fail
|
128
|
-
content = "def TestMethod"
|
129
|
-
|
130
|
-
highlighted = Rack::Blogengine::DocumentParser.highlight(content, nil, testpath)
|
131
|
-
assert_equal(content, highlighted, "If Language is not defined Content should be returned unmodified")
|
43
|
+
def test_documents_with_pygments
|
44
|
+
capture_stdout { @cli.send(:setup, "pygment.content", "#{testpath}", true) }
|
45
|
+
system("rm #{testpath}/index.content")
|
46
|
+
documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath)
|
47
|
+
documents.each do |document|
|
48
|
+
assert(document[:html].include?('class="highlight"'), 'Highlighted code should be wrapped in a div.highlight')
|
49
|
+
end
|
132
50
|
end
|
133
51
|
|
134
|
-
def
|
135
|
-
|
136
|
-
#
|
137
|
-
|
138
|
-
|
139
|
-
|
52
|
+
def test_documents_with_operator
|
53
|
+
capture_stdout { @cli.send(:setup, "operator.content", "#{testpath}", true) }
|
54
|
+
system("rm #{testpath}/index.content")
|
55
|
+
documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath)
|
56
|
+
documents.each do |document|
|
57
|
+
assert(document[:html].include?('test'), 'Test Operator should return test')
|
58
|
+
end
|
140
59
|
end
|
141
60
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
highlight_code = Rack::Blogengine::DocumentParser.get_highlight_code(content, seperator)
|
148
|
-
assert_equal('def TestMethod', highlight_code[:text], "Code between #{seperator} should be returned")
|
149
|
-
assert_equal('ruby', highlight_code[:brush], "Brush should be recognised by the class attribute")
|
61
|
+
def test_document_sort
|
62
|
+
capture_stdout { @cli.send(:setup, "date_test.content", "#{testpath}", true) }
|
63
|
+
documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath)
|
64
|
+
assert(documents[0][:html].include?('This is 2012'), 'The Document with lower date should be first')
|
150
65
|
end
|
151
66
|
|
152
67
|
def teardown
|
data/test/test_helper.rb
CHANGED
@@ -14,7 +14,7 @@ SimpleCov.start do
|
|
14
14
|
add_filter '/features/'
|
15
15
|
add_filter '/doc/'
|
16
16
|
add_filter '/assets/'
|
17
|
-
end if ENV[
|
17
|
+
end if ENV['COVERAGE']
|
18
18
|
|
19
19
|
# Previous content of test helper now starts here
|
20
20
|
|
@@ -23,6 +23,9 @@ require 'minitest/autorun'
|
|
23
23
|
require 'minitest/mock'
|
24
24
|
require 'minitest/pride' # for colored output
|
25
25
|
|
26
|
+
# Rack Test Methods
|
27
|
+
require 'rack/test'
|
28
|
+
|
26
29
|
# TestUnit -> MiniTest (TestUnit is only compatibility Layer)
|
27
30
|
# require 'test/unit'
|
28
31
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-blogengine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benny1992
|
@@ -9,77 +9,85 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-04 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: bundler
|
16
|
-
prerelease: false
|
17
15
|
requirement: &id001 !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: "1.3"
|
22
|
-
|
20
|
+
name: bundler
|
21
|
+
prerelease: false
|
23
22
|
version_requirements: *id001
|
23
|
+
type: :development
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
|
-
name: rake
|
26
|
-
prerelease: false
|
27
25
|
requirement: &id002 !ruby/object:Gem::Requirement
|
28
26
|
requirements:
|
29
27
|
- &id003
|
30
28
|
- ">="
|
31
29
|
- !ruby/object:Gem::Version
|
32
30
|
version: "0"
|
33
|
-
|
31
|
+
name: rake
|
32
|
+
prerelease: false
|
34
33
|
version_requirements: *id002
|
34
|
+
type: :development
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name: cucumber
|
37
|
-
prerelease: false
|
38
36
|
requirement: &id004 !ruby/object:Gem::Requirement
|
39
37
|
requirements:
|
40
38
|
- *id003
|
41
|
-
|
39
|
+
name: cucumber
|
40
|
+
prerelease: false
|
42
41
|
version_requirements: *id004
|
42
|
+
type: :development
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
|
-
name: capybara
|
45
|
-
prerelease: false
|
46
44
|
requirement: &id005 !ruby/object:Gem::Requirement
|
47
45
|
requirements:
|
48
46
|
- *id003
|
49
|
-
|
47
|
+
name: capybara
|
48
|
+
prerelease: false
|
50
49
|
version_requirements: *id005
|
50
|
+
type: :development
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
name: coveralls
|
53
|
-
prerelease: false
|
54
52
|
requirement: &id006 !ruby/object:Gem::Requirement
|
55
53
|
requirements:
|
56
54
|
- *id003
|
57
|
-
|
55
|
+
name: coveralls
|
56
|
+
prerelease: false
|
58
57
|
version_requirements: *id006
|
58
|
+
type: :development
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name: rack
|
61
|
-
prerelease: false
|
62
60
|
requirement: &id007 !ruby/object:Gem::Requirement
|
63
61
|
requirements:
|
64
62
|
- *id003
|
65
|
-
|
63
|
+
name: rack-test
|
64
|
+
prerelease: false
|
66
65
|
version_requirements: *id007
|
66
|
+
type: :development
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
name: pygments.rb
|
69
|
-
prerelease: false
|
70
68
|
requirement: &id008 !ruby/object:Gem::Requirement
|
71
69
|
requirements:
|
72
70
|
- *id003
|
73
|
-
|
71
|
+
name: rack
|
72
|
+
prerelease: false
|
74
73
|
version_requirements: *id008
|
74
|
+
type: :runtime
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name: nokogiri
|
77
|
-
prerelease: false
|
78
76
|
requirement: &id009 !ruby/object:Gem::Requirement
|
79
77
|
requirements:
|
80
78
|
- *id003
|
81
|
-
|
79
|
+
name: pygments.rb
|
80
|
+
prerelease: false
|
82
81
|
version_requirements: *id009
|
82
|
+
type: :runtime
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- *id003
|
87
|
+
name: nokogiri
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: *id010
|
90
|
+
type: :runtime
|
83
91
|
description: Blogengine based on rack applications
|
84
92
|
email:
|
85
93
|
- klotz.benjamin@yahoo.de
|
@@ -100,9 +108,12 @@ files:
|
|
100
108
|
- assets/config.yml
|
101
109
|
- assets/content_error.content
|
102
110
|
- assets/date_error.content
|
111
|
+
- assets/date_test.content
|
103
112
|
- assets/index.content
|
104
113
|
- assets/layout.html
|
114
|
+
- assets/operator.content
|
105
115
|
- assets/operator.rb
|
116
|
+
- assets/pygment.content
|
106
117
|
- assets/title_error.content
|
107
118
|
- bin/rack-blogengine
|
108
119
|
- features/hello.feature
|
@@ -120,10 +131,13 @@ files:
|
|
120
131
|
- rack-blogengine.gemspec
|
121
132
|
- spec/rack/blogengine/document_spec.rb
|
122
133
|
- spec/spec_helper.rb
|
134
|
+
- tasks/default.rake
|
135
|
+
- tasks/floodtest.rake
|
136
|
+
- tasks/test.rake
|
123
137
|
- test/rack/blogengine/application_router_test.rb
|
138
|
+
- test/rack/blogengine/application_test.rb
|
124
139
|
- test/rack/blogengine/command_line_interface_test.rb
|
125
140
|
- test/rack/blogengine/document_parser_test.rb
|
126
|
-
- test/rack/blogengine/document_test.rb
|
127
141
|
- test/test_helper.rb
|
128
142
|
homepage: http://www.bennyklotz.at
|
129
143
|
licenses:
|
@@ -156,8 +170,7 @@ test_files:
|
|
156
170
|
- spec/rack/blogengine/document_spec.rb
|
157
171
|
- spec/spec_helper.rb
|
158
172
|
- test/rack/blogengine/application_router_test.rb
|
173
|
+
- test/rack/blogengine/application_test.rb
|
159
174
|
- test/rack/blogengine/command_line_interface_test.rb
|
160
175
|
- test/rack/blogengine/document_parser_test.rb
|
161
|
-
- test/rack/blogengine/document_test.rb
|
162
176
|
- test/test_helper.rb
|
163
|
-
has_rdoc:
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'test_helper.rb'
|
2
|
-
|
3
|
-
#
|
4
|
-
# TestClass for Documents
|
5
|
-
#
|
6
|
-
# @author [benny]
|
7
|
-
#
|
8
|
-
class DocumentTest < MiniTest::Unit::TestCase
|
9
|
-
def setup
|
10
|
-
@document = Rack::Blogengine::Document.new
|
11
|
-
|
12
|
-
@document.title = 'testtitle'
|
13
|
-
@document.path = '/test'
|
14
|
-
@document.date = '20-20-2014'
|
15
|
-
@document.html = '<html><h1>Test</h1></html>'
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_new_document
|
19
|
-
assert_instance_of(Rack::Blogengine::Document, @document, 'Document should be of class Rack::Blogengine::Document')
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_document_has_content
|
23
|
-
assert_equal('testtitle', @document.title, 'Document should contain the testtitle')
|
24
|
-
assert_equal('/test', @document.path, 'Document should contain the test path')
|
25
|
-
assert_equal('20-20-2014', @document.date, 'Document should contain the test date')
|
26
|
-
assert_equal('<html><h1>Test</h1></html>', @document.html, 'Document should contain the test html')
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_document_to_hash
|
30
|
-
hashed = @document.to_hash
|
31
|
-
assert(hashed.key?(:path), 'Hashed Document should contain the path')
|
32
|
-
assert(hashed.key?(:html), 'Hashed Document should contain parsed html')
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_exec_content_operator
|
36
|
-
cli = Rack::Blogengine::CommandLineInterface.new
|
37
|
-
capture_stdout { cli.generate(testpath) }
|
38
|
-
|
39
|
-
document = Rack::Blogengine::Document.new
|
40
|
-
document.html = '{% test_operator %}'
|
41
|
-
|
42
|
-
document.exec_content_operator(document, "#{testpath}")
|
43
|
-
|
44
|
-
assert_equal('test', document.html, 'Documents html should contain test_operators return value')
|
45
|
-
|
46
|
-
system("rm -rf #{testpath}")
|
47
|
-
end
|
48
|
-
end
|