aruba 0.11.0.pre → 0.11.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/History.md +21 -1
  4. data/aruba.gemspec +1 -0
  5. data/features/api/command/find_command.feature +83 -0
  6. data/features/api/command/last_command_started.feature +50 -0
  7. data/features/api/command/last_command_stopped.feature +89 -0
  8. data/features/api/command/run.feature +259 -0
  9. data/features/api/command/stop.feature +53 -1
  10. data/features/api/text/replace_variables.feature +1 -1
  11. data/features/getting_started/run_commands.feature +177 -0
  12. data/features/matchers/file/be_existing_executable.feature +87 -0
  13. data/features/{integration/rspec/getting_started.feature → rspec/integration.feature} +31 -0
  14. data/fixtures/getting-started-app/Gemfile +1 -1
  15. data/lib/aruba.rb +0 -19
  16. data/lib/aruba/api.rb +2 -0
  17. data/lib/aruba/api/command.rb +103 -44
  18. data/lib/aruba/api/core.rb +13 -8
  19. data/lib/aruba/api/deprecated.rb +26 -4
  20. data/lib/aruba/api/environment.rb +21 -13
  21. data/lib/aruba/api/filesystem.rb +13 -0
  22. data/lib/aruba/api/rvm.rb +5 -0
  23. data/lib/aruba/api/text.rb +7 -1
  24. data/lib/aruba/aruba_path.rb +6 -0
  25. data/lib/aruba/basic_configuration.rb +35 -3
  26. data/lib/aruba/basic_configuration/option.rb +7 -0
  27. data/lib/aruba/cli.rb +4 -0
  28. data/lib/aruba/command.rb +47 -1
  29. data/lib/aruba/config.rb +15 -2
  30. data/lib/aruba/config_wrapper.rb +49 -8
  31. data/lib/aruba/console.rb +4 -1
  32. data/lib/aruba/console/help.rb +2 -0
  33. data/lib/aruba/contracts/absolute_path.rb +7 -0
  34. data/lib/aruba/contracts/enum.rb +5 -0
  35. data/lib/aruba/contracts/is_power_of_two.rb +9 -2
  36. data/lib/aruba/contracts/relative_path.rb +7 -0
  37. data/lib/aruba/cucumber/command.rb +6 -9
  38. data/lib/aruba/cucumber/file.rb +1 -1
  39. data/lib/aruba/cucumber/hooks.rb +36 -29
  40. data/lib/aruba/errors.rb +16 -1
  41. data/lib/aruba/events.rb +39 -0
  42. data/lib/aruba/extensions/string/strip.rb +1 -0
  43. data/lib/aruba/file_size.rb +11 -0
  44. data/lib/aruba/hooks.rb +2 -0
  45. data/lib/aruba/in_config_wrapper.rb +24 -0
  46. data/lib/aruba/in_process.rb +2 -0
  47. data/lib/aruba/initializer.rb +37 -0
  48. data/lib/aruba/matchers/base/base_matcher.rb +2 -0
  49. data/lib/aruba/matchers/base/object_formatter.rb +4 -0
  50. data/lib/aruba/matchers/collection/all.rb +2 -0
  51. data/lib/aruba/matchers/collection/include_an_object.rb +2 -0
  52. data/lib/aruba/matchers/command/have_exit_status.rb +1 -1
  53. data/lib/aruba/matchers/command/have_finished_in_time.rb +1 -10
  54. data/lib/aruba/matchers/command/have_output.rb +1 -10
  55. data/lib/aruba/matchers/command/have_output_on_stderr.rb +1 -10
  56. data/lib/aruba/matchers/command/have_output_on_stdout.rb +1 -10
  57. data/lib/aruba/matchers/file/be_an_existing_executable.rb +37 -0
  58. data/lib/aruba/platform.rb +4 -0
  59. data/lib/aruba/platforms/announcer.rb +225 -0
  60. data/lib/aruba/platforms/aruba_file_creator.rb +4 -0
  61. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +4 -0
  62. data/lib/aruba/{aruba_logger.rb → platforms/aruba_logger.rb} +4 -0
  63. data/lib/aruba/platforms/command_monitor.rb +229 -0
  64. data/lib/aruba/platforms/determine_disk_usage.rb +5 -0
  65. data/lib/aruba/platforms/determine_file_size.rb +9 -0
  66. data/lib/aruba/platforms/disk_usage_calculator.rb +9 -0
  67. data/lib/aruba/platforms/local_environment.rb +12 -0
  68. data/lib/aruba/platforms/simple_table.rb +11 -0
  69. data/lib/aruba/platforms/unix_command_string.rb +3 -0
  70. data/lib/aruba/platforms/unix_environment_variables.rb +3 -0
  71. data/lib/aruba/platforms/unix_platform.rb +20 -2
  72. data/lib/aruba/platforms/unix_which.rb +6 -2
  73. data/lib/aruba/platforms/windows_command_string.rb +7 -0
  74. data/lib/aruba/platforms/windows_environment_variables.rb +2 -0
  75. data/lib/aruba/platforms/windows_platform.rb +3 -0
  76. data/lib/aruba/platforms/windows_which.rb +6 -2
  77. data/lib/aruba/processes/basic_process.rb +20 -5
  78. data/lib/aruba/processes/debug_process.rb +3 -1
  79. data/lib/aruba/processes/in_process.rb +18 -2
  80. data/lib/aruba/processes/spawn_process.rb +14 -13
  81. data/lib/aruba/rspec.rb +34 -23
  82. data/lib/aruba/runtime.rb +65 -6
  83. data/lib/aruba/setup.rb +87 -0
  84. data/lib/aruba/version.rb +1 -1
  85. data/spec/aruba/api_spec.rb +13 -36
  86. data/spec/aruba/{config_wrapper_spec.rb → in_config_wrapper_spec.rb} +1 -1
  87. data/spec/aruba/spawn_process_spec.rb +9 -14
  88. data/spec/support/configs/pry.rb +3 -0
  89. data/spec/support/shared_contexts/aruba.rb +1 -0
  90. metadata +40 -14
  91. data/features/getting_started/supported_programming_languages.feature +0 -89
  92. data/lib/aruba/announcer.rb +0 -219
  93. data/lib/aruba/matchers/rspec.rb +0 -0
  94. data/lib/aruba/process_monitor.rb +0 -201
  95. data/lib/aruba/processes/null_process.rb +0 -26
