rubycut-babushka 0.10.6

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.
Files changed (171) hide show
  1. data/Gemfile +8 -0
  2. data/Gemfile.lock +31 -0
  3. data/README.markdown +246 -0
  4. data/Rakefile +26 -0
  5. data/bin/babushka +11 -0
  6. data/deps/babushka.rb +101 -0
  7. data/deps/dev.rb +12 -0
  8. data/deps/fhs.rb +31 -0
  9. data/deps/git.rb +29 -0
  10. data/deps/homebrew.rb +30 -0
  11. data/deps/os_x.rb +33 -0
  12. data/deps/packages.rb +22 -0
  13. data/deps/pkg_managers.rb +110 -0
  14. data/deps/ruby.rb +23 -0
  15. data/deps/rubygems.rb +24 -0
  16. data/deps/system.rb +10 -0
  17. data/deps/templates/app.rb +68 -0
  18. data/deps/templates/external.rb +12 -0
  19. data/deps/templates/installer.rb +31 -0
  20. data/deps/templates/managed.rb +105 -0
  21. data/deps/templates/ppa.rb +24 -0
  22. data/deps/templates/src.rb +42 -0
  23. data/deps/templates/tmbundle.rb +15 -0
  24. data/lib/babushka.rb +28 -0
  25. data/lib/babushka/accepts_block_for.rb +72 -0
  26. data/lib/babushka/accepts_list_for.rb +49 -0
  27. data/lib/babushka/accepts_value_for.rb +24 -0
  28. data/lib/babushka/base.rb +78 -0
  29. data/lib/babushka/bug_reporter.rb +55 -0
  30. data/lib/babushka/cmdline.rb +133 -0
  31. data/lib/babushka/cmdline/handler.rb +41 -0
  32. data/lib/babushka/cmdline/helpers.rb +127 -0
  33. data/lib/babushka/cmdline/parser.rb +69 -0
  34. data/lib/babushka/colorizer.rb +59 -0
  35. data/lib/babushka/core_patches/array.rb +171 -0
  36. data/lib/babushka/core_patches/blank.rb +22 -0
  37. data/lib/babushka/core_patches/bytes.rb +52 -0
  38. data/lib/babushka/core_patches/hash.rb +107 -0
  39. data/lib/babushka/core_patches/hashish.rb +14 -0
  40. data/lib/babushka/core_patches/integer.rb +25 -0
  41. data/lib/babushka/core_patches/io.rb +8 -0
  42. data/lib/babushka/core_patches/numeric.rb +16 -0
  43. data/lib/babushka/core_patches/object.rb +27 -0
  44. data/lib/babushka/core_patches/string.rb +116 -0
  45. data/lib/babushka/core_patches/symbol.rb +12 -0
  46. data/lib/babushka/core_patches/try.rb +15 -0
  47. data/lib/babushka/core_patches/uri.rb +24 -0
  48. data/lib/babushka/dep.rb +470 -0
  49. data/lib/babushka/dep_context.rb +18 -0
  50. data/lib/babushka/dep_definer.rb +115 -0
  51. data/lib/babushka/dep_pool.rb +49 -0
  52. data/lib/babushka/dep_runner.rb +85 -0
  53. data/lib/babushka/dsl.rb +26 -0
  54. data/lib/babushka/git_repo.rb +185 -0
  55. data/lib/babushka/helpers/git_helpers.rb +32 -0
  56. data/lib/babushka/helpers/log_helpers.rb +176 -0
  57. data/lib/babushka/helpers/path_helpers.rb +34 -0
  58. data/lib/babushka/helpers/run_helpers.rb +145 -0
  59. data/lib/babushka/helpers/shell_helpers.rb +229 -0
  60. data/lib/babushka/helpers/suggest_helpers.rb +16 -0
  61. data/lib/babushka/helpers/uri_helpers.rb +36 -0
  62. data/lib/babushka/ip.rb +160 -0
  63. data/lib/babushka/lambda_chooser.rb +40 -0
  64. data/lib/babushka/levenshtein.rb +125 -0
  65. data/lib/babushka/meta_dep.rb +65 -0
  66. data/lib/babushka/meta_dep_context.rb +15 -0
  67. data/lib/babushka/parameter.rb +143 -0
  68. data/lib/babushka/pkg_helper.rb +81 -0
  69. data/lib/babushka/pkg_helpers/apt_helper.rb +61 -0
  70. data/lib/babushka/pkg_helpers/base_helper.rb +19 -0
  71. data/lib/babushka/pkg_helpers/binpkgsrc_helper.rb +48 -0
  72. data/lib/babushka/pkg_helpers/binports_helper.rb +34 -0
  73. data/lib/babushka/pkg_helpers/brew_helper.rb +110 -0
  74. data/lib/babushka/pkg_helpers/gem_helper.rb +120 -0
  75. data/lib/babushka/pkg_helpers/macports_helper.rb +22 -0
  76. data/lib/babushka/pkg_helpers/npm_helper.rb +45 -0
  77. data/lib/babushka/pkg_helpers/pacman_helper.rb +27 -0
  78. data/lib/babushka/pkg_helpers/pip_helper.rb +45 -0
  79. data/lib/babushka/pkg_helpers/src_helper.rb +16 -0
  80. data/lib/babushka/pkg_helpers/yum_helper.rb +25 -0
  81. data/lib/babushka/popen.rb +40 -0
  82. data/lib/babushka/prompt.rb +176 -0
  83. data/lib/babushka/renderable.rb +67 -0
  84. data/lib/babushka/resource.rb +215 -0
  85. data/lib/babushka/run_reporter.rb +60 -0
  86. data/lib/babushka/shell.rb +108 -0
  87. data/lib/babushka/source.rb +216 -0
  88. data/lib/babushka/source_pool.rb +146 -0
  89. data/lib/babushka/system_definitions.rb +97 -0
  90. data/lib/babushka/system_profile.rb +210 -0
  91. data/lib/babushka/task.rb +142 -0
  92. data/lib/babushka/vars.rb +108 -0
  93. data/lib/babushka/version_of.rb +65 -0
  94. data/lib/babushka/version_str.rb +57 -0
  95. data/lib/babushka/xml_string.rb +28 -0
  96. data/lib/components.rb +82 -0
  97. data/lib/fancypath/fancypath.rb +200 -0
  98. data/lib/inkan/inkan.rb +76 -0
  99. data/spec/acceptance/acceptance.rb +43 -0
  100. data/spec/acceptance_helper.rb +113 -0
  101. data/spec/archives/Blah.app.zip +0 -0
  102. data/spec/archives/archive.tar +0 -0
  103. data/spec/archives/archive.tar.bz2 +0 -0
  104. data/spec/archives/archive.tar.gz +0 -0
  105. data/spec/archives/archive.tbz2 +0 -0
  106. data/spec/archives/archive.tgz +0 -0
  107. data/spec/archives/archive.zip +0 -0
  108. data/spec/archives/content.txt +5 -0
  109. data/spec/archives/invalid_archive +5 -0
  110. data/spec/archives/nested archive/content.txt +5 -0
  111. data/spec/archives/nested_archive.tar +0 -0
  112. data/spec/archives/really_a_gzip.zip +0 -0
  113. data/spec/archives/test-0.3.1.tgz +0 -0
  114. data/spec/archives/tgz_archive +0 -0
  115. data/spec/archives/zip_without_extension +0 -0
  116. data/spec/babushka/accepts_for_spec.rb +174 -0
  117. data/spec/babushka/accepts_for_support.rb +72 -0
  118. data/spec/babushka/cmdline/console_spec.rb +11 -0
  119. data/spec/babushka/cmdline/help_spec.rb +61 -0
  120. data/spec/babushka/cmdline/version_spec.rb +10 -0
  121. data/spec/babushka/core_patches_spec.rb +171 -0
  122. data/spec/babushka/dep_context_spec.rb +58 -0
  123. data/spec/babushka/dep_definer_spec.rb +152 -0
  124. data/spec/babushka/dep_definer_support.rb +36 -0
  125. data/spec/babushka/dep_spec.rb +567 -0
  126. data/spec/babushka/dep_support.rb +29 -0
  127. data/spec/babushka/deps_spec.rb +113 -0
  128. data/spec/babushka/gem_helper_spec.rb +90 -0
  129. data/spec/babushka/git_repo_spec.rb +396 -0
  130. data/spec/babushka/ip_spec.rb +131 -0
  131. data/spec/babushka/lambda_chooser_spec.rb +115 -0
  132. data/spec/babushka/meta_dep_definer_spec.rb +127 -0
  133. data/spec/babushka/meta_dep_wrapper_spec.rb +32 -0
  134. data/spec/babushka/parameter_spec.rb +135 -0
  135. data/spec/babushka/path_helpers_spec.rb +102 -0
  136. data/spec/babushka/prompt_spec.rb +188 -0
  137. data/spec/babushka/renderable_spec.rb +100 -0
  138. data/spec/babushka/resource_spec.rb +141 -0
  139. data/spec/babushka/run_helpers_spec.rb +26 -0
  140. data/spec/babushka/shell_helpers_spec.rb +244 -0
  141. data/spec/babushka/shell_spec.rb +19 -0
  142. data/spec/babushka/source_pool_spec.rb +320 -0
  143. data/spec/babushka/source_pool_support.rb +31 -0
  144. data/spec/babushka/source_spec.rb +382 -0
  145. data/spec/babushka/source_support.rb +17 -0
  146. data/spec/babushka/system_profile_spec.rb +61 -0
  147. data/spec/babushka/task_spec.rb +141 -0
  148. data/spec/babushka/uri_spec.rb +13 -0
  149. data/spec/babushka/vars_spec.rb +59 -0
  150. data/spec/babushka/version_of_spec.rb +110 -0
  151. data/spec/babushka/version_str_spec.rb +130 -0
  152. data/spec/babushka/version_str_support.rb +37 -0
  153. data/spec/babushka/xml_string_spec.rb +98 -0
  154. data/spec/deps/bad/broken.rb +7 -0
  155. data/spec/deps/bad/working.rb +3 -0
  156. data/spec/deps/good/meta.rb +14 -0
  157. data/spec/deps/good/test.rb +11 -0
  158. data/spec/deps/outer/deps.rb +19 -0
  159. data/spec/deps/outer/more deps.rb +11 -0
  160. data/spec/deps/params/params.rb +10 -0
  161. data/spec/fancypath/fancypath_spec.rb +272 -0
  162. data/spec/fancypath_support.rb +10 -0
  163. data/spec/inkan/inkan_spec.rb +217 -0
  164. data/spec/renderable/different_example.conf.erb +4 -0
  165. data/spec/renderable/example.conf.erb +3 -0
  166. data/spec/renderable/example.sh +6 -0
  167. data/spec/renderable/with_binding.conf.erb +4 -0
  168. data/spec/renderable/xml_example.conf.erb +8 -0
  169. data/spec/repos/remote.git.tgz +0 -0
  170. data/spec/spec_helper.rb +87 -0
  171. metadata +238 -0
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "console" do
4
+ before {
5
+ entry_point = File.expand_path(File.join(__FILE__, '../../../../lib/babushka'))
6
+ Cmdline.should_receive(:exec).with("irb -r'#{entry_point}' --simple-prompt")
7
+ }
8
+ it "should launch a console via Kernel#exec" do
9
+ Cmdline::Parser.for(%w[console]).run
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe "help" do
4
+ context "with no verb" do
5
+ before {
6
+ [
7
+ "Babushka v#{Babushka::VERSION}, (c) 2011 Ben Hoskings <ben@hoskings.net>",
8
+ "\nThe gist:",
9
+ " #{Base.program_name} <command> [options]",
10
+ "\nAlso:",
11
+ " #{Base.program_name} help <command> # Print command-specific usage info",
12
+ " #{Base.program_name} <dep name> # A shortcut for 'babushka meet <dep name>'",
13
+ " #{Base.program_name} babushka # Update babushka itself (what babushka.me/up does)",
14
+ "\nCommands:",
15
+ " help Print usage information",
16
+ " version Print the current version",
17
+ " list List the available deps",
18
+ " meet The main one: run a dep and all its dependencies.",
19
+ " sources Manage dep sources",
20
+ " console Start an interactive (irb-based) babushka session",
21
+ " search Search for deps in the community database",
22
+ " edit Load the file containing the specified dep in $EDITOR",
23
+ "\nCommands can be abbrev'ed, as long as they remain unique.",
24
+ " e.g. '#{Base.program_name} l' is short for '#{Base.program_name} list'.",
25
+ "\n"
26
+ ].each {|line|
27
+ Cmdline::Helpers.should_receive(:log).with(line)
28
+ }
29
+ }
30
+ it "should print the verb help information" do
31
+ Cmdline::Parser.for(%w[help]).run
32
+ end
33
+ end
34
+ context "with a verb" do
35
+ let(:parser) { Cmdline::Parser.for(%w[help meet]) }
36
+ before {
37
+ [
38
+ "Babushka v#{Babushka::VERSION}, (c) 2011 Ben Hoskings <ben@hoskings.net>",
39
+ "\nmeet - The main one: run a dep and all its dependencies."
40
+ ].each {|line|
41
+ Cmdline::Helpers.should_receive(:log).with(line)
42
+ }
43
+
44
+ parser.should_receive(:log).with("
45
+ -v, --version Print the current version
46
+ -h, --help Show this information
47
+ -d, --debug Show more verbose logging, and realtime shell command output
48
+ --[no-]color, --[no-]colour Disable color in the output
49
+ -n, --dry-run Discover the curent state without making any changes
50
+ -y, --defaults Assume the default value for all vars without prompting, where possible
51
+ --show-args Show the arguments being passed between deps as they're run
52
+ --track-blocks Track deps' blocks in TextMate as they're run
53
+ ")
54
+
55
+ Cmdline::Helpers.should_receive(:log).with("\n")
56
+ }
57
+ it "should print the help information for the verb" do
58
+ parser.run
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe "version" do
4
+ before {
5
+ Cmdline::Helpers.should_receive(:log).with(Babushka::VERSION)
6
+ }
7
+ it "should print the version" do
8
+ Cmdline::Parser.for(%w[version]).run
9
+ end
10
+ end
@@ -0,0 +1,171 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array, "to_list" do
4
+ it "no elements" do
5
+ [].to_list.should == ''
6
+ end
7
+ it "single element" do
8
+ %w[a].to_list.should == 'a'
9
+ end
10
+ it "two elements" do
11
+ %w[a b].to_list.should == 'a and b'
12
+ end
13
+ it "three elements" do
14
+ %w[a b c].to_list.should == 'a, b and c'
15
+ end
16
+ it "oxford comma" do
17
+ %w[a b c].to_list(:oxford => true).should == 'a, b, and c'
18
+ end
19
+ it "custom conjugation" do
20
+ %w[a b c].to_list(:conj => 'or').should == 'a, b or c'
21
+ end
22
+ describe "limits" do
23
+ it "below limit" do
24
+ %w[a b c].to_list(:limit => 4).should == 'a, b and c'
25
+ end
26
+ it "at limit" do
27
+ %w[a b c].to_list(:limit => 3).should == 'a, b and c'
28
+ end
29
+ it "above limit" do
30
+ %w[a b c].to_list(:limit => 2).should == 'a, b et al'
31
+ %w[a b c d e].to_list(:limit => 4).should == 'a, b, c, d et al'
32
+ end
33
+ it "with noun" do
34
+ %w[a b c].to_list(:limit => 2, :noun => 'items').should == 'a, b et al - 3 items'
35
+ end
36
+ end
37
+ end
38
+
39
+ describe Array, '#collapse' do
40
+ it "should work for empty lists" do
41
+ [].collapse('blah').should == []
42
+ [].collapse(/blah/).should == []
43
+ end
44
+ it "should select surnames from a list" do
45
+ [
46
+ 'Ben Hoskings',
47
+ 'Nathan Sampimon',
48
+ 'Nathan de Vries'
49
+ ].collapse(/Nathan /).should == ['Sampimon', 'de Vries']
50
+ end
51
+ it "should strip git branch prefixes" do
52
+ [
53
+ ' next',
54
+ '* master',
55
+ ' topic'
56
+ ].collapse(/^\* /).should == [
57
+ 'master'
58
+ ]
59
+ end
60
+ it "should use the replacement if passed" do
61
+ [
62
+ "Chain fail2ban-nginx-catchall (1 references)",
63
+ "target prot opt source destination",
64
+ "DROP all -- 58.161.41.76 0.0.0.0/0 ",
65
+ "RETURN all -- 0.0.0.0/0 0.0.0.0/0 "
66
+ ].collapse(/^DROP\s+[^\d]+([\d\.]+)\s+.*/, '\1').should == [
67
+ '58.161.41.76'
68
+ ]
69
+ end
70
+ end
71
+
72
+ describe Array, '#local_group_by' do
73
+ it "should work for empty lists" do
74
+ [].group_by(&:length).should == {}
75
+ end
76
+ it "should do what you expect" do
77
+ %w[cat badger narwahl pug].local_group_by(&:length).should == {
78
+ 3 => %w[cat pug],
79
+ 6 => %w[badger],
80
+ 7 => %w[narwahl]
81
+ }
82
+ end
83
+ it "should work with nils and such" do
84
+ %w[cat badger narwahl pug].local_group_by {|i|
85
+ i[/a[rt]/]
86
+ }.should == {
87
+ nil => %w[badger pug],
88
+ 'at' => %w[cat],
89
+ 'ar' => %w[narwahl]
90
+ }
91
+ end
92
+ it "should return nil for keys that don't match a group" do
93
+ %w[cat badger narwahl pug].local_group_by(&:length)[4].should be_nil
94
+ end
95
+ end
96
+
97
+ def version_of *args
98
+ Babushka::VersionOf::Helpers.VersionOf *args
99
+ end
100
+
101
+
102
+ describe Array, '#versions' do
103
+ {
104
+ %w[a] => [version_of('a')],
105
+ %w[a b c] => [version_of('a'), version_of('b'), version_of('c')],
106
+ [version_of('a')] => [version_of('a')],
107
+ ['a 0.1', 'b >= 0.6.0', 'c ~> 2.2'] => [version_of('a', '0.1'), version_of('b', '>= 0.6.0'), version_of('c', '~> 2.2')]
108
+ }.each_pair {|input, expected|
109
+ it "should return #{expected.inspect} when passed #{input.inspect}" do
110
+ input.versions.should == expected
111
+ end
112
+ }
113
+ end
114
+
115
+ describe Hash, '#defaults!' do
116
+ it "should work for empty hashes" do
117
+ {}.defaults!(:a => 'b', :c => 'd').should == {:a => 'b', :c => 'd'}
118
+ end
119
+ it "should work for empty defaults" do
120
+ {:a => 'custom b', :c => 'custom d'}.defaults!({}).should == {:a => 'custom b', :c => 'custom d'}
121
+ end
122
+ it "should combine defaults with the hash" do
123
+ {:a => 'custom b', :c => 'custom d'}.defaults!({:e => 'f', :g => 'h'}).should == {:a => 'custom b', :c => 'custom d', :e => 'f', :g => 'h'}
124
+ end
125
+ it "should override default values" do
126
+ {:a => 'custom b', :e => 'custom e'}.defaults!({:e => 'f', :g => 'h'}).should == {:a => 'custom b', :e => 'custom e', :g => 'h'}
127
+ end
128
+ end
129
+
130
+ describe String, "val_for" do
131
+ it "space separation" do
132
+ 'key value'.val_for('key').should == 'value'
133
+ end
134
+ it "key/value separation" do
135
+ 'key: value'.val_for('key').should == 'value'
136
+ 'key = value'.val_for('key').should == 'value'
137
+ end
138
+ it "whitespace" do
139
+ ' key value '.val_for('key').should == 'value'
140
+ end
141
+ it "whitespace in key" do
142
+ 'space-separated key: value'.val_for('space-separated key').should == 'value'
143
+ end
144
+ it "whitespace in value" do
145
+ 'key: space-separated value'.val_for('key').should == 'space-separated value'
146
+ end
147
+ it "whitespace in both" do
148
+ 'key with spaces: space-separated value'.val_for('key with spaces').should == 'space-separated value'
149
+ end
150
+ it "key ending in non-word characters" do
151
+ "psql (PostgreSQL) 9.1.0".val_for('psql (PostgreSQL)').should == '9.1.0'
152
+ end
153
+ it "non-word leading characters" do
154
+ '*key: value'.val_for('*key').should == 'value'
155
+ '-key: value'.val_for('-key').should == 'value'
156
+ '-key: value'.val_for('key').should == nil
157
+ end
158
+ it "non-word leading tokens" do
159
+ '* key: value'.val_for('key').should == 'value'
160
+ '- key with spaces: value'.val_for('key with spaces').should == 'value'
161
+ ' -- key with spaces: value'.val_for('key with spaces').should == 'value'
162
+ end
163
+ it "trailing characters" do
164
+ 'key: value;'.val_for('key').should == 'value'
165
+ 'key: value,'.val_for('key').should == 'value'
166
+ end
167
+ it "paths" do
168
+ "/dev/disk1s2 Apple_HFS /Volumes/TextMate 1.5.9".val_for("/dev/disk1s2 Apple_HFS").should == "/Volumes/TextMate 1.5.9"
169
+ "/dev/disk1s2 Apple_HFS /Volumes/TextMate 1.5.9".val_for(/^\/dev\/disk\d+s\d+\s+Apple_HFS\s+/).should == "/Volumes/TextMate 1.5.9"
170
+ end
171
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'dep_definer_support'
3
+
4
+ describe "accepts_block_for behaviour" do
5
+ before {
6
+ Dep.stub!(:base_template).and_return(TestTemplate)
7
+ setup_test_lambdas
8
+ dep 'default'
9
+ }
10
+
11
+ it "should define a declarer" do
12
+ Dep('default').context.should_not respond_to(:test_defining)
13
+ TestDepContext.accepts_block_for :test_defining
14
+ Dep('default').context.should respond_to(:test_defining)
15
+ end
16
+
17
+ it "should return lambda" do
18
+ TestDepContext.accepts_block_for :test_defining
19
+ lambda = L{ 'blah' }
20
+ value_from_block = nil
21
+ dep 'returning test' do
22
+ value_from_block = test_defining &lambda
23
+ end.met?
24
+ value_from_block.should == lambda
25
+ end
26
+
27
+ it "should accept and return a block" do
28
+ test_accepts_block_for_response :test_response, @lambda_hello, @lambda_hello
29
+ end
30
+ it "should accept and return a block for this system" do
31
+ test_accepts_block_for_response :test_this_system, @lambda_hello, @lambda_hello, :on => Base.host.system
32
+ end
33
+ it "should return nothing on a non-specified system" do
34
+ test_accepts_block_for_response :test_other_system, @lambda_hello, nil, :on => :nonexistent
35
+ end
36
+
37
+ it "should use default blocks when no specific one is specified" do
38
+ lambda = L{ 'default value' }
39
+ TestDepContext.accepts_block_for :test_defaults, &lambda
40
+ value_from_block = nil
41
+ dep 'default test' do
42
+ value_from_block = test_defaults
43
+ end.met?
44
+ value_from_block.should == lambda
45
+ end
46
+
47
+ after { Base.sources.anonymous.deps.clear! }
48
+ end
49
+
50
+ describe "accepts_list_for behaviour" do
51
+ before {
52
+ Babushka::Base.stub!(:host).and_return FakeOSXSystemProfile.new
53
+ make_test_deps
54
+ }
55
+ it "should choose requires for the correct system" do
56
+ Dep('test build tools').context.requires.should == ['xcode tools']
57
+ end
58
+ end
@@ -0,0 +1,152 @@
1
+ require 'spec_helper'
2
+ require 'dep_definer_support'
3
+
4
+ describe "source_template" do
5
+ it "should return BaseTemplate" do
6
+ TestDepContext.source_template.should == Dep::BaseTemplate
7
+ end
8
+ end
9
+
10
+ describe "args" do
11
+ describe "parsing style" do
12
+ it "should parse as named when just a single hash is passed" do
13
+ dep('1 arg', :a).tap {|dep|
14
+ dep.should_receive(:parse_named_arguments).with({:a => 'a'}).and_return({})
15
+ dep.with(:a => 'a')
16
+ }
17
+ end
18
+ it "should parse as a list when non-hash values are passed" do
19
+ dep('2 args', :a, :b).tap {|dep|
20
+ dep.should_receive(:parse_positional_arguments).with(['a', {'key' => 'value'}]).and_return({})
21
+ dep.with('a', 'key' => 'value')
22
+ }
23
+ end
24
+ it "should parse as a list when no args are passed" do
25
+ dep('no args').tap {|dep|
26
+ dep.should_receive(:parse_positional_arguments).with([]).and_return({})
27
+ dep.with
28
+ }
29
+ end
30
+ end
31
+ context "without arguments" do
32
+ it "should fail when called with unnamed args" do
33
+ L{ dep('no args').with('a') }.should raise_error(DepArgumentError, "The dep 'no args' accepts 0 arguments, but 1 was passed.")
34
+ end
35
+ it "should fail when called with named args that don't match" do
36
+ L{ dep('no args').with(:a => 'a') }.should raise_error(DepArgumentError, "The dep 'no args' received an unexpected argument :a.")
37
+ end
38
+ end
39
+ context "with the wrong number of arguments" do
40
+ it "should fail when called with the wrong number of unnamed args" do
41
+ L{ dep('1 arg', :a).with('a', 'b') }.should raise_error(DepArgumentError, "The dep '1 arg' accepts 1 argument, but 2 were passed.")
42
+ L{ dep('2 args', :a, :b).with('a') }.should raise_error(DepArgumentError, "The dep '2 args' accepts 2 arguments, but 1 was passed.")
43
+ end
44
+ it "should fail when called with named args that don't match" do
45
+ L{ dep('1 arg', :a).with(:a => 'a', :b => 'b') }.should raise_error(DepArgumentError, "The dep '1 arg' received an unexpected argument :b.")
46
+ L{ dep('1 arg', :a).with(:a => 'a', :b => 'b', :c => 'c') }.should raise_error(DepArgumentError, "The dep '1 arg' received unexpected arguments :b and :c.")
47
+ end
48
+ end
49
+ context "with empty arguments" do
50
+ subject { dep('2 args', :a, :b).with() }
51
+ it "should populate the args with Parameter objects" do
52
+ subject.args.map_values {|_,v| v.class }.should == {:a => Parameter, :b => Parameter}
53
+ end
54
+ it "should set the names correctly" do
55
+ subject.args.map_values {|_,v| v.name }.should == {:a => :a, :b => :b}
56
+ end
57
+ it "should not set the values" do
58
+ subject.args.values.each {|v| v.should_not be_set }
59
+ end
60
+ end
61
+ context "with the right number of positional arguments" do
62
+ subject { dep('2 args', :a, :b).with('a', 'b') }
63
+ it "should populate the args with Parameter objects" do
64
+ subject.args.map_values {|_,v| v.class }.should == {:a => Parameter, :b => Parameter}
65
+ end
66
+ it "should set the names correctly" do
67
+ subject.args.map_values {|_,v| v.name }.should == {:a => :a, :b => :b}
68
+ end
69
+ it "should set the values" do
70
+ subject.args.values.each {|v| v.should be_set }
71
+ end
72
+ end
73
+ context "with the correct named arguments" do
74
+ subject { dep('2 args', :a, :b).with(:a => 'a', :b => 'b') }
75
+ it "should populate the args with Parameter objects" do
76
+ subject.args.map_values {|_,v| v.class }.should == {:a => Parameter, :b => Parameter}
77
+ end
78
+ it "should set the names correctly" do
79
+ subject.args.map_values {|_,v| v.name }.should == {:a => :a, :b => :b}
80
+ end
81
+ it "should set the values" do
82
+ subject.args.values.each {|v| v.should be_set }
83
+ end
84
+ end
85
+ context "with non-symbol names" do
86
+ it "should be rejected, singular" do
87
+ L{
88
+ dep('2 args', :a).with('a' => 'a')
89
+ }.should raise_error(DepArgumentError, %{The dep '2 args' received a non-symbol argument "a".})
90
+ end
91
+ it "should be rejected, plural" do
92
+ L{
93
+ dep('2 args', :a, :b).with('a' => 'a', 'b' => 'b')
94
+ }.should raise_error(DepArgumentError, %{The dep '2 args' received non-symbol arguments "a" and "b".})
95
+ end
96
+ end
97
+ context "with incomplete named arguments" do
98
+ subject { dep('2 args', :a, :b).with(:a => 'a') }
99
+ it "should partially populate the args with Parameter objects" do
100
+ subject.args.map_values {|_,v| v.class }.should == {:a => Parameter}
101
+ end
102
+ it "should set the names that are present correctly" do
103
+ subject.args.map_values {|_,v| v.name }.should == {:a => :a}
104
+ end
105
+ it "should lazily create the missing parameter" do
106
+ subject.context.b.should be_an_instance_of(Parameter)
107
+ subject.context.b.name.should == :b
108
+ end
109
+ it "should set only the paramters that were passed" do
110
+ subject.context.a.should be_set
111
+ subject.context.b.should_not be_set
112
+ end
113
+ end
114
+ end
115
+
116
+ describe "methods in deps" do
117
+ before {
118
+ dep 'helper method test' do
119
+ def helper_test
120
+ 'hello from the helper method!'
121
+ end
122
+ end
123
+ dep 'without helper method'
124
+ }
125
+ it "should only be defined on the specified dep" do
126
+ Dep('helper method test').context.should respond_to(:helper_test)
127
+ Dep('without helper method').context.should_not respond_to(:helper_test)
128
+ end
129
+ it "should return the right value" do
130
+ Dep('helper method test').context.helper_test.should == 'hello from the helper method!'
131
+ end
132
+ end
133
+
134
+ describe "#on for scoping accepters" do
135
+ before {
136
+ Base.stub!(:host).and_return OSXSystemProfile.for_flavour
137
+ Base.host.stub!(:version).and_return '10.6.7'
138
+ @lambda = lambda = L{ 'hello from the lambda' }
139
+ @other_lambda = other_lambda = L{ 'hello from the other lambda' }
140
+ dep 'scoping' do
141
+ on :osx do
142
+ met?(&lambda)
143
+ end
144
+ on :linux do
145
+ met?(&other_lambda)
146
+ end
147
+ end
148
+ }
149
+ it "should only allow choices that match" do
150
+ Dep('scoping').send(:payload)[:met?].should == {:osx => @lambda}
151
+ end
152
+ end