escort 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +8 -0
  3. data/README.md +365 -14
  4. data/TODO.md +157 -44
  5. data/escort.gemspec +1 -0
  6. data/examples/{1_1_basic.rb → attic/1_1_basic.rb} +0 -0
  7. data/examples/{1_2_basic_requires_arguments.rb → attic/1_2_basic_requires_arguments.rb} +0 -0
  8. data/examples/{2_2_command.rb → attic/2_2_command.rb} +0 -0
  9. data/examples/{2_2_command_requires_arguments.rb → attic/2_2_command_requires_arguments.rb} +0 -0
  10. data/examples/{2_3_nested_commands.rb → attic/2_3_nested_commands.rb} +0 -0
  11. data/examples/{3_validations.rb → attic/3_validations.rb} +0 -0
  12. data/examples/{4_1_config_file.rb → attic/4_1_config_file.rb} +0 -0
  13. data/examples/{argument_handling → attic/argument_handling}/basic.rb +0 -0
  14. data/examples/{argument_handling → attic/argument_handling}/basic_command.rb +0 -0
  15. data/examples/{argument_handling → attic/argument_handling}/no_arguments.rb +0 -0
  16. data/examples/{argument_handling → attic/argument_handling}/no_arguments_command.rb +0 -0
  17. data/examples/{command_aliases → attic/command_aliases}/app.rb +0 -0
  18. data/examples/{config_file → attic/config_file}/.apprc2 +0 -0
  19. data/examples/{config_file → attic/config_file}/app.rb +0 -0
  20. data/examples/{config_file → attic/config_file}/sub_commands.rb +0 -0
  21. data/examples/{default_command → attic/default_command}/app.rb +0 -0
  22. data/examples/{sub_commands → attic/sub_commands}/app.rb +0 -0
  23. data/examples/{validation_basic → attic/validation_basic}/app.rb +0 -0
  24. data/examples/basic +10 -0
  25. data/examples/basic_conflicts +17 -0
  26. data/examples/basic_depends_on +25 -0
  27. data/examples/basic_flags +15 -0
  28. data/examples/basic_options +14 -0
  29. data/examples/basic_options_multi +15 -0
  30. data/examples/basic_require_arguments +17 -0
  31. data/examples/basic_texts +21 -0
  32. data/examples/basic_validations +21 -0
  33. data/examples/command +19 -0
  34. data/examples/commands/example_command.rb +13 -0
  35. data/lib/escort/action_command/base.rb +4 -0
  36. data/lib/escort/app.rb +33 -11
  37. data/lib/escort/formatter/borderless_table.rb +4 -0
  38. data/lib/escort/formatter/command.rb +87 -0
  39. data/lib/escort/formatter/commands.rb +36 -0
  40. data/lib/escort/formatter/default_help_formatter.rb +68 -73
  41. data/lib/escort/formatter/global_command.rb +17 -0
  42. data/lib/escort/formatter/option.rb +138 -0
  43. data/lib/escort/formatter/options.rb +17 -3
  44. data/lib/escort/formatter/shell_command_executor.rb +49 -0
  45. data/lib/escort/formatter/terminal.rb +17 -9
  46. data/lib/escort/formatter/terminal_formatter.rb +6 -0
  47. data/lib/escort/logger.rb +4 -4
  48. data/lib/escort/option_dependency_validator.rb +83 -0
  49. data/lib/escort/option_parser.rb +11 -1
  50. data/lib/escort/setup/configuration/reader.rb +0 -2
  51. data/lib/escort/setup/configuration/writer.rb +0 -2
  52. data/lib/escort/setup/dsl/command.rb +2 -7
  53. data/lib/escort/setup/dsl/global.rb +2 -9
  54. data/lib/escort/setup/dsl/options.rb +56 -0
  55. data/lib/escort/setup_accessor.rb +23 -6
  56. data/lib/escort/trollop.rb +4 -3
  57. data/lib/escort/validator.rb +4 -1
  58. data/lib/escort/version.rb +1 -1
  59. data/lib/escort.rb +8 -1
  60. data/spec/integration/basic_conflicts_spec.rb +47 -0
  61. data/spec/integration/basic_depends_on_spec.rb +275 -0
  62. data/spec/integration/basic_options_spec.rb +9 -21
  63. data/spec/integration/basic_options_with_multi_spec.rb +30 -0
  64. data/spec/integration/basic_spec.rb +5 -6
  65. data/spec/integration/basic_validations_spec.rb +77 -0
  66. data/spec/integration/basic_with_arguments_spec.rb +33 -0
  67. data/spec/integration/basic_with_text_fields_spec.rb +21 -0
  68. data/spec/lib/escort/formatter/command_spec.rb +238 -0
  69. data/spec/lib/escort/formatter/global_command_spec.rb +50 -0
  70. data/spec/lib/escort/formatter/option_spec.rb +300 -0
  71. data/spec/lib/escort/formatter/shell_command_executor_spec.rb +59 -0
  72. data/spec/lib/escort/formatter/string_splitter_spec.rb +12 -0
  73. data/spec/lib/escort/formatter/terminal_spec.rb +19 -0
  74. data/spec/lib/escort/setup_accessor_spec.rb +1 -0
  75. data/spec/spec_helper.rb +9 -3
  76. data/spec/support/integration_helpers.rb +2 -0
  77. data/spec/{helpers/execute_action_matcher.rb → support/matchers/execute_action_for_command_matcher.rb} +3 -3
  78. data/spec/support/matchers/execute_action_with_arguments_matcher.rb +25 -0
  79. data/spec/support/matchers/execute_action_with_options_matcher.rb +29 -0
  80. data/spec/support/matchers/exit_with_code_matcher.rb +29 -0
  81. data/spec/support/shared_contexts/integration_setup.rb +34 -0
  82. metadata +86 -28
  83. data/examples/basic/app.rb +0 -16
  84. data/lib/escort/formatter/common.rb +0 -58
  85. data/spec/helpers/exit_with_code_matcher.rb +0 -21
  86. data/spec/helpers/give_option_to_action_with_value_matcher.rb +0 -22
