rack-blogengine 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e31dc4ce6c8c6c9cb2bafc8d24cc0914693897fe
4
- data.tar.gz: d26429eab938829b1327c67e63825287d5350b97
3
+ metadata.gz: 6d1d461e13788b067f570f69315af3379f17c89d
4
+ data.tar.gz: bac62b1d82b17e8cc097ebc83f94b23bfe077a20
5
5
  SHA512:
6
- metadata.gz: 28af739b4183e622649a779dff8b54e75fac04ca6eaae4493f3249561891b8b22f80379e3a29a1c9d234fb8b27bd70be6596e779a61b7adfdd48d74bddc0d666
7
- data.tar.gz: df05afe21a21150796675188e02fe4092e84af82c4c087ca1fa1bd32e2e1c105344c016d0f088ac328012559ca5da72fb7da40b4f4b39fc03d0f3dff515cf60e
6
+ metadata.gz: 21729aaf42d0acee7106f1789c4aa0cac38837aa28668b1ce1fd84d29adeb3e70c5b9514fcd8e401e9bfd4e16767588e82039af8d594972ba87799cd66ac5c4c
7
+ data.tar.gz: 6ecb1d38bd634db4f40be15f27fc512b003208c8c3f7a5a9ea7c775c5d5310272e1151eb6e576e36273a3f57f20c84e372f60b0af3e5958377aaa430289aa113
data/.rubocop.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  LineLength:
2
- Max: 120
2
+ Max: 160
data/.travis.yml CHANGED
@@ -1,8 +1,15 @@
1
1
  language: ruby
2
+ cache: bundler
3
+
2
4
  rvm:
3
- - 1.8.7
4
5
  - 1.9.3
5
6
  - 2.0.0
6
7
  - 2.1.0
7
8
  - jruby
8
- - rbx
9
+ - rbx
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: rbx
14
+ - rvm: jruby
15
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
- # gem "rubysl", "~> 2.0", :platform => :rbx
2
+ gem "rubysl-test-unit", :platform => :rbx
3
+ gem 'coveralls', require: false
4
+
3
5
  # Specify your gem's dependencies in rack-blogengine.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -5,6 +5,17 @@ Rack Middleware to serve a simple blog
5
5
  ## Build status
6
6
 
