pakada 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,69 +0,0 @@
1
- class Pakada
2
- module TestCase
3
- def create_files(files)
4
- files.each do |name, content|
5
- File.open(name, "w") do |f|
6
- f.write(content)
7
- end
8
- end
9
- end
10
-
11
- def stub_gemspecs(paths)
12
- @stubbed_gemspecs ||= []
13
- @load_path_diff ||= []
14
-
15
- old_load_path = $LOAD_PATH.dup
16
-
17
- paths.each do |path|
18
- spec = eval(File.read(path))
19
- dir = File.expand_path(File.dirname(path))
20
-
21
- spec.stubs(:full_gem_path).returns(dir)
22
- spec.stubs(:load_paths).returns([dir + "/lib"])
23
- Gem.loaded_specs[spec.name] = spec
24
- @stubbed_gemspecs << spec.name
25
-
26
- $LOAD_PATH.unshift(spec.load_paths.first)
27
- end
28
-
29
- @load_path_diff += $LOAD_PATH - old_load_path
30
- end
31
-
32
- def revert_gemspecs()
33
- @stubbed_gemspecs.each {|name| Gem.loaded_specs.delete(name) }
34
- @load_path_diff.each {|path| $LOAD_PATH.delete(path) }
35
-
36
- @stubbed_gemspecs = nil
37
- @load_path_diff = nil
38
- end
39
-
40
- def self.included(klass)
41
- klass.extend(ClassMethods)
42
- end
43
-
44
- module ClassMethods
45
- def setup(&block)
46
- define_method(:setup, &block)
47
- end
48
-
49
- def teardown(&block)
50
- define_method(:teardown, &block)
51
- end
52
-
53
- def test(name, &block)
54
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
55
-
56
- defined = instance_method(test_name) rescue false
57
- raise "#{test_name} is already defined in #{self}" if defined
58
-
59
- if block_given?
60
- define_method(test_name, &block)
61
- else
62
- define_method(test_name) do
63
- flunk "No implementation provided for #{name}"
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
data/tasks/test.rb DELETED
@@ -1,73 +0,0 @@
1
- require "rake/testtask"
2
-
3
- desc " => rake test"
4
- task " " => :default
5
- task :default => :test
6
-
7
- desc "Test all modules as well as Pakada's core"
8
- task :test do
9
- Rake::Task["test:*"].execute
10
- end
11
-
12
- namespace :test do
13
- desc "Test the module 'my_module'"
14
- task :"my_module"
15
-
16
- desc "Test the modules 'my_module' and 'another_module' as well as Pakada's core"
17
- task :"my_module+another_module+core"
18
- end
19
-
20
- rule /^test(:.+)?$/ do |t|
21
- arg = (t.name || "*").split(":").last
22
- modules = []
23
-
24
- if arg == "*"
25
- modules << "core"
26
- modules += Pakada::Module.descendants.keys
27
- else
28
- modules = arg.split("+")
29
- end
30
-
31
- modules.each do |mod|
32
- puts "-----"
33
- puts "Testing #{mod}"
34
-
35
- runner = "rake/rake_test_loader.rb"
36
- $LOAD_PATH.each do |p|
37
- path = File.join p, runner
38
- if File.exist? path
39
- runner = path
40
- break
41
- end
42
- end
43
-
44
- dir = File.expand_path(if mod == "core"
45
- File.dirname(__FILE__) + "/.."
46
- else
47
- Pakada::Module.descendants[mod.to_sym][:path] rescue raise("Unknown module: #{mod}")
48
- end)
49
- files = FileList[dir + "/test/**/*_test.rb"]
50
-
51
- opts = []
52
- opts << "-rubygems"
53
- opts << "-C#{dir}"
54
- opts << "-I#{Gem.loaded_specs["pakada"].full_gem_path}/lib"
55
-
56
- ["_", "PWD", "GEM_PATH", "GEM_HOME"].each {|k| ENV.delete(k) }
57
- ENV["BUNDLE_GEMFILE"] = if File.exist?(dir + "/Gemfile")
58
- dir + "/Gemfile"
59
- else
60
- File.expand_path("Gemfile")
61
- end
62
-
63
- begin
64
- cmd = FileUtils::RUBY + " " + [
65
- opts.join(" "),
66
- runner,
67
- files.map{|f| %("#{f}") }.join(" "),
68
- ].join(" ")
69
- system(cmd)
70
- rescue
71
- end
72
- end
73
- end
data/test/files.rb DELETED
@@ -1,60 +0,0 @@
1
- FILES = {
2
-
3
- "config/middleware.yml" => <<-CODE,
4
- :testing:
5
- - Rack::ShowExceptions
6
- - Rack::Static:
7
- :urls:
8
- - /images
9
- :root: public
10
- CODE
11
-
12
- "modules/foo/pakada0-foo.gemspec" => <<-CODE,
13
- Gem::Specification.new do |s|
14
- s.name = "pakada0-foo"
15
- s.version = "0.1.0dev"
16
- s.platform = Gem::Platform::RUBY
17
- s.authors = ["Lars Gierth"]
18
- s.email = ["lgierth@entwickler.com"]
19
- s.homepage = "http://github.com/lgierth/pakada"
20
- s.summary = "nothing"
21
-
22
- s.add_dependency "pakada"
23
-
24
- s.files = ["module.rb"]
25
- s.require_path = "lib"
26
-
27
- s.required_rubygems_version = ">= 1.3.6"
28
- end
29
- CODE
30
- "modules/foo/module.rb" => <<-CODE,
31
- class FooModule
32
- include Pakada::Module
33
- end
34
- CODE
35
-
36
- "modules/bar/pakada0-bar.gemspec" => <<-CODE,
37
- Gem::Specification.new do |s|
38
- s.name = "pakada0-bar"
39
- s.version = "0.1.0dev"
40
- s.platform = Gem::Platform::RUBY
41
- s.authors = ["Lars Gierth"]
42
- s.email = ["lgierth@entwickler.com"]
43
- s.homepage = "http://github.com/lgierth/pakada"
44
- s.summary = "nothing"
45
-
46
- s.add_dependency "pakada"
47
-
48
- s.files = ["module.rb"]
49
- s.require_path = "lib"
50
-
51
- s.required_rubygems_version = ">= 1.3.6"
52
- end
53
- CODE
54
- "modules/bar/module.rb" => <<-CODE,
55
- class BarModule
56
- include Pakada::Module
57
- end
58
- CODE
59
-
60
- }
data/test/helper.rb DELETED
@@ -1 +0,0 @@
1
- require "pakada/test"
data/test/module_test.rb DELETED
@@ -1,81 +0,0 @@
1
- require "test/helper"
2
- require "test/files"
3
-
4
- class ModuleTest < Test::Unit::TestCase
5
- setup do
6
- FakeFS.activate!
7
- FakeFS::Require.activate!({
8
- :fallback => true,
9
- :load => true,
10
- :autoload => true,
11
- })
12
- create_files(FILES)
13
-
14
- stub_gemspecs([
15
- "modules/foo/pakada0-foo.gemspec",
16
- "modules/bar/pakada0-bar.gemspec",
17
- ])
18
- end
19
-
20
- teardown do
21
- revert_gemspecs
22
- Mocha::Mockery.instance.teardown
23
-
24
- Pakada.shutdown
25
-
26
- FakeFS::FileSystem.clear
27
- FakeFS::Require.deactivate!
28
- FakeFS.deactivate!
29
- end
30
-
31
- test "prepares modules" do
32
- Pakada::Module.prepare
33
- modules = Pakada::Module.descendants
34
-
35
- assert_equal 2, modules.length
36
- assert_equal File.expand_path("modules/foo"), modules[:foo][:path]
37
- assert_equal "pakada0-foo", modules[:foo][:gemspec].name
38
- end
39
-
40
- test "loads modules" do
41
- Pakada::Module.load
42
- modules = Pakada::Module.descendants
43
-
44
- assert_equal 2, modules.length
45
- assert_equal FooModule, modules[:foo][:klass]
46
- end
47
-
48
- test "has hooks" do
49
- Pakada::Module.load
50
-
51
- FooModule.class_eval do
52
- hook :asd do
53
- end
54
- end
55
-
56
- assert(FooModule.class_eval { @hooks[:asd] })
57
- assert_equal 1, FooModule.class_eval { @hooks[:asd].length }
58
- end
59
-
60
- test "executes hooks" do
61
- Pakada.boot
62
-
63
- FooModule.class_eval do
64
- hook :something do |state|
65
- state.called = true
66
- end
67
- end
68
-
69
- state = Struct.new(:called).new
70
- Pakada.hook :something, state
71
-
72
- assert state.called
73
- end
74
-
75
- test "has a version" do
76
- Pakada.boot
77
-
78
- version = Gem.loaded_specs["pakada0-foo"].version.to_s
79
- assert_equal version, Pakada[:foo].version
80
- end
81
- end
data/test/pakada_test.rb DELETED
@@ -1,80 +0,0 @@
1
- require "test/helper"
2
- require "test/files"
3
-
4
- class PakadaTest < Test::Unit::TestCase
5
- setup do
6
- FakeFS.activate!
7
- FakeFS::Require.activate!({
8
- :fallback => true,
9
- :load => true,
10
- :autoload => true,
11
- })
12
- create_files(FILES)
13
-
14
- stub_gemspecs([
15
- "modules/foo/pakada0-foo.gemspec",
16
- "modules/bar/pakada0-bar.gemspec",
17
- ])
18
- end
19
-
20
- teardown do
21
- revert_gemspecs
22
- Mocha::Mockery.instance.teardown
23
-
24
- Pakada.shutdown
25
-
26
- FakeFS::FileSystem.clear
27
- FakeFS::Require.deactivate!
28
- FakeFS.deactivate!
29
- end
30
-
31
- test "maintains a Rack middleware stack" do
32
- Rack::Builder.any_instance.expects(:use).with(Rack::ShowExceptions)
33
- Rack::Builder.any_instance.expects(:use).with(Rack::Static, {
34
- :urls => ["/images"],
35
- :root => "public",
36
- })
37
- Pakada.boot
38
- end
39
-
40
- test "executes modules' hooks" do
41
- Pakada.boot
42
- Pakada[:foo].class.class_eval do
43
- hook(:foobar) do
44
- end
45
- end
46
-
47
- Pakada[:foo].expects(:hook).once.with(:foobar, 123)
48
- Pakada.hook(:foobar, 123)
49
- end
50
-
51
- test "cancels the execution of a hook when it catches :halt" do
52
- Pakada.boot
53
- Pakada[:foo].class.class_eval do
54
- hook(:foobar) do |state|
55
- throw :halt
56
- state.after_throw = true
57
- end
58
- end
59
-
60
- state = Struct.new(:after_throw).new
61
- Pakada.hook(:foobar, state)
62
-
63
- assert !state.after_throw
64
- end
65
-
66
- test "provides a Rack application end-point" do
67
- Rack::Builder.any_instance.expects(:run).with(Pakada::Application)
68
-
69
- Pakada.boot
70
- assert_equal Rack::ShowExceptions, Pakada.app.class
71
- end
72
-
73
- test "prints a greeting when the response would be empty" do
74
- Pakada.boot
75
- Pakada.stubs(:hook)
76
-
77
- resp = Pakada.app.call("PATH_INFO" => "/")
78
- assert_equal "Hi, I'm Pakada!", resp[2].body.to_s
79
- end
80
- end