@@ -0,0 +1,238 @@
1
+ describe Escort::Formatter::Command do
2
+ let(:command) { Escort::Formatter::Command.new(name, setup, context)}
3
+ let(:setup) { Escort::SetupAccessor.new(app_configuration) }
4
+ let(:context) {[]}
5
+ let(:name) {:command1}
6
+ let(:command_alias) {:c1}
7
+ let(:aliases) {[command_alias]}
8
+ let(:summary) {'command summary'}
9
+ let(:description) {'command description'}
10
+
11
+ let(:app_configuration) do
12
+ Escort::Setup::Dsl::Global.new do |app|
13
+ app.command name, :aliases => aliases do |command|
14
+ command.summary summary
15
+ command.description description
16
+
17
+ command.action do |options, arguments|
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ context "#description" do
24
+ subject {command.description}
25
+
26
+ context "when no description" do
27
+ let(:description) {nil}
28
+ it{subject.should == ''}
29
+ end
30
+
31
+ context "when has description" do
32
+ let(:description) {'command description'}
33
+ it{subject.should == description}
34
+ end
35
+ end
36
+
37
+ context "#summary" do
38
+ subject {command.summary}
39
+
40
+ context "when no summary" do
41
+ let(:summary) {nil}
42
+ it{subject.should == ''}
43
+ end
44
+
45
+ context "when has summary" do
46
+ let(:summary) {'command summary'}
47
+ it{subject.should == summary}
48
+ end
49
+ end
50
+
51
+ context "#has_aliases?" do
52
+ subject {command.has_aliases?}
53
+
54
+ context "when no aliases" do
55
+ let(:aliases) {[]}
56
+ it {subject.should be_false}
57
+ end
58
+
59
+ context "when has an alias" do
60
+ let(:aliases) {[command_alias]}
61
+ it {subject.should be_true}
62
+ end
63
+ end
64
+
65
+ context "#aliases" do
66
+ subject {command.aliases}
67
+
68
+ context "when no aliases" do
69
+ let(:aliases) {[]}
70
+ it {subject.should == []}
71
+ end
72
+
73
+ context "when has an alias" do
74
+ let(:aliases) {[command_alias]}
75
+ it {subject.first.should == command_alias}
76
+ end
77
+ end
78
+
79
+ context "#outline" do
80
+ subject {command.outline}
81
+
82
+ context "when no summary or description" do
83
+ let(:summary) {nil}
84
+ let(:description) {nil}
85
+ it {subject.should == ''}
86
+ end
87
+
88
+ context "when no summary" do
89
+ let(:summary) {nil}
90
+ let(:description) {'desc 1'}
91
+ it {subject.should == 'desc 1'}
92
+ end
93
+
94
+ context "when no description" do
95
+ let(:summary) {'summary 1'}
96
+ let(:description) {nil}
97
+ it {subject.should == 'summary 1'}
98
+ end
99
+ end
100
+
101
+ context "#aliases" do
102
+ subject {command.name_with_aliases}
103
+
104
+ context "when no aliases" do
105
+ let(:aliases) {[]}
106
+ it {subject.should == "command1"}
107
+ end
108
+
109
+ context "when has an alias" do
110
+ let(:aliases) {[command_alias]}
111
+ it {subject.should == "command1, #{command_alias}"}
112
+ end
113
+ end
114
+
115
+ context "#script_name" do
116
+ subject {command.script_name}
117
+
118
+ context "when context is global" do
119
+ let(:context) {[]}
120
+ it{subject.split(" ").count.should == 1}
121
+ end
122
+
123
+ context "when context is not global" do
124
+ let(:context) {[:hello]}
125
+ it{subject.split(" ").count.should == 2}
126
+ it{subject.split(" ").include?('hello').should be_true}
127
+ end
128
+ end
129
+
130
+ context "#child_commands" do
131
+ subject {command.child_commands}
132
+
133
+ context "when no child commands" do
134
+ let(:app_configuration) do
135
+ Escort::Setup::Dsl::Global.new do |app|
136
+ app.action do |options, arguments|
137
+ end
138
+ end
139
+ end
140
+ it {subject.should be_empty}
141
+ end
142
+
143
+ context "when has child commands" do
144
+ it {subject.should_not be_empty}
145
+ it {subject.count.should == 1}
146
+ it {subject.first.should == :command1}
147
+ end
148
+ end
149
+
150
+ context "#has_child_commands?" do
151
+ subject {command.has_child_commands?}
152
+
153
+ context "when no child commands" do
154
+ let(:app_configuration) do
155
+ Escort::Setup::Dsl::Global.new do |app|
156
+ app.action do |options, arguments|
157
+ end
158
+ end
159
+ end
160
+ it {subject.should be_false}
161
+ end
162
+
163
+ context "when has child commands" do
164
+ it {subject.should be_true}
165
+ end
166
+ end
167
+
168
+ context "#requires_arguments?" do
169
+ subject {command.requires_arguments?}
170
+
171
+ context "when arguments not required" do
172
+ it {subject.should be_false}
173
+ end
174
+
175
+ context "when arguments are required" do
176
+ let(:app_configuration) do
177
+ Escort::Setup::Dsl::Global.new do |app|
178
+ app.requires_arguments
179
+ app.action do |options, arguments|
180
+ end
181
+ end
182
+ end
183
+ it {subject.should be_true}
184
+ end
185
+ end
186
+
187
+ context "#usage" do
188
+ subject {command.usage}
189
+
190
+ before do
191
+ $0 = 'hello'
192
+ end
193
+
194
+ context "when global command with no children" do
195
+ let(:app_configuration) do
196
+ Escort::Setup::Dsl::Global.new do |app|
197
+ app.action do |options, arguments|
198
+ end
199
+ end
200
+ end
201
+ it {subject.split(" ").first.should == 'hello'}
202
+ it {subject.split(" ")[1].should == '[options]'}
203
+ it {subject.split(" ")[2].should == '[arguments]'}
204
+ end
205
+
206
+ context "when global command with children" do
207
+ it {subject.split(" ").first.should == 'hello'}
208
+ it {subject.split(" ")[1].should == '[options]'}
209
+ it {subject.split(" ")[2].should == 'command'}
210
+ it {subject.split(" ")[3].should == '[command_options]'}
211
+ it {subject.split(" ")[4].should == '[arguments]'}
212
+ end
213
+
214
+ context "when global command and requires arguments" do
215
+ let(:app_configuration) do
216
+ Escort::Setup::Dsl::Global.new do |app|
217
+ app.requires_arguments
218
+ app.action do |options, arguments|
219
+ end
220
+ end
221
+ end
222
+ it {subject.split(" ").last.should == 'arguments'}
223
+ end
224
+
225
+ context "when does not require arguments" do
226
+ it {subject.split(" ").last.should == '[arguments]'}
227
+ end
228
+
229
+ context "when child command context with no children of its own" do
230
+ let(:context){[:command1]}
231
+ it {subject.split(" ").first.should == 'hello'}
232
+ it {subject.split(" ")[1].should == '[options]'}
233
+ it {subject.split(" ")[2].should == 'command1'}
234
+ it {subject.split(" ")[3].should == '[command1_options]'}
235
+ it {subject.split(" ")[4].should == '[arguments]'}
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,50 @@
1
+ describe Escort::Formatter::GlobalCommand do
2
+ let(:command) { Escort::Formatter::GlobalCommand.new(setup)}
3
+ let(:setup) { Escort::SetupAccessor.new(app_configuration) }
4
+ let(:context) {[]}
5
+ let(:name) {:command1}
6
+ let(:command_alias) {:c1}
7
+ let(:aliases) {[command_alias]}
8
+ let(:summary) {'app summary'}
9
+ let(:description) {'app description'}
10
+
11
+ let(:app_configuration) do
12
+ Escort::Setup::Dsl::Global.new do |app|
13
+ app.summary summary
14
+ app.description description
15
+
16
+ app.command name, :aliases => aliases do |command|
17
+ command.action do |options, arguments|
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ context "#description" do
24
+ subject {command.description}
25
+
26
+ context "when no description" do
27
+ let(:description) {nil}
28
+ it{subject.should == ''}
29
+ end
30
+
31
+ context "when has description" do
32
+ let(:description) {'app description'}
33
+ it{subject.should == description}
34
+ end
35
+ end
36
+
37
+ context "#summary" do
38
+ subject {command.summary}
39
+
40
+ context "when no summary" do
41
+ let(:summary) {nil}
42
+ it{subject.should == ''}
43
+ end
44
+
45
+ context "when has summary" do
46
+ let(:summary) {'app summary'}
47
+ it{subject.should == summary}
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,300 @@
1
+ describe Escort::Formatter::Option do
2
+ let(:option) {Escort::Formatter::Option.new(name, details, setup, context)}
3
+ let(:setup) { Escort::SetupAccessor.new(app_configuration) }
4
+ let(:context) {[]}
5
+ let(:name) { 'option1' }
6
+ let(:details) do
7
+ {:short=>short, :long=>"option1", :type=>type, :default=>default, :desc=>desc, :multi=>false}
8
+ end
9
+ let(:short) {:none}
10
+ let(:type) {:string}
11
+ let(:default) {'foo'}
12
+ let(:desc) {'Option 1'}
13
+ let(:app_configuration) do
14
+ Escort::Setup::Dsl::Global.new do |app|
15
+ end
16
+ end
17
+
18
+ describe "#usage" do
19
+ subject {option.usage}
20
+
21
+ context "when option is a flag" do
22
+ let(:type) {:flag}
23
+
24
+ context "and it has a default value of 'true'" do
25
+ let(:default) {true}
26
+ it {subject.should == '--option1, --no-option1'}
27
+ end
28
+
29
+ context "and its default value is 'false'" do
30
+ let(:default) {false}
31
+ it {subject.should == '--option1'}
32
+ end
33
+ end
34
+
35
+ context 'when option is not a flag' do
36
+ let(:type) {:string}
37
+
38
+ context "and it has no short specification" do
39
+ let(:short) {:none}
40
+ it {subject.should == '--option1 <s>'}
41
+ end
42
+
43
+ context "and it has a short specification" do
44
+ let(:short) {'o'}
45
+ it {subject.should == '--option1 -o <s>'}
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "#description" do
51
+ subject {option.description}
52
+
53
+ context "when no description" do
54
+ let(:desc) {nil}
55
+ context "and has no default value" do
56
+ let(:default) {nil}
57
+ it {subject.should == ''}
58
+ end
59
+
60
+ context "and has a default value" do
61
+ let(:default) {"blah"}
62
+ it {subject.should == '(default: blah)'}
63
+ end
64
+ end
65
+
66
+ context "when has description" do
67
+ context "and description end with dot" do
68
+ let(:desc) {"Option 1."}
69
+
70
+ context "and has no default value" do
71
+ let(:default) {nil}
72
+ it {subject.should == 'Option 1.'}
73
+ end
74
+
75
+ context "and has a default value" do
76
+ let(:default) {"blah"}
77
+ it {subject.should == 'Option 1. (Default: blah)'}
78
+ end
79
+ end
80
+
81
+ context "and description does not end with dot" do
82
+ let(:desc) {"Option 1"}
83
+
84
+ context "and has no default value" do
85
+ let(:default) {nil}
86
+ it {subject.should == 'Option 1'}
87
+ end
88
+
89
+ context "and has a default value" do
90
+ let(:default) {"blah"}
91
+ it {subject.should == 'Option 1 (default: blah)'}
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "#has_conflicts?" do
98
+ subject {option.has_conflicts?}
99
+ context "when no conflicts defined" do
100
+ let(:app_configuration) do
101
+ Escort::Setup::Dsl::Global.new do |app|
102
+ app.options do |opts|
103
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
104
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
105
+ end
106
+
107
+ app.action do |options, arguments|
108
+ end
109
+ end
110
+ end
111
+ it {subject.should be_false}
112
+ end
113
+
114
+ context "when conflict is defined" do
115
+ let(:app_configuration) do
116
+ Escort::Setup::Dsl::Global.new do |app|
117
+ app.options do |opts|
118
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :conflicts_with => :option2
119
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
120
+ end
121
+
122
+ app.action do |options, arguments|
123
+ end
124
+ end
125
+ end
126
+ it {subject.should be_true}
127
+ end
128
+ end
129
+
130
+ describe "#has_dependencies?" do
131
+ subject {option.has_dependencies?}
132
+ context "when no dependencies defined" do
133
+ let(:app_configuration) do
134
+ Escort::Setup::Dsl::Global.new do |app|
135
+ app.options do |opts|
136
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
137
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
138
+ end
139
+
140
+ app.action do |options, arguments|
141
+ end
142
+ end
143
+ end
144
+ it {subject.should be_false}
145
+ end
146
+
147
+ context "when dependency is defined" do
148
+ let(:app_configuration) do
149
+ Escort::Setup::Dsl::Global.new do |app|
150
+ app.options do |opts|
151
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :depends_on => :option2
152
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
153
+ end
154
+
155
+ app.action do |options, arguments|
156
+ end
157
+ end
158
+ end
159
+ it {subject.should be_true}
160
+ end
161
+ end
162
+
163
+ describe "#has_validations?" do
164
+ subject {option.has_validations?}
165
+ context "when no validations defined" do
166
+ let(:app_configuration) do
167
+ Escort::Setup::Dsl::Global.new do |app|
168
+ app.options do |opts|
169
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
170
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
171
+ end
172
+
173
+ app.action do |options, arguments|
174
+ end
175
+ end
176
+ end
177
+ it {subject.should be_false}
178
+ end
179
+
180
+ context "when validations is defined" do
181
+ let(:app_configuration) do
182
+ Escort::Setup::Dsl::Global.new do |app|
183
+ app.options do |opts|
184
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
185
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
186
+
187
+ opts.validate(:option1, "must be 'foo'") {|option| option == 'foo'}
188
+ end
189
+
190
+ app.action do |options, arguments|
191
+ end
192
+ end
193
+ end
194
+ it {subject.should be_true}
195
+ end
196
+ end
197
+
198
+ describe "#conflicts" do
199
+ subject {option.conflicts}
200
+ context "when no conflicts defined" do
201
+ let(:app_configuration) do
202
+ Escort::Setup::Dsl::Global.new do |app|
203
+ app.options do |opts|
204
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
205
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
206
+ end
207
+
208
+ app.action do |options, arguments|
209
+ end
210
+ end
211
+ end
212
+ it {subject.should == ''}
213
+ end
214
+
215
+ context "when conflict is defined" do
216
+ let(:app_configuration) do
217
+ Escort::Setup::Dsl::Global.new do |app|
218
+ app.options do |opts|
219
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :conflicts_with => [:option2, :option3]
220
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
221
+ opts.opt :option3, "Option3", :short => :none, :long => '--option3', :type => :string
222
+ end
223
+
224
+ app.action do |options, arguments|
225
+ end
226
+ end
227
+ end
228
+ it {subject.should == 'conflicts with: --option2, --option3'}
229
+ end
230
+ end
231
+
232
+ describe "#dependencies" do
233
+ subject {option.dependencies}
234
+ context "when no dependencies defined" do
235
+ let(:app_configuration) do
236
+ Escort::Setup::Dsl::Global.new do |app|
237
+ app.options do |opts|
238
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
239
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
240
+ end
241
+
242
+ app.action do |options, arguments|
243
+ end
244
+ end
245
+ end
246
+ it {subject.should == ''}
247
+ end
248
+
249
+ context "when dependency is defined" do
250
+ let(:app_configuration) do
251
+ Escort::Setup::Dsl::Global.new do |app|
252
+ app.options do |opts|
253
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string, :depends_on => :option2
254
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
255
+ end
256
+
257
+ app.action do |options, arguments|
258
+ end
259
+ end
260
+ end
261
+ it {subject.should == 'depends on: --option2'}
262
+ end
263
+ end
264
+
265
+ describe "#validations" do
266
+ subject {option.validations}
267
+ context "when no validations defined" do
268
+ let(:app_configuration) do
269
+ Escort::Setup::Dsl::Global.new do |app|
270
+ app.options do |opts|
271
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
272
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
273
+ end
274
+
275
+ app.action do |options, arguments|
276
+ end
277
+ end
278
+ end
279
+ it {subject.should == ''}
280
+ end
281
+
282
+ context "when validations is defined" do
283
+ let(:app_configuration) do
284
+ Escort::Setup::Dsl::Global.new do |app|
285
+ app.options do |opts|
286
+ opts.opt :option1, "Option1", :short => '-o', :long => '--option1', :type => :string
287
+ opts.opt :option2, "Option2", :short => :none, :long => '--option2', :type => :string
288
+
289
+ opts.validate(:option1, "must be 'foo'") {|option| option == 'foo'}
290
+ opts.validate(:option1, "must not be 'bar'") {|option| option != 'bar'}
291
+ end
292
+
293
+ app.action do |options, arguments|
294
+ end
295
+ end
296
+ end
297
+ it {subject.should == "must be 'foo'\n- must not be 'bar'"}
298
+ end
299
+ end
300
+ end
@@ -0,0 +1,59 @@
1
+ describe Escort::Formatter::ShellCommandExecutor do
2
+ let(:executor) {Escort::Formatter::ShellCommandExecutor.new(command)}
3
+ let(:result) { [] }
4
+ let(:error_callback) {lambda{ |command, error| result << 'error'; result << error.class }}
5
+
6
+ #describe "#execute_in_new_shell" do
7
+ #subject {executor.execute_in_new_shell(success_callback, error_callback)}
8
+
9
+ #let(:success_callback) {lambda{ |command, stdin, stdout, stderr| result << 'success' }}
10
+
11
+ #context "when command is invalid" do
12
+ #let(:command) { 'lx -z' }
13
+ #it("error callback should be executed") {subject; result.first.should == 'error'}
14
+ #it("should return nil") {subject.should be_nil}
15
+ #end
16
+
17
+ #context "when command is valid" do
18
+ #context "but options passed to it are invalid" do
19
+ #let(:command) { 'ls --foobar' }
20
+ #it("error callback should be executed") {subject; result.first.should == 'error'}
21
+ #it("command should produce an exit status error") {subject; result[1].should == Escort::InternalError}
22
+ #it("should return nil") {subject.should be_nil}
23
+ #end
24
+
25
+ #context "and options passed to it are valid" do
26
+ #let(:command) { 'ls -al' }
27
+ #it("success callback should be executed") {subject; result.first.should == 'success'}
28
+ #it("should not return nil") {subject.should_not be_nil}
29
+ #end
30
+ #end
31
+ #end
32
+
33
+ describe "#execute_in_current_shell" do
34
+ subject {executor.execute_in_current_shell(success_callback, error_callback)}
35
+
36
+ let(:success_callback) {lambda{ |command, final_result| result << 'success' }}
37
+
38
+ context "when command is invalid" do
39
+ let(:command) { 'lx -z' }
40
+ it("error callback should be executed") {subject; result.first.should == 'error'}
41
+ it("should return nil") {subject.should be_nil}
42
+ end
43
+
44
+ context "when command is valid" do
45
+ context "but options passed to it are invalid" do
46
+ let(:command) { 'ls --foobar' }
47
+ it("error callback should be executed") {subject; result.first.should == 'error'}
48
+ it("command should produce an exit status error") {subject; result[1].should == Escort::InternalError}
49
+ it("should return nil") {subject.should be_nil}
50
+ end
51
+
52
+ context "and options passed to it are valid" do
53
+ let(:command) { 'ls -al' }
54
+ it("success callback should be executed") {subject; result.first.should == 'success'}
55
+ it("should not return nil") {subject.should_not be_nil}
56
+ end
57
+ end
58
+ end
59
+ end
@@ -34,5 +34,17 @@ describe Escort::Formatter::StringSplitter do
34
34
  it("first segment should be 'd'") { subject[2].should == 'd' }