7
7
  [![Build Status](https://travis-ci.org/Benny1992/rack-blogengine.png?branch=master)](https://travis-ci.org/Benny1992/rack-blogengine)
8
+ [![Coverage Status](https://coveralls.io/repos/Benny1992/rack-blogengine/badge.png?branch=master)](https://coveralls.io/r/Benny1992/rack-blogengine?branch=master)
9
+ [![Gem Version](https://badge.fury.io/rb/rack-blogengine.png)](http://badge.fury.io/rb/rack-blogengine)
10
+ [![Dependency Status](https://gemnasium.com/Benny1992/rack-blogengine.png)](https://gemnasium.com/Benny1992/rack-blogengine)
11
+
12
+ ## Supported Ruby Versions & Platforms
13
+
14
+ - rbx 2.2.5
15
+ - ruby 1.9.3
16
+ - ruby 2.0.0
17
+ - ruby 2.1.0
18
+ - jruby 1.7.9
8
19
 
9
20
  ## Installation
10
21
 
data/Rakefile CHANGED
@@ -1,12 +1,28 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rake/testtask'
3
+ require 'cucumber/rake/task'
4
+
3
5
 
4
6
  namespace :test do
5
7
  Rake::TestTask.new(:unit) do |t|
6
8
  t.libs << "test"
7
- t.test_files = FileList['test/*_test.rb']
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ t.verbose = true
11
+ end
12
+
13
+ Rake::TestTask.new(:spec) do |t|
14
+ t.libs << "spec"
15
+ t.test_files = FileList['spec/**/spec_*.rb']
8
16
  t.verbose = true
9
17
  end
18
+
19
+ Cucumber::Rake::Task.new(:feature) do |t|
20
+ t.cucumber_opts = "features --format pretty"
21
+ end
10
22
  end
11
23
 
12
- task :default => 'test:unit'
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/assets/operator.rb CHANGED
@@ -5,4 +5,7 @@
5
5
  #
6
6
  module UserOperator
7
7
  # define your operators here
8
+ def test_operator(documents, html)
9
+ 'test'
10
+ end
8
11
  end
@@ -0,0 +1,5 @@
1
+ Feature: The app should Work
2
+
3
+ Scenario: View home page
4
+ Given I am on the home page
5
+ Then I should see "index"
@@ -0,0 +1,13 @@
1
+ Given(/^I am on the home page$/) do
2
+ puts visit 'http://localhost:3000'
3
+ end
4
+
5
+ Then(/^I should see "(.*?)"$/) do |text|
6
+ page.has_content?(text)
7
+ # page.driver.resize(20,30)
8
+ # page.save_screenshot("/path/to/test.pdf")
9
+ # puts page.within_window
10
+ # puts page.driver.network_traffic
11
+ # puts page.driver.cookies
12
+ # puts page.response_headers.to_a
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'capybara/cucumber'
5
+ require 'rack/blogengine'
6
+
7
+ Rack::Blogengine.documents = [{ html: '<!DOCTYPE html><body><h2>index</h2></body></html>',
8
+ path: '/' }]
9
+ Capybara.app = Rack::Blogengine::Application
@@ -12,7 +12,7 @@ module Rack
12
12
  # @return [Array] response Array
13
13
  def self.call(env)
14
14
  # Router for map docs to routes
15
- route = ApplicationRouter.map_route(env, $documents)
15
+ route = ApplicationRouter.map_route(env, Rack::Blogengine.documents)
16
16
 
17
17
  route['response']
18
18
  end
@@ -5,7 +5,7 @@ module Rack
5
5
  #
6
6
  # @author [benny]
7
7
  #
8
- class ApplicationRouter
8
+ module ApplicationRouter
9
9
  # Maps documents to routes.
10
10
  # @param env Env Contains path info etc...
11
11
  # @param documents Documents which will be looked at
@@ -22,22 +22,15 @@ module Rack
22
22
  # @param [String] target
23
23
  def run(target)
24
24
  if target.empty?
25
- puts 'Specify a targetfolder!'
25
+ print 'Specify a targetfolder!'
26
26
  else
27
- if target.include?('/')
28
- target = target.dup
29
- target['/'] = ''
30
- end
31
-
32
27
  if Dir.exists?("#{target}")
33
28
  system("cd #{target}")
34
-
35
- targetfolder = "#{Dir.pwd}/#{target}"
36
- config = get_config(targetfolder)
29
+ config = get_config(target)
37
30
 
38
31
  app = Rack::Builder.new do
39
32
  map '/assets' do
40
- run Rack::Directory.new("#{targetfolder}/assets")
33
+ run Rack::Directory.new("#{target}/assets")
41
34
  end
42
35
 
43
36
  use Rack::CommonLogger
@@ -52,14 +45,16 @@ module Rack
52
45
 
53
46
  # Parse in all Documents in cli.run(target)
54
47
  # -> $documents are parsed in only once and then cached via a global variable
55
- $documents = DocParser.parse_in_documents(targetfolder)
48
+ # Todo Cache without global variable?
49
+ # Global Variable replaced with module instance variable
50
+ Rack::Blogengine.documents = DocumentParser.parse_in_documents(target)
56
51
 
57
- run Rack::Blogengine::Application
52
+ run Application
58
53
  end
59
54
 
60
55
  Rack::Server.start(app: app, Port: config['Port'], server: config['Server'])
61
56
  else
62
- puts 'Target is not a folder!'
57
+ print "#{target} is not a folder!"
63
58
  end
64
59
  end
65
60
  end
@@ -103,8 +98,7 @@ module Rack
103
98
  # Display Version
104
99
  # return [String] VERSION
105
100
  def version?
106
- puts "\n\tVERSION: #{Rack::Blogengine::VERSION}"
107
- puts "\tRack::Blogengine releases are all pre-relases, first production release will be VERSION 1.0.0\n\n"
101
+ 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"
108
102
  end
109
103
 
110
104
  private
@@ -8,7 +8,11 @@ module Rack
8
8
  #
9
9
  # @author [benny]
10
10
  #
11
- class DocParser
11
+ module DocumentParser
12
+ class << self
13
+ attr_accessor :title, :content, :date
14
+ end
15
+
12
16
  # Parse in .content Documents.
13
17
  # @param target.
14
18
  # @return [Hash] Documents
@@ -24,11 +28,11 @@ module Rack
24
28
  next if item == '.' || item == '..' || extension != 'content'
25
29
 
26
30
  get_file_contents(item)
27
- @html = fill_file_contents(@layout)
31
+ @html = fill_file_contents(@layout, @title, @content, @date)
28
32
 
29
33
  @document = Document.new
30
34
  @document.path = @path
31
- @document.html = @html.gsub(/\s+/, ' ').strip
35
+ @document.html = @html
32
36
  @document.title = @title
33
37
  @document.date = @date
34
38
 
@@ -54,13 +58,7 @@ module Rack
54
58
  content_file = ::File.open("#{@target}/#{file}")
55
59
  content = content_file.read
56
60
 
57
- # Replace Closing tags
58
- content['/path'] = '/close'
59
- content['/title'] = '/close'
60
- content['/content'] = '/close'
61
- content['/date'] = '/close'
62
-
63
- contentarray = content.split('[/close]')
61
+ contentarray = get_content_array(content)
64
62
 
65
63
  contentarray.each do |contentblock|
66
64
  if contentblock.include? '[path]:'
@@ -90,15 +88,28 @@ module Rack
90
88
  end
91
89
  end
92
90
 
91
+ def self.get_content_array(content)
92
+ # Replace Closing tags
93
+ content['/path'] = '/close'
94
+ content['/title'] = '/close'
95
+ content['/content'] = '/close'
96
+ content['/date'] = '/close'
97
+
98
+ content.split('[/close]')
99
+ end
100
+
93
101
  # Replace layout placeholder with content from .content file
94
102
  # @param [String] layout
103
+ # @param [String] title
104
+ # @param [String] content
105
+ # @param [Date] date
95
106
  # return [String] html placeholder replaced with content
96
- def self.fill_file_contents(layout)
107
+ def self.fill_file_contents(layout, title, content, date)
97
108
  html = layout.dup
98
109
 
99
- html.gsub! '{title}', @title
100
- html['{content}'] = @content
101
- html.gsub! '{date}', @date.strftime('%d.%m.%Y')
110
+ html.gsub! '{title}', title
111
+ html['{content}'] = content
112
+ html.gsub! '{date}', date.strftime('%d.%m.%Y')
102
113
  end
103
114
 
104
115
  # Sort documents array by date of each documenthash
@@ -6,8 +6,12 @@ module Rack
6
6
  # @author [benny]
7
7
  #
8
8
  module Blogengine
9
- def self.root
10
- ::File.dirname(::File.dirname(::File.expand_path('../..', __FILE__)))
9
+ class << self
10
+ attr_accessor :documents
11
+
12
+ def root
13
+ ::File.dirname(::File.dirname(::File.expand_path('../..', __FILE__)))
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -9,7 +9,7 @@ class Operator
9
9
  Dir.foreach("#{target}/operator/") do |item|
10
10
  extension = item.split('.')[1]
11
11
  next if item == '.' || item == '..' || extension != 'rb'
12
- require "#{target}/operator/#{item}"
12
+ require "#{Dir.pwd}/#{target}/operator/#{item}"
13
13
  end
14
14
 
15
15
  extend UserOperator # load user operators
@@ -6,6 +6,6 @@ module Rack
6
6
  # @author [benny]
7
7
  #
8
8
  module Blogengine
9
- VERSION = '0.2.1'.freeze
9
+ VERSION = '0.2.2'.freeze
10
10
  end
11
11
  end
@@ -1,5 +1,5 @@
1
1
  require 'rack/blogengine/version'
2
- require 'rack/blogengine/doc_parser'
2
+ require 'rack/blogengine/document_parser'
3
3
  require 'rack/blogengine/document'
4
4
  require 'rack/blogengine/application'
5
5
  require 'rack/blogengine/application_router'
@@ -20,10 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", ">= 2.0.0"
24
- spec.add_development_dependency "test-unit"
25
- spec.add_development_dependency "test-unit-notify"
26
- spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "cucumber"
24
+ spec.add_development_dependency "capybara"
27
25
 
28
26
  spec.add_runtime_dependency "rack"
29
27
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::Blogengine::Document do
4
+ before do
5
+ @document = Rack::Blogengine::Document.new
6
+
7
+ @document.title = 'testtitle'
8
+ @document.path = '/test'
9
+ @document.date = '20-20-2014'
10
+ @document.html = '<html><h1>Test</h1></html>'
11
+ end
12
+
13
+ describe '#new' do
14
+ it 'should be an instance of Document' do
15
+ @document.class.must_equal Rack::Blogengine::Document
16
+ end
17
+
18
+ it 'should have content when parsed in' do
19
+ @document.title.must_equal 'testtitle'
20
+ @document.path.must_equal '/test'
21
+ @document.date.must_equal '20-20-2014'
22
+ @document.html.must_equal '<html><h1>Test</h1></html>'
23
+ end
24
+ end
25
+
26
+ describe '#to_hash' do
27
+ it 'should return the right hash' do
28
+ hashed = @document.to_hash
29
+
30
+ hashed.key?(:path).must_equal true
31
+ hashed.key?(:html).must_equal true
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,53 @@
1
+ # RSPEC spec_helper
2
+ # =========================
3
+ # require 'rack/blogengine'
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # Require this file using `require "spec_helper"` to ensure that it is only
8
+ # loaded once.
9
+ #
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ # RSpec.configure do |config|
12
+ # config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ # config.run_all_when_everything_filtered = true
14
+ # config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ # config.order = 'random'
21
+ # end
22
+ # =================================
23
+
24
+ require 'coveralls'
25
+ Coveralls.wear!
26
+
27
+ # Minitest
28
+ require 'minitest/autorun'
29
+
30
+ # Load Rack::Blogengine gem
31
+ require 'rack/blogengine'
32
+
33
+ #
34
+ # Opening Kernel for testpath method
35
+ #
36
+ # @author [benny]
37
+ #
38
+ module Kernel
39
+ def testpath
40
+ "#{Rack::Blogengine.root}/testfolder"
41
+ end
42
+ end
43
+
44
+ def capture_stdout(&block)
45
+ original_stdout = $stdout
46
+ $stdout = fake = StringIO.new
47
+ begin
48
+ yield
49
+ ensure
50
+ $stdout = original_stdout
51
+ end
52
+ fake.string
53
+ end
@@ -5,15 +5,12 @@ require 'test_helper.rb'
5
5
  #
6
6
  # @author [benny]
7
7
  #
8
- class ApplicationRouterTest < Test::Unit::TestCase
9
- include Rack::Test::Methods
10
-
8
+ class ApplicationRouterTest < MiniTest::Unit::TestCase
11
9
  def setup
12
- # TODO: Use Fake Data - Don't generate a whole testfolder....
13
- cli = Rack::Blogengine::CommandLineInterface.new
14
- capture_stdout { cli.generate(testpath) }
10
+ # fake document
11
+ documents = [{ html: '<!DOCTYPE html><body><h2>This is the Index Page</h2></body></html>',
12
+ path: '/' }]
15
13
 
16
- documents = Rack::Blogengine::DocParser.parse_in_documents(testpath)
17
14
  env_fail = { 'PATH_INFO' => '/fail' }
18
15
  env_success = { 'PATH_INFO' => '/' }
19
16
 
@@ -22,18 +19,18 @@ class ApplicationRouterTest < Test::Unit::TestCase
22
19
  end
23
20
 
24
21
  def test_map_route_general
25
- assert_equal(Hash, @route_success.class, 'Route should be a hash')
22
+ assert_instance_of(Hash, @route_success, 'Route should be a hash')
26
23
 
27
24
  # Check Hash keys
28
- assert_true(@route_success.key?('path'), 'Route should contain a path')
29
- assert_true(@route_success.key?('response'), 'Route should contain a response')
25
+ assert(@route_success.key?('path'), 'Route should contain a path')
26
+ assert(@route_success.key?('response'), 'Route should contain a response')
30
27
 
31
28
  # Check path
32
- assert_equal(String, @route_success['path'].class, 'Path should be a string')
29
+ assert_instance_of(String, @route_success['path'], 'Path should be a string')
33
30
 
34
31
  # Check response
35
- assert_equal(Array, @route_success['response'].class, 'Response should be an Array')
36
- assert_equal(Fixnum, @route_success['response'][0].class, 'Status should be a Fixnum')
32
+ assert_instance_of(Array, @route_success['response'], 'Response should be an Array')
33
+ assert_instance_of(Fixnum, @route_success['response'][0], 'Status should be a Fixnum')
37
34
  end
38
35
 
39
36
  def test_map_route_on_success
@@ -45,6 +42,5 @@ class ApplicationRouterTest < Test::Unit::TestCase
45
42
  end
46
43
 
47
44
  def teardown
48
- system("rm -rf #{testpath}")
49
45
  end
50
46
  end
@@ -0,0 +1,92 @@
1
+ require 'test_helper.rb'
2
+
3
+ #
4
+ # TestClass for CommandLineInterface
5
+ #
6
+ # @author [benny]
7
+ #
8
+ class CommandLineInterfaceTest < MiniTest::Unit::TestCase
9
+ def setup
10
+ @cli = Rack::Blogengine::CommandLineInterface.new
11
+ end
12
+
13
+ def test_available_methods
14
+ assert(@cli.respond_to?(:method_missing), 'CLI should respond to :method_missing method')
15
+ assert(@cli.respond_to?(:run), 'CLI should respond to :run method')
16
+ assert(@cli.respond_to?(:generate), 'CLI should respond to :generate method')
17
+ assert(@cli.respond_to?(:version?), 'CLI should respond to :version? method')
18
+ end
19
+
20
+ def test_methods_missing
21
+ result = capture_stdout { @cli.send(:missing_method) }
22
+ assert(result.include?('Command missing_method not available'), 'Not Available Method should not raise NoMethodError')
23
+ end
24
+
25
+ def test_version?
26
+ result = capture_stdout { @cli.send(:version?) }
27
+ assert(result.include?('VERSION'), ':version? should output the current VERSION')
28
+ end
29
+
30
+ def test_generate
31
+ capture_stdout { @cli.send(:generate, testpath) }
32
+
33
+ assert(Dir.exist?(testpath), 'Test Directory should exist after generate method')
34
+ assert(Dir.exist?("#{testpath}/assets"), 'assets Directory should exist after generate method')
35
+ assert(Dir.exist?("#{testpath}/assets/layout"), 'assets/layout Directory should exist after generate method')
36
+ assert(Dir.exist?("#{testpath}/assets/style"), 'assets/style Directory should exist after generate method')
37
+ assert(Dir.exist?("#{testpath}/assets/js"), 'assets/js Directory should exist after generate method')
38
+ assert(Dir.exist?("#{testpath}/assets/images"), 'assets/images Directory should exist after generate method')
39
+ assert(Dir.exist?("#{testpath}/operator"), 'operator Directory should exist after generate method')
40
+
41
+ assert(File.exist?("#{testpath}/operator/operator.rb"), 'operator.rb should exist after generate method')
42
+ assert(File.exist?("#{testpath}/config.yml"), 'config.yml should exist after generate method')
43
+ assert(File.exist?("#{testpath}/index.content"), 'index.content should exist after generate method')
44
+ assert(File.exist?("#{testpath}/assets/layout/layout.html"), 'layout.html should exist after generate method')
45
+ assert(File.exist?("#{testpath}/assets/style/style.css"), 'style.css should exist after generate method')
46
+ assert(File.exist?("#{testpath}/assets/js/script.js"), 'script.js should exist after generate method')
47
+
48
+ system("rm -rf #{testpath}")
49
+ end
50
+
51
+ def test_run_empty_string_argument
52
+ result = capture_stdout { @cli.send(:run, '') }
53
+ assert_equal('Specify a targetfolder!', result, 'run method should output "Specify a targetfolder!" when folderstring is empty')
54
+ end
55
+
56
+ def test_run_not_folder_string_argument
57
+ result = capture_stdout { @cli.send(:run, '/not_a_directory') }
58
+ 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
+ end
60
+
61
+ # def test_run
62
+ # capture_stdout { @cli.send(:generate, testpath) }
63
+
64
+ # threads = []
65
+
66
+ # thr1 = Thread.new do
67
+ # capture_stdout { @cli.send(:run, testpath) }
68
+ # end
69
+
70
+ # thr2 = Thread.new do
71
+ # sleep 10
72
+ # system("rm -rf #{testpath}")
73
+ # exit!
74
+ # end
75
+
76
+ # threads << thr1 << thr2
77
+ # threads.each { |thr| thr.join }
78
+ # end
79
+
80
+ def test_get_config
81
+ capture_stdout { @cli.send(:generate, testpath) }
82
+ config = @cli.send(:get_config, testpath)
83
+
84
+ assert_equal(3000, config['Port'], 'Default Port should be 3000')
85
+ assert_equal('webrick', config['Server'], 'Default Server should be webrick')
86
+ assert_equal('', config['Username'], 'Default Username should not be set')
87
+ assert_equal('', config['Password'], 'Default Password should not be set')
88
+ assert_equal('no', config['Usage'], 'Default HTTP Auth Usage should be no')
89
+
90
+ system("rm -rf #{testpath}")
91
+ end
92
+ end
@@ -0,0 +1,92 @@
1
+ require 'test_helper'
2
+
3
+ #
4
+ # Test Class for DocumentParser
5
+ #
6
+ # @author [benny]
7
+ #
8
+ class DocumentParserTest < MiniTest::Unit::TestCase
9
+ # parallelize_me!
10
+
11
+ def setup
12
+ cli = Rack::Blogengine::CommandLineInterface.new
13
+ capture_stdout { cli.generate(testpath) }
14
+
15
+ @documents = Rack::Blogengine::DocumentParser.parse_in_documents(testpath)
16
+ end
17
+
18
+ # Test DocumentParser.parse_in_documents(path)
19
+ def test_parse_in_documents
20
+ @documents.each do |document|
21
+ # Check Hash keys
22
+ assert(document.key?(:html), 'Documents should contain a path')
23
+ assert(document.key?(:path), 'Documents should contain a response')
24
+ end
25
+ end
26
+
27
+ # Test DocumentParser.fill_file_contents(layout, title, content, date)
28
+ def test_fill_file_contents
29
+ layout_file = ::File.open("#{testpath}/assets/layout/layout.html", 'r')
30
+ layout = layout_file.read
31
+ title = 'testtitle'
32
+ content = 'testcontent'
33
+ date = Date.new
34
+
35
+ html = Rack::Blogengine::DocumentParser.fill_file_contents(layout, title, content, date)
36
+
37
+ assert(html.include?(title), 'Parsed and filled in HTML should contain Title')
38
+ assert(html.include?(content), 'Parsed and filled in HTML should contain Content')
39
+ assert(html.include?(date.strftime('%d.%m.%Y')), 'Parsed and filled in HTML should contain Date')
40
+ end
41
+
42
+ # Test DocumentParser.get_file_contents('file.content')
43
+ def test_get_file_contents
44
+ Rack::Blogengine::DocumentParser.title = ''
45
+ Rack::Blogengine::DocumentParser.content = ''
46
+ Rack::Blogengine::DocumentParser.date = ''
47
+
48
+ Rack::Blogengine::DocumentParser.get_file_contents('index.content')
49
+
50
+ assert_equal('INDEX', Rack::Blogengine::DocumentParser.title, 'Parsed in Title should eql Title in test .content file')
51
+ assert_equal('<h2>This is the Index Page</h2>', Rack::Blogengine::DocumentParser.content, 'Parsed in Content should eql Content in test .content file')
52
+ assert_instance_of(Date, Rack::Blogengine::DocumentParser.date, 'Parsed in Date should be of Class Date')
53
+ end
54
+
55
+ # Test DocumentParser.get_content_array(contentstring)
56
+ # Should split up the content for each content section (Path, Title, Date, Content)
57
+ def test_get_content_array
58
+ content = '[path]:[/path]
59
+ [title]:INDEX[/title]
60
+ [date]:2013,01,01[/date]
61
+ [content]:
62
+ <h2>This is the Index Page</h2>
63
+ [/content]'
64
+ contentarray = Rack::Blogengine::DocumentParser.get_content_array(content)
65
+
66
+ assert_equal(4, contentarray.length, 'The content Array should contain 4 members (Path, Title, Date, Content)')
67
+ assert(contentarray[0].include?('path'), 'First Entry should contain the path')
68
+ assert(contentarray[1].include?('title'), 'Second Entry should contain the title')
69
+ assert(contentarray[2].include?('date'), 'Third Entry should contain the date')
70
+ assert(contentarray[3].include?('content'), 'Fourth Entry should contain the content')
71
+ end
72
+
73
+ # Test DocumentParser.sort(documents)
74
+ def test_sort
75
+ documents = []
76
+
77
+ document1 = Rack::Blogengine::Document.new
78
+ document1.date = Date.new(2013, 12, 12)
79
+
80
+ document2 = Rack::Blogengine::Document.new
81
+ document2.date = Date.new(2012, 12, 12)
82
+
83
+ documents << document1 << document2
84
+ documents = Rack::Blogengine::DocumentParser.sort(documents)
85
+
86
+ assert_equal(Date.new(2012, 12, 12), documents[0].date, 'Documents should be sorted by date (earlier first)')
87
+ end
88
+
89
+ def teardown
90
+ system("rm -rf #{testpath}")
91
+ end
92
+ end
@@ -0,0 +1,48 @@
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, 'testfolder')
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
data/test/test_helper.rb CHANGED
@@ -1,17 +1,18 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ # Previous content of test helper now starts here
5
+
1
6
  # Minitest
2
- # require 'minitest/autorun'
7
+ require 'minitest/autorun'
3
8
  # require 'minitest/pride' # for colored output
4
- # require "test_notifier/runner/minitest"
9
+ # require 'test_notifier/runner/minitest' # for a notifier
5
10
 
6
- # Real TestUnit
7
- require 'test/unit'
8
- require 'test/unit/notify'
9
- require 'rack/blogengine'
10
- require 'rack/test'
11
+ # TestUnit -> MiniTest (TestUnit is only compatibility Layer)
12
+ # require 'test/unit'
11
13
 
12
- # alternative to require_relative
13
- # rake install in gem dir and then
14
- # require 'mygem'
14
+ # Load Rack::Blogengine gem
15
+ require 'rack/blogengine'
15
16
 
16
17
  # class Hash
17
18
  # method for usage with assert_boolean
@@ -27,11 +28,11 @@ require 'rack/test'
27
28
  # end
28
29
 
29
30
  #
30
- # Opening Core Class Object for testpath method
31
+ # Opening Kernel for testpath method
31
32
  #
32
33
  # @author [benny]
33
34
  #
34
- class Object
35
+ module Kernel
35
36
  def testpath
36
37
  "#{Rack::Blogengine.root}/testfolder"
37
38
  end
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benny1992
@@ -9,71 +9,53 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-02-07 00:00:00 Z
12
+ date: 2014-02-16 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bundler
16
15
  requirement: &id001 !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - ~>
19
18
  - !ruby/object:Gem::Version
20
19
  version: "1.3"
20
+ name: bundler
21
21
  prerelease: false
22
- type: :development
23
22
  version_requirements: *id001
23
+ type: :development
24
24
  - !ruby/object:Gem::Dependency
25
- name: rake
26
25
  requirement: &id002 !ruby/object:Gem::Requirement
27
26
  requirements:
28
- - &id004
27
+ - &id003
29
28
  - ">="
30
29
  - !ruby/object:Gem::Version
31
30
  version: "0"
31
+ name: rake
32
32
  prerelease: false
33
- type: :development
34
33
  version_requirements: *id002
34
+ type: :development
35
35
  - !ruby/object:Gem::Dependency
36
- name: rspec
37
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ requirement: &id004 !ruby/object:Gem::Requirement
38
37
  requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 2.0.0
38
+ - *id003
39
+ name: cucumber
42
40
  prerelease: false
41
+ version_requirements: *id004
43
42
  type: :development
44
- version_requirements: *id003
45
43
  - !ruby/object:Gem::Dependency
46
- name: test-unit
47
44
  requirement: &id005 !ruby/object:Gem::Requirement
48
45
  requirements:
49
- - *id004
46
+ - *id003
47
+ name: capybara
50
48
  prerelease: false
51
- type: :development
52
49
  version_requirements: *id005
53
- - !ruby/object:Gem::Dependency
54
- name: test-unit-notify
55
- requirement: &id006 !ruby/object:Gem::Requirement
56
- requirements:
57
- - *id004
58
- prerelease: false
59
50
  type: :development
60
- version_requirements: *id006
61
51
  - !ruby/object:Gem::Dependency
62
- name: rack-test
63
- requirement: &id007 !ruby/object:Gem::Requirement
52
+ requirement: &id006 !ruby/object:Gem::Requirement
64
53
  requirements:
65
- - *id004
66
- prerelease: false
67
- type: :development
68
- version_requirements: *id007
69
- - !ruby/object:Gem::Dependency
54
+ - *id003
70
55
  name: rack
71
- requirement: &id008 !ruby/object:Gem::Requirement
72
- requirements:
73
- - *id004
74
56
  prerelease: false
57
+ version_requirements: *id006
75
58
  type: :runtime
76
- version_requirements: *id008
77
59
  description: Blogengine based on rack applications
78
60
  email:
79
61
  - klotz.benjamin@yahoo.de
@@ -85,7 +67,6 @@ extra_rdoc_files: []
85
67
 
86
68
  files:
87
69
  - .gitignore
88
- - .rspec
89
70
  - .rubocop.yml
90
71
  - .travis.yml
91
72
  - Gemfile
@@ -97,18 +78,25 @@ files:
97
78
  - assets/layout.html
98
79
  - assets/operator.rb
99
80
  - bin/rack-blogengine
81
+ - features/hello.feature
82
+ - features/step_definitions/hello_steps.rb
83
+ - features/support/env.rb
100
84
  - lib/rack/blogengine.rb
101
85
  - lib/rack/blogengine/application.rb
102
86
  - lib/rack/blogengine/application_router.rb
103
87
  - lib/rack/blogengine/command_line_interface.rb
104
- - lib/rack/blogengine/doc_parser.rb
105
88
  - lib/rack/blogengine/document.rb
89
+ - lib/rack/blogengine/document_parser.rb
106
90
  - lib/rack/blogengine/methods.rb
107
91
  - lib/rack/blogengine/operator.rb
108
92
  - lib/rack/blogengine/version.rb
109
93
  - rack-blogengine.gemspec
110
- - test/application_router_test.rb
111
- - test/document_test.rb
94
+ - spec/rack/blogengine/document_spec.rb
95
+ - spec/spec_helper.rb
96
+ - test/rack/blogengine/application_router_test.rb
97
+ - test/rack/blogengine/command_line_interface_test.rb
98
+ - test/rack/blogengine/document_parser_test.rb
99
+ - test/rack/blogengine/document_test.rb
112
100
  - test/test_helper.rb
113
101
  homepage: http://www.bennyklotz.at
114
102
  licenses:
@@ -123,10 +111,10 @@ require_paths:
123
111
  - spec
124
112
  required_ruby_version: !ruby/object:Gem::Requirement
125
113
  requirements:
126
- - *id004
114
+ - *id003
127
115
  required_rubygems_version: !ruby/object:Gem::Requirement
128
116
  requirements:
129
- - *id004
117
+ - *id003
130
118
  requirements: []
131
119
 
132
120
  rubyforge_project:
@@ -135,6 +123,13 @@ signing_key:
135
123
  specification_version: 4
136
124
  summary: Blogengine based on rack applications
137
125
  test_files:
138
- - test/application_router_test.rb
139
- - test/document_test.rb
126
+ - features/hello.feature
127
+ - features/step_definitions/hello_steps.rb
128
+ - features/support/env.rb
129
+ - spec/rack/blogengine/document_spec.rb
130
+ - spec/spec_helper.rb
131
+ - test/rack/blogengine/application_router_test.rb
132
+ - test/rack/blogengine/command_line_interface_test.rb
133
+ - test/rack/blogengine/document_parser_test.rb
134
+ - test/rack/blogengine/document_test.rb
140
135
  - test/test_helper.rb
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format documentation
@@ -1,31 +0,0 @@
1
- require 'test_helper.rb'
2
-
3
- #
4
- # TestClass for Documents
5
- #
6
- # @author [benny]
7
- #
8
- class DocumentTest < Test::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_document_has_content
19
- assert_equal('testtitle', @document.title, 'Document should contain the testtitle')
20
- assert_equal('/test', @document.path, 'Document should contain the test path')
21
- assert_equal('20-20-2014', @document.date, 'Document should contain the test date')
22
- assert_equal('<html><h1>Test</h1></html>', @document.html, 'Document should contain the test html')
23
- end
24
-
25
- def test_document_to_hash
26
- hashed = @document.to_hash
27
-
28
- assert_true(hashed.key?(:path), 'Hashed Document should contain the path')
29
- assert_true(hashed.key?(:html), 'Hashed Document should contain parsed html')
30
- end
31
- end