pico 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 +24 -0
- data/.vimrc +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +33 -0
- data/gold_master_apps/tic_tac_toe/Gemfile +18 -0
- data/gold_master_apps/tic_tac_toe/Rakefile +3 -0
- data/gold_master_apps/tic_tac_toe/boot.rb +2 -0
- data/gold_master_apps/tic_tac_toe/config/application.rb +8 -0
- data/gold_master_apps/tic_tac_toe/config/environments/test.rb +3 -0
- data/gold_master_apps/tic_tac_toe/game/bad_move.rb +1 -0
- data/gold_master_apps/tic_tac_toe/game/game.rb +62 -0
- data/gold_master_apps/tic_tac_toe/game/make_move_command.rb +38 -0
- data/gold_master_apps/tic_tac_toe/game/memory_repository.rb +39 -0
- data/gold_master_apps/tic_tac_toe/test/game_test.rb +65 -0
- data/gold_master_apps/tic_tac_toe/test/reports/TEST-GameTest.xml +13 -0
- data/gold_master_apps/tic_tac_toe/test/test_helper.rb +7 -0
- data/lib/pico.rb +41 -0
- data/lib/pico/application.rb +120 -0
- data/lib/pico/autoloader.rb +131 -0
- data/lib/pico/context.rb +89 -0
- data/lib/pico/context/const_resolver.rb +80 -0
- data/lib/pico/pry_context.rb +71 -0
- data/lib/pico/rake.rb +15 -0
- data/lib/pico/ruse_extensions.rb +9 -0
- data/lib/pico/string_inflections.rb +30 -0
- data/lib/pico/test_runner.rb +27 -0
- data/lib/pico/version.rb +3 -0
- data/pico.gemspec +30 -0
- data/test/integration/autoloading_test.rb +47 -0
- data/test/support/fakes_filesystem.rb +182 -0
- data/test/support/tests_autoloading.rb +16 -0
- data/test/test_helper.rb +36 -0
- data/test/unit/application_test.rb +79 -0
- data/test/unit/autoloader_test.rb +68 -0
- data/test/unit/context_test.rb +80 -0
- metadata +202 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AutoloaderTest < Minitest::Test
|
4
|
+
include FakesFilesystem
|
5
|
+
include TestsAutoloading
|
6
|
+
|
7
|
+
def test_throws_constant_when_found
|
8
|
+
const = assert_catches :const do
|
9
|
+
Pico::Autoloader.handle :A, from: Foo
|
10
|
+
end
|
11
|
+
assert_equal 'Foo::A', const.name
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_raises_error_when_const_not_found
|
15
|
+
exception = assert_raises NameError do
|
16
|
+
Pico::Autoloader.handle :Abracadabra, from: Foo
|
17
|
+
end
|
18
|
+
assert_equal 'uninitialized constant Abracadabra (in Foo)', exception.message
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_simple_implicit_namespace_case
|
22
|
+
Pico::Autoloader.handle :B, from: Foo
|
23
|
+
const = assert_catches :const do
|
24
|
+
Pico::Autoloader.handle :BA, from: Foo
|
25
|
+
end
|
26
|
+
assert_equal 'Foo::B::BA', const.name
|
27
|
+
assert_nil Pico::Autoloader.current_autoloader
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_cleanup_after_implicit_namespace
|
31
|
+
Pico::Autoloader.handle :B, from: Foo
|
32
|
+
assert_raises NameError do
|
33
|
+
Pico::Autoloader.handle :Abracadabra, from: Foo
|
34
|
+
end
|
35
|
+
assert_nil Pico::Autoloader.current_autoloader
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_deeply_nested_module_with_implicit_namespaces
|
39
|
+
%i(C CA CAA).each do |implicit_namespace|
|
40
|
+
Pico::Autoloader.handle implicit_namespace, from: Foo
|
41
|
+
end
|
42
|
+
const = assert_catches :const do
|
43
|
+
Pico::Autoloader.handle :CAAA, from: Foo
|
44
|
+
end
|
45
|
+
assert_equal 'Foo::C::CA::CAA::CAAA', const.name
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_shallowly_nested_module_with_implicit_namespaces
|
49
|
+
@foo.resolve_const 'A::AB::ABA'
|
50
|
+
|
51
|
+
const = assert_catches :const do
|
52
|
+
Pico::Autoloader.handle :ABB, from: Foo::A::AB::ABA
|
53
|
+
end
|
54
|
+
assert_equal 'Foo::A::AB::ABB', const.name
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def assert_catches(thrown)
|
60
|
+
val = catch thrown do
|
61
|
+
yield
|
62
|
+
:not_found
|
63
|
+
end
|
64
|
+
refute_equal :not_found, val, "Expected block to throw #{thrown.inspect}"
|
65
|
+
val
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ContextTest < Minitest::Test
|
4
|
+
include FakesFilesystem
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@context = Pico.define_context :Foo, root: "/foo"
|
8
|
+
@context.boot!
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_resolving_constant
|
12
|
+
mod = @context.resolve_const(:A)
|
13
|
+
assert_autoloaded_module 'A', mod
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_resolving_deep_constant
|
17
|
+
mod = @context.resolve_const('A::AA')
|
18
|
+
assert_autoloaded_module 'A::AA', mod
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_resolving_inner_constant
|
22
|
+
mod = @context.resolve_const('A::AB::ABA')
|
23
|
+
assert_autoloaded_module 'A::AB::ABA', mod
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_parent_namespace_defined_in_child
|
27
|
+
mod = @context.resolve_const('B::BA')
|
28
|
+
assert_autoloaded_module 'B::BA', mod
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_returns_nil_if_constant_isnt_defined
|
32
|
+
assert_nil @context.resolve_const(:Abracadabra)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_raises_error_if_corresponding_file_did_not_define_constant
|
36
|
+
File.write "/foo/abracadabra.rb", ""
|
37
|
+
|
38
|
+
exception = assert_raises(Pico::AutoloadError) do
|
39
|
+
@context.resolve_const(:Abracadabra)
|
40
|
+
end
|
41
|
+
|
42
|
+
expected_message = %r{Expected /foo/abracadabra\.rb to define Abracadabra}
|
43
|
+
assert_match expected_message, exception.message
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_nesting_context
|
47
|
+
nested_context = Pico.define_context :Bar, root: "/bar", parent: 'Foo'
|
48
|
+
nested_context.boot!
|
49
|
+
|
50
|
+
mod = nested_context.resolve_const('A')
|
51
|
+
assert_autoloaded_module 'Bar::A', mod
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_eager_load
|
55
|
+
refute Foo.const_defined?(:A)
|
56
|
+
@context.eager_load!
|
57
|
+
assert Foo.const_defined?(:A)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_reload_drops_constant_references
|
61
|
+
@context.eager_load!
|
62
|
+
assert Foo.const_defined?(:A)
|
63
|
+
@context.reload!
|
64
|
+
refute Foo.const_defined?(:A)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_shutdown_removes_const
|
68
|
+
assert @context.booted?
|
69
|
+
@context.shutdown!
|
70
|
+
refute @context.booted?
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def assert_autoloaded_module(expected_name, mod)
|
76
|
+
assert_kind_of Module, mod
|
77
|
+
assert_equal "Foo::#{expected_name}", mod.name
|
78
|
+
assert_equal "hello from #{expected_name}", mod.message
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pico
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ntl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruse
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
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: fakefs
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-reporters
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: A very light weight framework for ruby designed to handle a small number
|
126
|
+
of details common to most every application.
|
127
|
+
email:
|
128
|
+
- nathanladd+github@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".vimrc"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- gold_master_apps/tic_tac_toe/Gemfile
|
140
|
+
- gold_master_apps/tic_tac_toe/Rakefile
|
141
|
+
- gold_master_apps/tic_tac_toe/boot.rb
|
142
|
+
- gold_master_apps/tic_tac_toe/config/application.rb
|
143
|
+
- gold_master_apps/tic_tac_toe/config/environments/test.rb
|
144
|
+
- gold_master_apps/tic_tac_toe/game/bad_move.rb
|
145
|
+
- gold_master_apps/tic_tac_toe/game/game.rb
|
146
|
+
- gold_master_apps/tic_tac_toe/game/make_move_command.rb
|
147
|
+
- gold_master_apps/tic_tac_toe/game/memory_repository.rb
|
148
|
+
- gold_master_apps/tic_tac_toe/test/game_test.rb
|
149
|
+
- gold_master_apps/tic_tac_toe/test/reports/TEST-GameTest.xml
|
150
|
+
- gold_master_apps/tic_tac_toe/test/test_helper.rb
|
151
|
+
- lib/pico.rb
|
152
|
+
- lib/pico/application.rb
|
153
|
+
- lib/pico/autoloader.rb
|
154
|
+
- lib/pico/context.rb
|
155
|
+
- lib/pico/context/const_resolver.rb
|
156
|
+
- lib/pico/pry_context.rb
|
157
|
+
- lib/pico/rake.rb
|
158
|
+
- lib/pico/ruse_extensions.rb
|
159
|
+
- lib/pico/string_inflections.rb
|
160
|
+
- lib/pico/test_runner.rb
|
161
|
+
- lib/pico/version.rb
|
162
|
+
- pico.gemspec
|
163
|
+
- test/integration/autoloading_test.rb
|
164
|
+
- test/support/fakes_filesystem.rb
|
165
|
+
- test/support/tests_autoloading.rb
|
166
|
+
- test/test_helper.rb
|
167
|
+
- test/unit/application_test.rb
|
168
|
+
- test/unit/autoloader_test.rb
|
169
|
+
- test/unit/context_test.rb
|
170
|
+
homepage: https://github.com/ntl/pico
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata: {}
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.2.2
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: Pico is a micro framework designed to get you some basic, essential functionality
|
194
|
+
and then get out of your way.
|
195
|
+
test_files:
|
196
|
+
- test/integration/autoloading_test.rb
|
197
|
+
- test/support/fakes_filesystem.rb
|
198
|
+
- test/support/tests_autoloading.rb
|
199
|
+
- test/test_helper.rb
|
200
|
+
- test/unit/application_test.rb
|
201
|
+
- test/unit/autoloader_test.rb
|
202
|
+
- test/unit/context_test.rb
|