35
35
  end
36
36
  end
37
+
38
+ context "when segment width is 5" do
39
+ let(:max_segment_width) { 5 }
40
+
41
+ context "and string is 'abc\\n123456'" do
42
+ let(:string) {"abc\n123456"}
43
+ it("should produce 3 segments") { subject.size.should == 3 }
44
+ it("first segment should be 'abc'") { subject[0].should == 'abc' }
45
+ it("second segment should be '12345'") { subject[1].should == '12345' }
46
+ it("last segment should be '6'") { subject[2].should == '6' }
47
+ end
48
+ end
37
49
  end
38
50
  end
@@ -0,0 +1,19 @@
1
+ describe Escort::Formatter::Terminal do
2
+ let(:terminal) {Escort::Formatter::Terminal}
3
+
4
+ describe "#width" do
5
+ subject {terminal.width}
6
+
7
+ context "when width can be found successfully" do
8
+ let(:current_width) {`/usr/bin/env tput cols`.to_i}
9
+ it("should be equal to current width") {subject.should == current_width}
10
+ end
11
+
12
+ context "when width could not be found successfully" do
13
+ before do
14
+ Escort::Formatter::ShellCommandExecutor.any_instance.stub(:execute_in_current_shell).and_return(nil)
15
+ end
16
+ it("should be equal to default width") {subject.should == Escort::Formatter::Terminal::DEFAULT_WIDTH}
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,6 @@
1
1
  describe Escort::SetupAccessor do
2
2
  let(:setup) { Escort::SetupAccessor.new(app_configuration) }
3
+
3
4
  let(:global_app_configuration) do
4
5
  Escort::Setup::Dsl::Global.new do |app|
5
6
  app.options do |opts|