alx 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/.simplecov +5 -0
- data/COPYING +20 -0
- data/Gemfile +4 -0
- data/LICENSE +674 -0
- data/README.md +5 -0
- data/Rakefile +16 -0
- data/alx.gemspec +24 -0
- data/bin/alx +14 -0
- data/features/add_books.feature +15 -0
- data/features/create_default_configuration.feature +8 -0
- data/features/give_meaningful_help.feature +8 -0
- data/features/remove_book.feature +17 -0
- data/features/step_definitions/alx_base_steps.rb +36 -0
- data/features/step_definitions/alx_configuration_steps.rb +19 -0
- data/features/step_definitions/alx_help_steps.rb +7 -0
- data/features/support/alx_extensions.rb +67 -0
- data/features/support/env.rb +27 -0
- data/lib/alx/add_handler.rb +25 -0
- data/lib/alx/book.rb +20 -0
- data/lib/alx/configuration.rb +51 -0
- data/lib/alx/controller.rb +43 -0
- data/lib/alx/editor.rb +33 -0
- data/lib/alx/executer.rb +13 -0
- data/lib/alx/handler.rb +62 -0
- data/lib/alx/help_handler.rb +39 -0
- data/lib/alx/library.rb +27 -0
- data/lib/alx/list_handler.rb +22 -0
- data/lib/alx/remove_handler.rb +36 -0
- data/lib/alx/renderer.rb +39 -0
- data/lib/alx/show_handler.rb +32 -0
- data/lib/alx/version.rb +3 -0
- data/lib/alx/viewer.rb +32 -0
- data/test/tc_book.rb +23 -0
- data/test/tc_controller.rb +37 -0
- data/test/tc_editor.rb +42 -0
- data/test/tc_library.rb +33 -0
- data/test/tc_list_handler.rb +48 -0
- data/test/tc_renderer.rb +41 -0
- data/test/tc_viewer.rb +58 -0
- data/test/test_helper.rb +69 -0
- metadata +168 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'alx/list_handler'
|
4
|
+
|
5
|
+
class ListHandlerTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup_dir( dir )
|
8
|
+
dir.entries << "first_file"
|
9
|
+
dir.entries << "almost_first_file"
|
10
|
+
dir.entries << "second_file"
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@directory = 'something'
|
15
|
+
@dir_stub = DirStub.new
|
16
|
+
setup_dir( @dir_stub )
|
17
|
+
Dir.stubs( :open ).yields( @dir_stub )
|
18
|
+
@conf = Hash.new
|
19
|
+
@list_handler = Alx::ListHandler.new( @conf )
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
Dir.unstub( :open )
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_pattern_list
|
27
|
+
output = capture_stdout do
|
28
|
+
@conf[ :rest ] = 'first'
|
29
|
+
@list_handler.handle
|
30
|
+
end
|
31
|
+
output.string.should =~ /#{@dir_stub.entries[ 0 ].gsub( /_/, ' ' )}/
|
32
|
+
output.string.should =~ /#{@dir_stub.entries[ 1 ].gsub( /_/, ' ' )}/
|
33
|
+
output.string.should_not =~ /#{@dir_stub.entries[ 2 ].gsub( /_/, ' ' )}/
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_list_all_if_pattern_is_empty
|
37
|
+
output = capture_stdout do
|
38
|
+
@conf[ :rest ] = ''
|
39
|
+
@list_handler.handle
|
40
|
+
end
|
41
|
+
|
42
|
+
@dir_stub.entries.each do | file |
|
43
|
+
output.string.should =~ /#{file.gsub( /_/, ' ' )}/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
data/test/tc_renderer.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'alx/renderer'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
class RendererTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
BOOK_CONTENT = 'apple'
|
9
|
+
RENDERED_HTML = "<p>#{BOOK_CONTENT}</p>\n"
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@conf = Hash.new
|
13
|
+
@renderer = Alx::Renderer.new( @conf )
|
14
|
+
@book = BookStub.new( BOOK_CONTENT )
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_html_renderer_is_called
|
21
|
+
@conf[ :html ] = true
|
22
|
+
@renderer.render( @book ).should == RENDERED_HTML
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_html_renderer_is_not_called
|
26
|
+
@conf[ :html ] = false
|
27
|
+
@renderer.render( @book ).should == BOOK_CONTENT
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_html_file_is_created
|
31
|
+
@conf[ :html ] = true
|
32
|
+
@renderer.render_to_file( @book ).should =~ /.*.html/
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_markdown_file_is_created
|
36
|
+
@conf[ :html ] = false
|
37
|
+
@renderer.render_to_file( @book ).should =~ /.*.md/
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
data/test/tc_viewer.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'alx/viewer'
|
4
|
+
|
5
|
+
class ViewerTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@conf = Hash.new
|
9
|
+
@viewer = Alx::Viewer.new( @conf )
|
10
|
+
@text_in_file = "this is the file content"
|
11
|
+
@file_input = StringIO.new( @text_in_file )
|
12
|
+
File.stubs( :open ).yields( @file_input )
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
File.unstub( :open )
|
17
|
+
end
|
18
|
+
|
19
|
+
def view
|
20
|
+
@viewer.view( '/tmp/some_file' )
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_viewer_error
|
24
|
+
@conf[ :html ] = true
|
25
|
+
@conf[ :html_viewer ] = DUMMY_EXEC
|
26
|
+
lambda { view }.should raise_error
|
27
|
+
@conf[ :html ] = false
|
28
|
+
@conf[ :terminal_viewer ] = DUMMY_EXEC
|
29
|
+
lambda { view }.should raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_viewer_returns_false
|
33
|
+
@conf[ :html ] = true
|
34
|
+
@conf[ :html_viewer ] = FALSE_EXEC
|
35
|
+
lambda { view }.should raise_error
|
36
|
+
@conf[ :html ] = false
|
37
|
+
@conf[ :terminal_viewer ] = FALSE_EXEC
|
38
|
+
lambda { view }.should raise_error
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_viewer_success
|
42
|
+
@conf[ :html ] = true
|
43
|
+
@conf[ :html_viewer ] = TRUE_EXEC
|
44
|
+
lambda { view }.should_not raise_error
|
45
|
+
@conf[ :html ] = false
|
46
|
+
@conf[ :terminal_viewer ] = TRUE_EXEC
|
47
|
+
lambda { view }.should_not raise_error
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_viewer_is_stdout
|
51
|
+
@conf[ :stdout ] = true
|
52
|
+
stub_in_and_out() do
|
53
|
+
lambda { view }.should_not raise_error
|
54
|
+
end.should== @text_in_file
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'mocha'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
DUMMY_EXEC = '111somthingsomethingdarkside'
|
6
|
+
FALSE_EXEC = '/bin/false'
|
7
|
+
TRUE_EXEC = '/bin/true'
|
8
|
+
|
9
|
+
class HandlerStub
|
10
|
+
attr_reader :handle_called
|
11
|
+
|
12
|
+
def initialize( configuration )
|
13
|
+
@handle_called = false
|
14
|
+
end
|
15
|
+
|
16
|
+
def handle
|
17
|
+
@handle_called = true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
class BookStub
|
23
|
+
attr_accessor :content
|
24
|
+
|
25
|
+
def initialize( content )
|
26
|
+
@content = content
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
class DirStub
|
33
|
+
attr_accessor :entries
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@entries = []
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def stub_in_and_out( input_text = "" )
|
43
|
+
standard_input = StringIO.new( input_text )
|
44
|
+
standard_output = StringIO.new
|
45
|
+
$stdin = standard_input
|
46
|
+
$stdout = standard_output
|
47
|
+
|
48
|
+
yield
|
49
|
+
|
50
|
+
$stdin = STDIN
|
51
|
+
$stdout = STDOUT
|
52
|
+
|
53
|
+
standard_output.string.chomp
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
module Kernel
|
58
|
+
|
59
|
+
def capture_stdout
|
60
|
+
out = StringIO.new
|
61
|
+
$stdout = out
|
62
|
+
yield
|
63
|
+
return out
|
64
|
+
ensure
|
65
|
+
$stdout = STDOUT
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Hajdu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redcarpet
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: cucumber
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Command line tool to manage your markdown documents. ( beta )
|
79
|
+
email:
|
80
|
+
- peter.ferenc.hajdu@gmail.com
|
81
|
+
executables:
|
82
|
+
- alx
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .simplecov
|
88
|
+
- COPYING
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- alx.gemspec
|
94
|
+
- bin/alx
|
95
|
+
- features/add_books.feature
|
96
|
+
- features/create_default_configuration.feature
|
97
|
+
- features/give_meaningful_help.feature
|
98
|
+
- features/remove_book.feature
|
99
|
+
- features/step_definitions/alx_base_steps.rb
|
100
|
+
- features/step_definitions/alx_configuration_steps.rb
|
101
|
+
- features/step_definitions/alx_help_steps.rb
|
102
|
+
- features/support/alx_extensions.rb
|
103
|
+
- features/support/env.rb
|
104
|
+
- lib/alx/add_handler.rb
|
105
|
+
- lib/alx/book.rb
|
106
|
+
- lib/alx/configuration.rb
|
107
|
+
- lib/alx/controller.rb
|
108
|
+
- lib/alx/editor.rb
|
109
|
+
- lib/alx/executer.rb
|
110
|
+
- lib/alx/handler.rb
|
111
|
+
- lib/alx/help_handler.rb
|
112
|
+
- lib/alx/library.rb
|
113
|
+
- lib/alx/list_handler.rb
|
114
|
+
- lib/alx/remove_handler.rb
|
115
|
+
- lib/alx/renderer.rb
|
116
|
+
- lib/alx/show_handler.rb
|
117
|
+
- lib/alx/version.rb
|
118
|
+
- lib/alx/viewer.rb
|
119
|
+
- test/tc_book.rb
|
120
|
+
- test/tc_controller.rb
|
121
|
+
- test/tc_editor.rb
|
122
|
+
- test/tc_library.rb
|
123
|
+
- test/tc_list_handler.rb
|
124
|
+
- test/tc_renderer.rb
|
125
|
+
- test/tc_viewer.rb
|
126
|
+
- test/test_helper.rb
|
127
|
+
homepage: http://github.com/PeterHajdu/alx
|
128
|
+
licenses: []
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 1.8.23
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: An easy to use command line text document manager. ( beta )
|
151
|
+
test_files:
|
152
|
+
- features/add_books.feature
|
153
|
+
- features/create_default_configuration.feature
|
154
|
+
- features/give_meaningful_help.feature
|
155
|
+
- features/remove_book.feature
|
156
|
+
- features/step_definitions/alx_base_steps.rb
|
157
|
+
- features/step_definitions/alx_configuration_steps.rb
|
158
|
+
- features/step_definitions/alx_help_steps.rb
|
159
|
+
- features/support/alx_extensions.rb
|
160
|
+
- features/support/env.rb
|
161
|
+
- test/tc_book.rb
|
162
|
+
- test/tc_controller.rb
|
163
|
+
- test/tc_editor.rb
|
164
|
+
- test/tc_library.rb
|
165
|
+
- test/tc_list_handler.rb
|
166
|
+
- test/tc_renderer.rb
|
167
|
+
- test/tc_viewer.rb
|
168
|
+
- test/test_helper.rb
|