@@ -1,89 +0,0 @@
1
- Feature: Supported programming languages
2
-
3
- As long as you've got the neccessary programs, libraries, runtime
4
- environments, interpreters installed, it doesn't matter in which programming
5
- language your commandline application is implemented.
6
-
7
- Below you find some examples of the "Hello, Aruba!"-application implemented
8
- with different programming languages. This is NOT an exclusive list. Every
9
- commandline application should run with `aruba`.
10
-
11
- Background:
12
- Given I use a fixture named "getting-started-app"
13
- And a file named "features/hello_aruba.feature" with:
14
- """
15
- Feature: Getting Started With Aruba
16
- Scenario: First Run of Command
17
- Given I successfully run `cli`
18
- Then the output should contain:
19
- \"\"\"
20
- Hello, Aruba!
21
- \"\"\"
22
- """
23
-
24
- Scenario: Bash Program
25
- Given an executable named "bin/cli" with:
26
- """bash
27
- #!/usr/bin/env bash
28
-
29
- echo "Hello, Aruba!"
30
- """
31
- When I successfully run `cucumber`
32
- Then the features should all pass
33
-
34
- Scenario: Ruby Program
35
- Given an executable named "bin/cli" with:
36
- """ruby
37
- #!/usr/bin/env ruby
38
-
39
- puts "Hello, Aruba!"
40
- """
41
- When I successfully run `cucumber`
42
- Then the features should all pass
43
-
44
- Scenario: Python Program
45
- Given an executable named "bin/cli" with:
46
- """python
47
- #!/usr/bin/env python
48
-
49
- print("Hello, Aruba!")
50
- """
51
- When I successfully run `cucumber`
52
- Then the features should all pass
53
-
54
- Scenario: Perl Program
55
- Given an executable named "bin/cli" with:
56
- """perl
57
- #!/usr/bin/env perl
58
-
59
- print "Hello, Aruba!\n";
60
- """
61
- When I successfully run `cucumber`
62
- Then the features should all pass
63
-
64
- Scenario: Java Program
65
-
66
- It's even possible to compile and run Java programs with Aruba.
67
-
68
- Given a file named "features/hello_aruba.feature" with:
69
- """cucumber
70
- Feature: Getting Started With Aruba
71
- Scenario: First Run of Command
72
- Given a file named "tmp/HelloArubaApp.java" with:
73
- \"\"\"
74
- class HelloArubaApp {
75
- public static void main(String[] args) {
76
- System.out.println("Hello, Aruba!");
77
- }
78
- }
79
- \"\"\"
80
- And I successfully run `javac tmp/HelloArubaApp.java`
81
- And I cd to "tmp/"
82
- And I successfully run `java HelloArubaApp`
83
- Then the output should contain:
84
- \"\"\"
85
- Hello, Aruba!
86
- \"\"\"
87
- """
88
- When I successfully run `cucumber`
89
- Then the features should all pass
@@ -1,219 +0,0 @@
1
- require 'shellwords'
2
-
3
- module Aruba
4
- # Announcer
5
- #
6
- # @example Activate your you own channel in cucumber
7
- #
8
- # Before('@announce-my-channel') do
9
- # announcer.activate :my_channel
10
- # end
11
- #
12
- # @example Activate your you own channel in rspec > 3
13
- #
14
- # before do
15
- # current_example = context.example
16
- # announcer.activate :my_channel if current_example.metadata[:announce_my_channel]
17
- # end
18
- #
19
- # Aruba.announcer.announce(:my_channel, 'my message')
20
- #
21
- class Announcer
22
- # Dev null
23
- class NullAnnouncer
24
- def announce(*)
25
- nil
26
- end
27
-
28
- def mode?(*)
29
- true
30
- end
31
- end
32
-
33
- # Announcer using Kernel.puts
34
- class KernelPutsAnnouncer
35
- def announce(message)
36
- Kernel.puts message
37
- end
38
-
39
- def mode?(m)
40
- :kernel_puts == m
41
- end
42
- end
43
-
44
- # Announcer using Main#puts
45
- class PutsAnnouncer
46
- def announce(message)
47
- Kernel.puts message
48
- end
49
-
50
- def mode?(m)
51
- :puts == m
52
- end
53
- end
54
-
55
- private
56
-
57
- attr_reader :announcers, :default_announcer, :announcer, :channels, :output_formats
58
-
59
- public
60
-
61
- def initialize(_, options)
62
- @announcers = []
63
- @announcers << PutsAnnouncer.new
64
- @announcers << KernelPutsAnnouncer.new
65
- @announcers << NullAnnouncer.new
66
-
67
- @default_announcer = @announcers.last
68
- @announcer = @announcers.first
69
- @channels = {}
70
- @output_formats = {}
71
-
72
- @options = options
73
-
74
- after_init
75
- end
76
-
77
- private
78
-
79
- # rubocop:disable Metrics/MethodLength
80
- def after_init
81
- output_format :directory, '$ cd %s'
82
- output_format :command, '$ %s'
83
- output_format :environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
84
- output_format :modified_environment, proc { |n, v| format('$ export %s=%s', n, Shellwords.escape(v)) }
85
- output_format :full_environment, proc { |h| Aruba.platform.simple_table(h) }
86
- output_format :timeout, '# %s-timeout: %s seconds'
87
- output_format :wait_time, '# %s: %s seconds'
88
- output_format :stop_signal, proc { |p, s| format('Command will be stopped with `kill -%s %s`', s, p) }
89
- output_format :stderr, "<<-STDERR\n%s\nSTDERR"
90
- output_format :stdout, "<<-STDOUT\n%s\nSTDOUT"
91
-
92
- # rubocop:disable Metrics/LineLength
93
- if @options[:stdout]
94
- warn('The use of "@announce_stdout-instance" variable and "options[:stdout] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stdout)" instead.')
95
- activate :stdout
96
- end
97
- if @options[:stderr]
98
- warn('The use of "@announce_stderr-instance" variable and "options[:stderr] = true" for Announcer.new is deprecated. Please use "announcer.activate(:stderr)" instead.')
99
- activate :stderr
100
- end
101
- if @options[:dir]
102
- warn('The use of "@announce_dir-instance" variable and "options[:dir] = true" for Announcer.new is deprecated. Please use "announcer.activate(:directory)" instead.')
103
- activate :directory
104
- end
105
- if @options[:cmd]
106
- warn('The use of "@announce_cmd-instance" variable and "options[:cmd] = true" for Announcer.new is deprecated. Please use "announcer.activate(:command)" instead.')
107
- activate :command
108
- end
109
- if @options[:env]
110
- warn('The use of "@announce_env-instance" variable and "options[:env] = true" for Announcer.new is deprecated. Please use "announcer.activate(:modified_environment)" instead.')
111
- activate :modified_enviroment
112
- end
113
- # rubocop:enable Metrics/LineLength
114
- end
115
- # rubocop:enable Metrics/MethodLength
116
-
117
- def output_format(channel, string = '%s', &block)
118
- if block_given?
119
- output_formats[channel.to_sym] = block
120
- elsif string.is_a?(Proc)
121
- output_formats[channel.to_sym] = string
122
- else
123
- output_formats[channel.to_sym] = proc { |*args| format(string, *args) }
124
- end
125
-
126
- self
127
- end
128
-
129
- public
130
-
131
- # Reset announcer
132
- def reset
133
- @default_announcer = @announcers.last
134
- @announcer = @announcers.first
135
- end
136
-
137
- # Change mode of announcer
138
- #
139
- # @param [Symbol] m
140
- # The mode to set
141
- def mode=(m)
142
- @announcer = @announcers.find { |a| f.mode? m.to_sym }
143
-
144
- self
145
- end
146
-
147
- # Check if channel is activated
148
- #
149
- # @param [Symbol] channel
150
- # The name of the channel to check
151
- def activated?(channel)
152
- channels[channel.to_sym] == true
153
- end
154
-
155
- # Activate a channel
156
- #
157
- # @param [Symbol] channel
158
- # The name of the channel to activate
159
- def activate(channel)
160
- channels[channel.to_sym] = true
161
-
162
- self
163
- end
164
-
165
- # Announce information to channel
166
- #
167
- # @param [Symbol] channel
168
- # The name of the channel to check
169
- #
170
- # @param [Array] args
171
- # Arguments
172
- def announce(channel, *args)
173
- channel = channel.to_sym
174
-
175
- the_output_format = if output_formats.key? channel
176
- output_formats[channel]
177
- else
178
- proc { |v| format('%s', v) }
179
- end
180
-
181
- message = the_output_format.call(*args)
182
-
183
- announcer.announce(message) if channels[channel]
184
-
185
- default_announcer.announce message
186
- end
187
-
188
- # @deprecated
189
- def stdout(content)
190
- warn('The announcer now has a new api to activate channels. Please use this one: announce(:stdout, message)')
191
- announce :stdout, content
192
- end
193
-
194
- # @deprecated
195
- def stderr(content)
196
- warn('The announcer now has a new api to activate channels. Please use this one: announce(:stderr, message)')
197
- announce :stderr, content
198
- end
199
-
200
- # @deprecated
201
- def dir(dir)
202
- warn('The announcer now has a new api to activate channels. Please use this one announce(:directory, message)')
203
- announce :directory, dir
204
- end
205
-
206
- # @deprecated
207
- def cmd(cmd)
208
- warn('The announcer now has a new api to activate channels. Please use this one announce(:command, message)')
209
- announce :command, cmd
210
- end
211
-
212
- # @deprecated
213
- def env(key, value)
214
- warn('The announcer now has a new api to activate channels. Please use this one: announce(:modified_environment, key, value)')
215
-
216
- announce :modified_environment, key, value
217
- end
218
- end
219
- end
File without changes
@@ -1,201 +0,0 @@
1
- require 'aruba/processes/null_process'
2
-
3
- module Aruba
4
- class ProcessMonitor
5
- private
6
-
7
- attr_reader :processes, :announcer
8
-
9
- public
10
-
11
- def initialize(announcer)
12
- @processes = []
13
- @announcer = announcer
14
- end
15
-
16
- def last_exit_status
17
- Aruba.platform.deprecated('The use of "#last_exit_status" is deprecated. Use "last_command_(started|stopped).exit_status" instead')
18
-
19
- return @last_exit_status if @last_exit_status
20
- all_commands.each { |c| stop_process(c) }
21
- @last_exit_status
22
- end
23
-
24
- def last_command_stopped
25
- return @last_command_stopped if @last_command_stopped
26
- return Command.new('false',
27
- :mode => :null,
28
- :exit_timeout => 0,
29
- :io_wait_timeout => 0,
30
- :working_directory => '/tmp',
31
- :environment => {},
32
- :main_class => nil,
33
- :stop_signal => nil,
34
- :startup_wait_time => nil
35
- ) if all_commands.empty?
36
-
37
- all_commands.each { |c| stop_process(c) }
38
-
39
- @last_command_stopped
40
- end
41
-
42
- def last_command_started
43
- return Command.new('false',
44
- :mode => :null,
45
- :exit_timeout => 0,
46
- :io_wait_timeout => 0,
47
- :working_directory => '/tmp',
48
- :environment => {},
49
- :main_class => nil,
50
- :stop_signal => nil,
51
- :startup_wait_time => nil
52
- ) unless processes.last.is_a? Array
53
-
54
- processes.last[1]
55
- end
56
-
57
- def stop_process(process)
58
- @last_command_stopped = process
59
- @last_exit_status = process.stop(announcer)
60
- end
61
-
62
- def terminate_process!(process)
63
- @last_command_stopped = process
64
- @last_exit_status = process.terminate
65
- end
66
-
67
- def stop_processes!
68
- Aruba.platform.deprecated('The use of "#stop_processes!" is deprecated. Use "#stop_all_commands" instead')
69
-
70
- stop_all_commands
71
- end
72
-
73
- def stop_all_commands
74
- all_commands.each { |c| c.stop(announcer) }
75
- end
76
-
77
- # Terminate all running processes
78
- def terminate_processes
79
- Aruba.platform.deprecated('The use of "#terminate_processes" is deprecated. Use "#all_commands.each(&:terminate)" instead')
80
-
81
- processes.each do |_, process|
82
- terminate_process(process)
83
- stop_process(process)
84
- end
85
- end
86
-
87
- def register_process(name, process)
88
- processes << [name, process]
89
-
90
- [name, process]
91
- end
92
-
93
- def get_process(wanted)
94
- matching_processes = processes.reverse.find{ |name, _| name == wanted }
95
- raise ArgumentError.new("No process named '#{wanted}' has been started") unless matching_processes
96
- matching_processes.last
97
- end
98
-
99
- def only_processes
100
- Aruba.platform.deprecated('The use of "#only_processes" is deprecated. Use "#all_commands" instead')
101
-
102
- processes.collect{ |_, process| process }
103
- end
104
-
105
- # Fetch output (stdout, stderr) from command
106
- #
107
- # @param [String] cmd
108
- # The command
109
- def output_from(cmd)
110
- cmd = Aruba.platform.detect_ruby(cmd)
111
- get_process(cmd).output
112
- end
113
-
114
- # Fetch stdout from command
115
- #
116
- # @param [String] cmd
117
- # The command
118
- def stdout_from(cmd)
119
- cmd = Aruba.platform.detect_ruby(cmd)
120
- get_process(cmd).stdout
121
- end
122
-
123
- # Fetch stderr from command
124
- #
125
- # @param [String] cmd
126
- # The command
127
- def stderr_from(cmd)
128
- cmd = Aruba.platform.detect_ruby(cmd)
129
- get_process(cmd).stderr
130
- end
131
-
132
- # Get stdout of all processes
133
- #
134
- # @return [String]
135
- # The stdout of all process which have run before
136
- def all_stdout
137
- # rubocop:disable Metrics/LineLength
138
- Aruba.platform.deprecated('The use of "#all_stdout" is deprecated. Use `all_commands.map { |c| c.stdout }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stdout /output/" instead')
139
- # rubocop:enable Metrics/LineLength
140
-
141
- stop_all_commands
142
-
143
- if RUBY_VERSION < '1.9'
144
- out = ''
145
- only_processes.each { |ps| out << ps.stdout }
146
-
147
- out
148
- else
149
- only_processes.each_with_object("") { |ps, o| o << ps.stdout }
150
- end
151
- end
152
-
153
- # Get stderr of all processes
154
- #
155
- # @return [String]
156
- # The stderr of all process which have run before
157
- def all_stderr
158
- # rubocop:disable Metrics/LineLength
159
- Aruba.platform.deprecated('The use of "#all_stderr" is deprecated. Use `all_commands.map { |c| c.stderr }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output_on_stderr /output/" instead')
160
- # rubocop:enable Metrics/LineLength
161
-
162
- stop_all_commands
163
-
164
- if RUBY_VERSION < '1.9'
165
- out = ''
166
- only_processes.each { |ps| out << ps.stderr }
167
-
168
- out
169
- else
170
- only_processes.each_with_object("") { |ps, o| o << ps.stderr }
171
- end
172
- end
173
-
174
- # Get stderr and stdout of all processes
175
- #
176
- # @return [String]
177
- # The stderr and stdout of all process which have run before
178
- def all_output
179
- # rubocop:disable Metrics/LineLength
180
- Aruba.platform.deprecated('The use of "#all_output" is deprecated. Use `all_commands.map { |c| c.output }.join("\n") instead. If you need to check for some output use "expect(all_commands).to have_output /output/" instead')
181
- # rubocop:enable Metrics/LineLength
182
-
183
- all_stdout << all_stderr
184
- end
185
-
186
- # Return all commands
187
- #
188
- # @return [Array]
189
- # A list of all commands
190
- def all_commands
191
- processes.collect { |_, process| process }
192
- end
193
-
194
- # Clear list of processes
195
- def clear
196
- processes.clear
197
-
198
- self
199
- end
200
- end
201
- end