rubycut-babushka 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +31 -0
- data/README.markdown +246 -0
- data/Rakefile +26 -0
- data/bin/babushka +11 -0
- data/deps/babushka.rb +101 -0
- data/deps/dev.rb +12 -0
- data/deps/fhs.rb +31 -0
- data/deps/git.rb +29 -0
- data/deps/homebrew.rb +30 -0
- data/deps/os_x.rb +33 -0
- data/deps/packages.rb +22 -0
- data/deps/pkg_managers.rb +110 -0
- data/deps/ruby.rb +23 -0
- data/deps/rubygems.rb +24 -0
- data/deps/system.rb +10 -0
- data/deps/templates/app.rb +68 -0
- data/deps/templates/external.rb +12 -0
- data/deps/templates/installer.rb +31 -0
- data/deps/templates/managed.rb +105 -0
- data/deps/templates/ppa.rb +24 -0
- data/deps/templates/src.rb +42 -0
- data/deps/templates/tmbundle.rb +15 -0
- data/lib/babushka.rb +28 -0
- data/lib/babushka/accepts_block_for.rb +72 -0
- data/lib/babushka/accepts_list_for.rb +49 -0
- data/lib/babushka/accepts_value_for.rb +24 -0
- data/lib/babushka/base.rb +78 -0
- data/lib/babushka/bug_reporter.rb +55 -0
- data/lib/babushka/cmdline.rb +133 -0
- data/lib/babushka/cmdline/handler.rb +41 -0
- data/lib/babushka/cmdline/helpers.rb +127 -0
- data/lib/babushka/cmdline/parser.rb +69 -0
- data/lib/babushka/colorizer.rb +59 -0
- data/lib/babushka/core_patches/array.rb +171 -0
- data/lib/babushka/core_patches/blank.rb +22 -0
- data/lib/babushka/core_patches/bytes.rb +52 -0
- data/lib/babushka/core_patches/hash.rb +107 -0
- data/lib/babushka/core_patches/hashish.rb +14 -0
- data/lib/babushka/core_patches/integer.rb +25 -0
- data/lib/babushka/core_patches/io.rb +8 -0
- data/lib/babushka/core_patches/numeric.rb +16 -0
- data/lib/babushka/core_patches/object.rb +27 -0
- data/lib/babushka/core_patches/string.rb +116 -0
- data/lib/babushka/core_patches/symbol.rb +12 -0
- data/lib/babushka/core_patches/try.rb +15 -0
- data/lib/babushka/core_patches/uri.rb +24 -0
- data/lib/babushka/dep.rb +470 -0
- data/lib/babushka/dep_context.rb +18 -0
- data/lib/babushka/dep_definer.rb +115 -0
- data/lib/babushka/dep_pool.rb +49 -0
- data/lib/babushka/dep_runner.rb +85 -0
- data/lib/babushka/dsl.rb +26 -0
- data/lib/babushka/git_repo.rb +185 -0
- data/lib/babushka/helpers/git_helpers.rb +32 -0
- data/lib/babushka/helpers/log_helpers.rb +176 -0
- data/lib/babushka/helpers/path_helpers.rb +34 -0
- data/lib/babushka/helpers/run_helpers.rb +145 -0
- data/lib/babushka/helpers/shell_helpers.rb +229 -0
- data/lib/babushka/helpers/suggest_helpers.rb +16 -0
- data/lib/babushka/helpers/uri_helpers.rb +36 -0
- data/lib/babushka/ip.rb +160 -0
- data/lib/babushka/lambda_chooser.rb +40 -0
- data/lib/babushka/levenshtein.rb +125 -0
- data/lib/babushka/meta_dep.rb +65 -0
- data/lib/babushka/meta_dep_context.rb +15 -0
- data/lib/babushka/parameter.rb +143 -0
- data/lib/babushka/pkg_helper.rb +81 -0
- data/lib/babushka/pkg_helpers/apt_helper.rb +61 -0
- data/lib/babushka/pkg_helpers/base_helper.rb +19 -0
- data/lib/babushka/pkg_helpers/binpkgsrc_helper.rb +48 -0
- data/lib/babushka/pkg_helpers/binports_helper.rb +34 -0
- data/lib/babushka/pkg_helpers/brew_helper.rb +110 -0
- data/lib/babushka/pkg_helpers/gem_helper.rb +120 -0
- data/lib/babushka/pkg_helpers/macports_helper.rb +22 -0
- data/lib/babushka/pkg_helpers/npm_helper.rb +45 -0
- data/lib/babushka/pkg_helpers/pacman_helper.rb +27 -0
- data/lib/babushka/pkg_helpers/pip_helper.rb +45 -0
- data/lib/babushka/pkg_helpers/src_helper.rb +16 -0
- data/lib/babushka/pkg_helpers/yum_helper.rb +25 -0
- data/lib/babushka/popen.rb +40 -0
- data/lib/babushka/prompt.rb +176 -0
- data/lib/babushka/renderable.rb +67 -0
- data/lib/babushka/resource.rb +215 -0
- data/lib/babushka/run_reporter.rb +60 -0
- data/lib/babushka/shell.rb +108 -0
- data/lib/babushka/source.rb +216 -0
- data/lib/babushka/source_pool.rb +146 -0
- data/lib/babushka/system_definitions.rb +97 -0
- data/lib/babushka/system_profile.rb +210 -0
- data/lib/babushka/task.rb +142 -0
- data/lib/babushka/vars.rb +108 -0
- data/lib/babushka/version_of.rb +65 -0
- data/lib/babushka/version_str.rb +57 -0
- data/lib/babushka/xml_string.rb +28 -0
- data/lib/components.rb +82 -0
- data/lib/fancypath/fancypath.rb +200 -0
- data/lib/inkan/inkan.rb +76 -0
- data/spec/acceptance/acceptance.rb +43 -0
- data/spec/acceptance_helper.rb +113 -0
- data/spec/archives/Blah.app.zip +0 -0
- data/spec/archives/archive.tar +0 -0
- data/spec/archives/archive.tar.bz2 +0 -0
- data/spec/archives/archive.tar.gz +0 -0
- data/spec/archives/archive.tbz2 +0 -0
- data/spec/archives/archive.tgz +0 -0
- data/spec/archives/archive.zip +0 -0
- data/spec/archives/content.txt +5 -0
- data/spec/archives/invalid_archive +5 -0
- data/spec/archives/nested archive/content.txt +5 -0
- data/spec/archives/nested_archive.tar +0 -0
- data/spec/archives/really_a_gzip.zip +0 -0
- data/spec/archives/test-0.3.1.tgz +0 -0
- data/spec/archives/tgz_archive +0 -0
- data/spec/archives/zip_without_extension +0 -0
- data/spec/babushka/accepts_for_spec.rb +174 -0
- data/spec/babushka/accepts_for_support.rb +72 -0
- data/spec/babushka/cmdline/console_spec.rb +11 -0
- data/spec/babushka/cmdline/help_spec.rb +61 -0
- data/spec/babushka/cmdline/version_spec.rb +10 -0
- data/spec/babushka/core_patches_spec.rb +171 -0
- data/spec/babushka/dep_context_spec.rb +58 -0
- data/spec/babushka/dep_definer_spec.rb +152 -0
- data/spec/babushka/dep_definer_support.rb +36 -0
- data/spec/babushka/dep_spec.rb +567 -0
- data/spec/babushka/dep_support.rb +29 -0
- data/spec/babushka/deps_spec.rb +113 -0
- data/spec/babushka/gem_helper_spec.rb +90 -0
- data/spec/babushka/git_repo_spec.rb +396 -0
- data/spec/babushka/ip_spec.rb +131 -0
- data/spec/babushka/lambda_chooser_spec.rb +115 -0
- data/spec/babushka/meta_dep_definer_spec.rb +127 -0
- data/spec/babushka/meta_dep_wrapper_spec.rb +32 -0
- data/spec/babushka/parameter_spec.rb +135 -0
- data/spec/babushka/path_helpers_spec.rb +102 -0
- data/spec/babushka/prompt_spec.rb +188 -0
- data/spec/babushka/renderable_spec.rb +100 -0
- data/spec/babushka/resource_spec.rb +141 -0
- data/spec/babushka/run_helpers_spec.rb +26 -0
- data/spec/babushka/shell_helpers_spec.rb +244 -0
- data/spec/babushka/shell_spec.rb +19 -0
- data/spec/babushka/source_pool_spec.rb +320 -0
- data/spec/babushka/source_pool_support.rb +31 -0
- data/spec/babushka/source_spec.rb +382 -0
- data/spec/babushka/source_support.rb +17 -0
- data/spec/babushka/system_profile_spec.rb +61 -0
- data/spec/babushka/task_spec.rb +141 -0
- data/spec/babushka/uri_spec.rb +13 -0
- data/spec/babushka/vars_spec.rb +59 -0
- data/spec/babushka/version_of_spec.rb +110 -0
- data/spec/babushka/version_str_spec.rb +130 -0
- data/spec/babushka/version_str_support.rb +37 -0
- data/spec/babushka/xml_string_spec.rb +98 -0
- data/spec/deps/bad/broken.rb +7 -0
- data/spec/deps/bad/working.rb +3 -0
- data/spec/deps/good/meta.rb +14 -0
- data/spec/deps/good/test.rb +11 -0
- data/spec/deps/outer/deps.rb +19 -0
- data/spec/deps/outer/more deps.rb +11 -0
- data/spec/deps/params/params.rb +10 -0
- data/spec/fancypath/fancypath_spec.rb +272 -0
- data/spec/fancypath_support.rb +10 -0
- data/spec/inkan/inkan_spec.rb +217 -0
- data/spec/renderable/different_example.conf.erb +4 -0
- data/spec/renderable/example.conf.erb +3 -0
- data/spec/renderable/example.sh +6 -0
- data/spec/renderable/with_binding.conf.erb +4 -0
- data/spec/renderable/xml_example.conf.erb +8 -0
- data/spec/repos/remote.git.tgz +0 -0
- data/spec/spec_helper.rb +87 -0
- metadata +238 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'acceptance_helper'
|
2
|
+
|
3
|
+
describe "babushka" do
|
4
|
+
before(:all) {
|
5
|
+
@vm = VM.instance
|
6
|
+
@vm.run 'bash -c "`wget -O - babushka.me/up/hard`"'
|
7
|
+
}
|
8
|
+
|
9
|
+
context "basics" do
|
10
|
+
it "should have installed babushka" do
|
11
|
+
@vm.run('babushka --version').should =~ /^[\d.]+$/
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "core deps" do
|
16
|
+
it "should install build tools" do
|
17
|
+
@vm.should meet('build tools')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "some of my deps" do
|
22
|
+
it "should configure the system" do
|
23
|
+
@vm.babushka('benhoskings:system') # once to set the locale
|
24
|
+
@vm.should meet('benhoskings:system')
|
25
|
+
end
|
26
|
+
it "should build ruby 1.9" do
|
27
|
+
@vm.should meet('benhoskings:ruby19.src')
|
28
|
+
end
|
29
|
+
it "should set up nginx" do
|
30
|
+
@vm.should meet('benhoskings:webserver running.nginx')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# It's important to have a wide range of deps here, so please suggest
|
35
|
+
# stable deps of your own that I can add to the list. The intention isn't
|
36
|
+
# to run every dep ever, just a representative set that together cover
|
37
|
+
# babushka's scope.
|
38
|
+
context "community deps" do
|
39
|
+
it "should build node and coffee-script" do
|
40
|
+
@vm.should meet('dgoodlad:coffeescript.src')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
require 'yaml'
|
5
|
+
require 'cloudservers'
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
class Babushka::Logging
|
10
|
+
def self.print_log message, printable
|
11
|
+
print message if printable
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class VM
|
16
|
+
include Singleton
|
17
|
+
include Babushka::LogHelpers
|
18
|
+
include Babushka::ShellHelpers
|
19
|
+
|
20
|
+
SERVER_NAME = 'babushka-specs'
|
21
|
+
|
22
|
+
def babushka task
|
23
|
+
run("babushka \"#{task}\" --defaults --no-colour").tap {|result|
|
24
|
+
# Fetch the debug log if the dep failed
|
25
|
+
run "cat ~/.babushka/logs/\"#{task}\"" unless result
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def run cmd, user = 'root'
|
30
|
+
log "\nRunning on #{user}@#{host}: #{cmd}" do
|
31
|
+
shell "ssh #{user}@#{host} '#{cmd}'", :log => true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def server
|
36
|
+
@_server || (existing_server || create_server).tap {|s|
|
37
|
+
wait_for_server
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def existing_server
|
44
|
+
server_detail = connection.list_servers_detail.detect {|s| s[:name] == SERVER_NAME }
|
45
|
+
unless server_detail.nil?
|
46
|
+
log "A server is already running."
|
47
|
+
@_server = connection.get_server(server_detail[:id])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_server
|
52
|
+
log_block "Creating a #{flavor[:ram]}MB #{image[:name]} rackspace instance" do
|
53
|
+
@_server = connection.create_server(image_args)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def wait_for_server
|
58
|
+
if server.status != 'ACTIVE'
|
59
|
+
log_block "Waiting for the server to come online" do
|
60
|
+
until server.status == 'ACTIVE'
|
61
|
+
sleep 3
|
62
|
+
print '.'
|
63
|
+
server.refresh
|
64
|
+
end
|
65
|
+
server.status == 'ACTIVE'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def host
|
71
|
+
server.addresses[:public].first
|
72
|
+
end
|
73
|
+
|
74
|
+
def image_args
|
75
|
+
{
|
76
|
+
:name => SERVER_NAME,
|
77
|
+
:imageId => image[:id],
|
78
|
+
:flavorId => flavor[:id],
|
79
|
+
:personality => {
|
80
|
+
public_key => '/root/.ssh/authorized_keys'
|
81
|
+
}
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
def image
|
86
|
+
connection.list_images.detect {|image| image[:name][cfg['image_name']] }
|
87
|
+
end
|
88
|
+
|
89
|
+
def flavor
|
90
|
+
connection.list_flavors.detect {|flavor| flavor[:ram] == 256 }
|
91
|
+
end
|
92
|
+
|
93
|
+
def connection
|
94
|
+
@_connection ||= CloudServers::Connection.new(
|
95
|
+
:username => cfg['username'], :api_key => cfg['api_key']
|
96
|
+
)
|
97
|
+
end
|
98
|
+
def cfg
|
99
|
+
@_cfg ||= YAML.load_file(Babushka::Path.path / 'conf/rackspace.yml')
|
100
|
+
end
|
101
|
+
def public_key
|
102
|
+
Dir.glob(File.expand_path("~/.ssh/id_[dr]sa.pub")).first
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
RSpec::Matchers.define :meet do |expected|
|
107
|
+
match {|vm|
|
108
|
+
vm.babushka(expected).should =~ /^\} ✓ #{Regexp.escape(expected)}\z/
|
109
|
+
}
|
110
|
+
failure_message_for_should {|vm|
|
111
|
+
"The '#{expected}' dep couldn't bet met."
|
112
|
+
}
|
113
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed augue lorem, viverra id consectetur ut, aliquet dapibus nulla. Morbi risus lacus, egestas nec consequat sit amet, aliquam eget quam. Integer justo est, pretium nec gravida ut, rutrum at quam. Maecenas sem enim, laoreet id aliquam sed, vulputate eget massa. Nunc a nulla diam, et mattis sapien. Donec tempus urna id neque porta auctor. Quisque semper porta purus nec convallis. Suspendisse tempus, massa id malesuada vestibulum, ante leo ornare quam, auctor lacinia ipsum enim vel nibh. Curabitur fermentum magna placerat nibh iaculis non tempor nibh sollicitudin. Morbi fermentum, purus sed consectetur pharetra, erat nisl malesuada justo, et facilisis massa purus et quam. Proin volutpat dignissim diam, ac viverra massa aliquam ac. Ut sit amet tortor arcu. Aliquam erat volutpat. Fusce orci nunc, placerat a pellentesque eu, pellentesque sit amet odio. Vivamus vitae augue sit amet orci posuere ultrices sit amet eu velit. Praesent ut velit urna. Praesent ornare turpis nec sapien tincidunt auctor.
|
2
|
+
|
3
|
+
Morbi vel mi lorem, iaculis semper diam. In elit turpis, tincidunt aliquet feugiat gravida, condimentum pellentesque leo. Aenean mi orci, ultrices quis posuere a, suscipit sed leo. Suspendisse adipiscing magna eu ante rutrum viverra. Aenean laoreet luctus lorem, volutpat bibendum eros vestibulum convallis. Donec erat tellus, scelerisque nec accumsan ut, lobortis vitae nisl. Mauris quis enim vel felis posuere tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dolor urna, adipiscing euismod hendrerit non, mattis vel est. Aliquam erat volutpat. In hac habitasse platea dictumst. Cras consequat dolor in dolor euismod eget laoreet massa tristique.
|
4
|
+
|
5
|
+
Nunc molestie ornare odio non blandit. Ut et semper sapien. Nulla sollicitudin lacinia imperdiet. Suspendisse ullamcorper massa lobortis dui fermentum elementum. Donec et ligula nunc. Sed ligula eros, condimentum quis ornare eu, vestibulum quis leo. Praesent cursus lorem sed justo scelerisque laoreet id non purus. Suspendisse sodales justo at arcu pulvinar a viverra ligula adipiscing. Aenean at consequat turpis. Praesent adipiscing, justo quis commodo dapibus, orci justo dictum mauris, eu aliquet nisl purus in turpis.
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed augue lorem, viverra id consectetur ut, aliquet dapibus nulla. Morbi risus lacus, egestas nec consequat sit amet, aliquam eget quam. Integer justo est, pretium nec gravida ut, rutrum at quam. Maecenas sem enim, laoreet id aliquam sed, vulputate eget massa. Nunc a nulla diam, et mattis sapien. Donec tempus urna id neque porta auctor. Quisque semper porta purus nec convallis. Suspendisse tempus, massa id malesuada vestibulum, ante leo ornare quam, auctor lacinia ipsum enim vel nibh. Curabitur fermentum magna placerat nibh iaculis non tempor nibh sollicitudin. Morbi fermentum, purus sed consectetur pharetra, erat nisl malesuada justo, et facilisis massa purus et quam. Proin volutpat dignissim diam, ac viverra massa aliquam ac. Ut sit amet tortor arcu. Aliquam erat volutpat. Fusce orci nunc, placerat a pellentesque eu, pellentesque sit amet odio. Vivamus vitae augue sit amet orci posuere ultrices sit amet eu velit. Praesent ut velit urna. Praesent ornare turpis nec sapien tincidunt auctor.
|
2
|
+
|
3
|
+
Morbi vel mi lorem, iaculis semper diam. In elit turpis, tincidunt aliquet feugiat gravida, condimentum pellentesque leo. Aenean mi orci, ultrices quis posuere a, suscipit sed leo. Suspendisse adipiscing magna eu ante rutrum viverra. Aenean laoreet luctus lorem, volutpat bibendum eros vestibulum convallis. Donec erat tellus, scelerisque nec accumsan ut, lobortis vitae nisl. Mauris quis enim vel felis posuere tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dolor urna, adipiscing euismod hendrerit non, mattis vel est. Aliquam erat volutpat. In hac habitasse platea dictumst. Cras consequat dolor in dolor euismod eget laoreet massa tristique.
|
4
|
+
|
5
|
+
Nunc molestie ornare odio non blandit. Ut et semper sapien. Nulla sollicitudin lacinia imperdiet. Suspendisse ullamcorper massa lobortis dui fermentum elementum. Donec et ligula nunc. Sed ligula eros, condimentum quis ornare eu, vestibulum quis leo. Praesent cursus lorem sed justo scelerisque laoreet id non purus. Suspendisse sodales justo at arcu pulvinar a viverra ligula adipiscing. Aenean at consequat turpis. Praesent adipiscing, justo quis commodo dapibus, orci justo dictum mauris, eu aliquet nisl purus in turpis.
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed augue lorem, viverra id consectetur ut, aliquet dapibus nulla. Morbi risus lacus, egestas nec consequat sit amet, aliquam eget quam. Integer justo est, pretium nec gravida ut, rutrum at quam. Maecenas sem enim, laoreet id aliquam sed, vulputate eget massa. Nunc a nulla diam, et mattis sapien. Donec tempus urna id neque porta auctor. Quisque semper porta purus nec convallis. Suspendisse tempus, massa id malesuada vestibulum, ante leo ornare quam, auctor lacinia ipsum enim vel nibh. Curabitur fermentum magna placerat nibh iaculis non tempor nibh sollicitudin. Morbi fermentum, purus sed consectetur pharetra, erat nisl malesuada justo, et facilisis massa purus et quam. Proin volutpat dignissim diam, ac viverra massa aliquam ac. Ut sit amet tortor arcu. Aliquam erat volutpat. Fusce orci nunc, placerat a pellentesque eu, pellentesque sit amet odio. Vivamus vitae augue sit amet orci posuere ultrices sit amet eu velit. Praesent ut velit urna. Praesent ornare turpis nec sapien tincidunt auctor.
|
2
|
+
|
3
|
+
Morbi vel mi lorem, iaculis semper diam. In elit turpis, tincidunt aliquet feugiat gravida, condimentum pellentesque leo. Aenean mi orci, ultrices quis posuere a, suscipit sed leo. Suspendisse adipiscing magna eu ante rutrum viverra. Aenean laoreet luctus lorem, volutpat bibendum eros vestibulum convallis. Donec erat tellus, scelerisque nec accumsan ut, lobortis vitae nisl. Mauris quis enim vel felis posuere tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dolor urna, adipiscing euismod hendrerit non, mattis vel est. Aliquam erat volutpat. In hac habitasse platea dictumst. Cras consequat dolor in dolor euismod eget laoreet massa tristique.
|
4
|
+
|
5
|
+
Nunc molestie ornare odio non blandit. Ut et semper sapien. Nulla sollicitudin lacinia imperdiet. Suspendisse ullamcorper massa lobortis dui fermentum elementum. Donec et ligula nunc. Sed ligula eros, condimentum quis ornare eu, vestibulum quis leo. Praesent cursus lorem sed justo scelerisque laoreet id non purus. Suspendisse sodales justo at arcu pulvinar a viverra ligula adipiscing. Aenean at consequat turpis. Praesent adipiscing, justo quis commodo dapibus, orci justo dictum mauris, eu aliquet nisl purus in turpis.
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'accepts_for_support'
|
3
|
+
|
4
|
+
describe "invalid input" do
|
5
|
+
it "should reject values and a block at once" do
|
6
|
+
L{
|
7
|
+
AcceptsForTest.new.records "stuff" do
|
8
|
+
more "stuff"
|
9
|
+
end
|
10
|
+
}.should raise_error(ArgumentError, "You can supply arguments or a block, but not both.")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "storing" do
|
15
|
+
before {
|
16
|
+
@list = AcceptsForTest.new
|
17
|
+
}
|
18
|
+
it "should return self to allow chaining" do
|
19
|
+
[
|
20
|
+
:package, :renders, :format, :records, :produces, :valid_formats
|
21
|
+
].each {|method_name|
|
22
|
+
@list.send(method_name, "hello").should == @list
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "accepts_value_for" do
|
28
|
+
before {
|
29
|
+
@value = AcceptsForTest.new
|
30
|
+
}
|
31
|
+
it "should return nil for no input" do
|
32
|
+
@value.package.should == nil
|
33
|
+
end
|
34
|
+
it "should return the correct default when no value is stored" do
|
35
|
+
@value.renders.should == "a default response"
|
36
|
+
@value.format.should == "json"
|
37
|
+
end
|
38
|
+
it "should return the value when called without args" do
|
39
|
+
[:package, :renders, :format].each {|method_name|
|
40
|
+
@value.send(method_name, "hello").send(method_name).should == "hello"
|
41
|
+
}
|
42
|
+
end
|
43
|
+
it "should return the result of callable items" do
|
44
|
+
[:package, :renders, :format].each {|method_name|
|
45
|
+
@value.send(method_name, L{ "world" }).send(method_name).should == "world"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
it "should replace existing values with new ones" do
|
49
|
+
@value.package "ruby-1.8"
|
50
|
+
@value.package "ruby-1.9"
|
51
|
+
@value.package.should == "ruby-1.9"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "accepts_value_for input processing" do
|
56
|
+
describe "lambda input" do
|
57
|
+
it "should return the correct call's args" do
|
58
|
+
test_value_lambdas.each_pair {|input, expected|
|
59
|
+
value = AcceptsForTest.new(input)
|
60
|
+
value.package &input
|
61
|
+
value.package.should == expected
|
62
|
+
}
|
63
|
+
end
|
64
|
+
it "should ignore default whenever any lambda is specified" do
|
65
|
+
test_value_lambdas.each_pair {|input, expected|
|
66
|
+
value = AcceptsForTest.new(input)
|
67
|
+
value.renders &input
|
68
|
+
value.renders.should == expected
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
describe "accepts_list_for" do
|
76
|
+
before {
|
77
|
+
@list = AcceptsForTest.new
|
78
|
+
}
|
79
|
+
it "should return the empty list for no input" do
|
80
|
+
@list.records.should == []
|
81
|
+
end
|
82
|
+
it "should return the empty list for nil input" do
|
83
|
+
@list.records nil
|
84
|
+
@list.records.should == []
|
85
|
+
end
|
86
|
+
it "should return the correct default when no value is stored" do
|
87
|
+
@list.produces.should == ["a default response"]
|
88
|
+
@list.valid_formats.should == %w[html xml js json]
|
89
|
+
end
|
90
|
+
it "should accept splatted args" do
|
91
|
+
@list.records "an item", "another item"
|
92
|
+
@list.records.should == ["an item", "another item"]
|
93
|
+
end
|
94
|
+
it "should accept an array of args" do
|
95
|
+
@list.records ["an item", "another item"]
|
96
|
+
@list.records.should == ["an item", "another item"]
|
97
|
+
end
|
98
|
+
it "should return the value when called without args" do
|
99
|
+
[:records, :produces, :valid_formats].each {|method_name|
|
100
|
+
@list.send(method_name, "hello").send(method_name).should == ["hello"]
|
101
|
+
}
|
102
|
+
end
|
103
|
+
it "should return the result of callable items" do
|
104
|
+
[:records, :produces, :valid_formats].each {|method_name|
|
105
|
+
@list.send(method_name, "hello", L{ "world" }).send(method_name).should == ["hello", "world"]
|
106
|
+
}
|
107
|
+
end
|
108
|
+
it "should append new values to existing ones" do
|
109
|
+
@list.records "scores", "quips"
|
110
|
+
@list.records "tall tales"
|
111
|
+
@list.records.should == ["scores", "quips", "tall tales"]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
describe "accepts_list_for input processing" do
|
117
|
+
describe "value input" do
|
118
|
+
test_lists.each_pair {|input, expected|
|
119
|
+
it "should return #{expected.inspect} when passed #{input.inspect}" do
|
120
|
+
list = AcceptsForTest.new
|
121
|
+
list.records input
|
122
|
+
list.records.should == expected
|
123
|
+
end
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "lambda input" do
|
128
|
+
it "should return the correct call's args" do
|
129
|
+
test_list_lambdas.each_pair {|input, expected|
|
130
|
+
list = AcceptsForTest.new(input)
|
131
|
+
list.records &input
|
132
|
+
list.records.should == expected
|
133
|
+
}
|
134
|
+
end
|
135
|
+
it "should ignore default whenever any lambda is specified" do
|
136
|
+
test_list_lambdas.each_pair {|input, expected|
|
137
|
+
list = AcceptsForTest.new(input)
|
138
|
+
list.produces &input
|
139
|
+
list.produces.should == expected
|
140
|
+
}
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "lambda and value input" do
|
145
|
+
test_lists.each_pair {|input, expected|
|
146
|
+
it "should return #{expected.inspect} when passed #{input.inspect} within a lambda" do
|
147
|
+
l = L{
|
148
|
+
via :macports, input
|
149
|
+
}
|
150
|
+
list = AcceptsForTest.new
|
151
|
+
list.records &l
|
152
|
+
list.records.should == expected
|
153
|
+
end
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "nested lambdas" do
|
158
|
+
it "should choose recursively" do
|
159
|
+
l = L{
|
160
|
+
via :macports do
|
161
|
+
via :macports, "haha, excellent"
|
162
|
+
via :apt, ":|"
|
163
|
+
end
|
164
|
+
via :apt do
|
165
|
+
via :macports, "no, not this one"
|
166
|
+
via :apt, "OK this one is just completely wrong"
|
167
|
+
end
|
168
|
+
}
|
169
|
+
list = AcceptsForTest.new
|
170
|
+
list.records &l
|
171
|
+
list.records.should == ["haha, excellent"]
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class AcceptsForTest
|
2
|
+
include AcceptsListFor
|
3
|
+
include AcceptsValueFor
|
4
|
+
attr_reader :payload
|
5
|
+
def initialize name = nil
|
6
|
+
@name = name
|
7
|
+
@payload = {}
|
8
|
+
end
|
9
|
+
def chooser
|
10
|
+
:macports
|
11
|
+
end
|
12
|
+
def chooser_choices
|
13
|
+
[:apt, :macports]
|
14
|
+
end
|
15
|
+
def default_formats
|
16
|
+
%w[html xml js json]
|
17
|
+
end
|
18
|
+
def default_format
|
19
|
+
"json"
|
20
|
+
end
|
21
|
+
accepts_value_for :package, :choose_with => :via
|
22
|
+
accepts_value_for :renders, "a default response", :choose_with => :via
|
23
|
+
accepts_value_for :format, :default_format, :choose_with => :via
|
24
|
+
|
25
|
+
accepts_list_for :records, :choose_with => :via
|
26
|
+
accepts_list_for :produces, "a default response", :choose_with => :via
|
27
|
+
accepts_list_for :valid_formats, :default_formats, :choose_with => :via
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_lists
|
31
|
+
{
|
32
|
+
nil => [],
|
33
|
+
[] => [],
|
34
|
+
'a' => ['a'],
|
35
|
+
%w[a] => ['a'],
|
36
|
+
%w[a b c] => ['a', 'b', 'c']
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_value_lambdas
|
41
|
+
{
|
42
|
+
L{ } => nil,
|
43
|
+
L{
|
44
|
+
via :apt, "git-core"
|
45
|
+
} => nil,
|
46
|
+
L{
|
47
|
+
via :macports, 'ruby'
|
48
|
+
via :apt, 'git-core'
|
49
|
+
} => 'ruby',
|
50
|
+
L{
|
51
|
+
via :macports, 'something else'
|
52
|
+
via :apt, 'some apt packages'
|
53
|
+
} => 'something else'
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_list_lambdas
|
58
|
+
{
|
59
|
+
L{ } => [],
|
60
|
+
L{
|
61
|
+
via :apt, %w[ruby irb ri rdoc]
|
62
|
+
} => [],
|
63
|
+
L{
|
64
|
+
via :macports, 'ruby'
|
65
|
+
via :apt, %w[ruby irb ri rdoc]
|
66
|
+
} => ['ruby'],
|
67
|
+
L{
|
68
|
+
via :macports, 'something else'
|
69
|
+
via :apt, 'some apt packages'
|
70
|
+
} => ['something else']
|
71
|
+
}
|
72
|
+
end
|