aruba 0.7.4 → 0.8.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.nav +12 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +12 -0
  6. data/.simplecov +2 -0
  7. data/.travis.yml +5 -6
  8. data/Gemfile +53 -26
  9. data/History.md +17 -0
  10. data/LICENSE +1 -1
  11. data/README.md +45 -19
  12. data/Rakefile +12 -2
  13. data/TODO.md +3 -0
  14. data/aruba.gemspec +19 -8
  15. data/cucumber.yml +1 -1
  16. data/features/api/cd.feature +119 -0
  17. data/features/api/command/run.feature +37 -0
  18. data/features/api/command/which.feature +37 -0
  19. data/features/api/environment/append_environment_variable.feature +118 -0
  20. data/features/api/environment/prepend_environment_variable.feature +118 -0
  21. data/features/api/environment/set_environment_variable.feature +252 -0
  22. data/features/configuration/exit_timeout.feature +51 -0
  23. data/features/configuration/fixtures_directories.feature +31 -0
  24. data/features/configuration/fixtures_path_prefix.feature +24 -0
  25. data/features/configuration/io_timeout.feature +31 -0
  26. data/features/configuration/keep_ansi.feature +31 -0
  27. data/features/configuration/root_directory.feature +31 -0
  28. data/features/configuration/working_directory.feature +32 -0
  29. data/features/fixtures/cli-app/.gitignore +9 -0
  30. data/features/fixtures/cli-app/.rspec +2 -0
  31. data/features/fixtures/cli-app/README.md +34 -0
  32. data/features/fixtures/cli-app/Rakefile +1 -0
  33. data/features/fixtures/cli-app/bin/cli +6 -0
  34. data/features/fixtures/cli-app/cli-app.gemspec +26 -0
  35. data/features/fixtures/cli-app/features/support/env.rb +1 -0
  36. data/features/fixtures/cli-app/lib/cli/app.rb +13 -0
  37. data/features/fixtures/cli-app/lib/cli/app/version.rb +5 -0
  38. data/features/fixtures/cli-app/script/console +14 -0
  39. data/features/fixtures/cli-app/spec/cli/app_spec.rb +7 -0
  40. data/features/fixtures/cli-app/spec/spec_helper.rb +10 -0
  41. data/features/fixtures/copy/file.txt +1 -1
  42. data/features/hooks/after/command.feature +34 -0
  43. data/features/hooks/before/command.feature +61 -0
  44. data/features/matchers/directory/have_sub_directory.feature +110 -0
  45. data/features/matchers/file/be_existing_file.feature +82 -0
  46. data/features/matchers/file/have_file_content.feature +123 -0
  47. data/features/matchers/file/have_file_size.feature +107 -0
  48. data/features/matchers/path/be_an_absolute_path.feature +74 -0
  49. data/features/matchers/path/be_an_existing_path.feature +97 -0
  50. data/features/matchers/path/have_permissions.feature +118 -0
  51. data/features/matchers/timeouts.feature +48 -0
  52. data/features/step_definitions/aruba_dev_steps.rb +69 -1
  53. data/features/steps/commands/exit_statuses.feature +136 -0
  54. data/features/steps/commands/in_process.feature +129 -0
  55. data/features/steps/commands/run.feature +36 -0
  56. data/features/steps/environment/home_variable.feature +49 -0
  57. data/features/steps/environment/set_environment_variable.feature +34 -0
  58. data/features/support/aruba.rb +5 -0
  59. data/features/support/env.rb +8 -4
  60. data/lib/aruba.rb +20 -8
  61. data/lib/aruba/announcer.rb +1 -0
  62. data/lib/aruba/api.rb +18 -1179
  63. data/lib/aruba/api/command.rb +351 -0
  64. data/lib/aruba/api/core.rb +141 -0
  65. data/lib/aruba/api/deprecated.rb +549 -0
  66. data/lib/aruba/api/environment.rb +61 -0
  67. data/lib/aruba/api/filesystem.rb +305 -0
  68. data/lib/aruba/api/rvm.rb +39 -0
  69. data/lib/aruba/aruba_path.rb +75 -0
  70. data/lib/aruba/basic_configuration.rb +208 -0
  71. data/lib/aruba/basic_configuration/option.rb +25 -0
  72. data/lib/aruba/config.rb +43 -30
  73. data/lib/aruba/config/jruby.rb +14 -0
  74. data/lib/aruba/config_wrapper.rb +17 -0
  75. data/lib/aruba/contracts/relative_path.rb +13 -0
  76. data/lib/aruba/creators/aruba_file_creator.rb +32 -0
  77. data/lib/aruba/creators/aruba_fixed_size_file_creator.rb +32 -0
  78. data/lib/aruba/cucumber.rb +87 -53
  79. data/lib/aruba/cucumber/hooks.rb +65 -10
  80. data/lib/aruba/environment.rb +121 -0
  81. data/lib/aruba/errors.rb +3 -0
  82. data/lib/aruba/extensions/string/strip.rb +24 -0
  83. data/lib/aruba/hooks.rb +54 -0
  84. data/lib/aruba/jruby.rb +4 -9
  85. data/lib/aruba/matchers/command.rb +1 -79
  86. data/lib/aruba/matchers/command/be_successfully_executed.rb +30 -0
  87. data/lib/aruba/matchers/command/have_exit_status.rb +47 -0
  88. data/lib/aruba/matchers/command/have_finished_in_time.rb +42 -0
  89. data/lib/aruba/matchers/directory.rb +1 -59
  90. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +34 -0
  91. data/lib/aruba/matchers/directory/have_sub_directory.rb +49 -0
  92. data/lib/aruba/matchers/file.rb +1 -177
  93. data/lib/aruba/matchers/file/be_an_existing_file.rb +34 -0
  94. data/lib/aruba/matchers/file/have_file_content.rb +58 -0
  95. data/lib/aruba/matchers/file/have_file_size.rb +43 -0
  96. data/lib/aruba/matchers/file/have_same_file_content.rb +44 -0
  97. data/lib/aruba/matchers/path.rb +1 -99
  98. data/lib/aruba/matchers/path/a_path_matching_pattern.rb +21 -0
  99. data/lib/aruba/matchers/path/be_an_absolute_path.rb +32 -0
  100. data/lib/aruba/matchers/path/be_an_existing_path.rb +33 -0
  101. data/lib/aruba/matchers/path/have_permissions.rb +60 -0
  102. data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
  103. data/lib/aruba/matchers/rspec.rb +0 -0
  104. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +1 -1
  105. data/lib/aruba/platform.rb +230 -0
  106. data/lib/aruba/process_monitor.rb +23 -5
  107. data/lib/aruba/processes/basic_process.rb +35 -1
  108. data/lib/aruba/processes/debug_process.rb +26 -15
  109. data/lib/aruba/processes/in_process.rb +21 -9
  110. data/lib/aruba/processes/spawn_process.rb +29 -19
  111. data/lib/aruba/reporting.rb +2 -0
  112. data/lib/aruba/rspec.rb +61 -13
  113. data/lib/aruba/runtime.rb +33 -0
  114. data/script/bootstrap +4 -6
  115. data/spec/aruba/api/runtime_spec.rb +28 -0
  116. data/spec/aruba/api_spec.rb +129 -126
  117. data/spec/aruba/aruba_path_spec.rb +65 -0
  118. data/spec/aruba/basic_configuration_spec.rb +5 -0
  119. data/spec/aruba/config_wrapper_spec.rb +25 -0
  120. data/spec/aruba/configuration_spec.rb +5 -0
  121. data/spec/aruba/jruby_spec.rb +34 -18
  122. data/spec/aruba/matchers/directory_spec.rb +6 -7
  123. data/spec/aruba/matchers/file_spec.rb +16 -20
  124. data/spec/aruba/matchers/path_spec.rb +14 -11
  125. data/spec/aruba/rspec_spec.rb +15 -0
  126. data/spec/aruba/runtime_spec.rb +29 -0
  127. data/spec/aruba/spawn_process_spec.rb +2 -2
  128. data/spec/spec_helper.rb +10 -2
  129. data/spec/support/configs/rspec.rb +1 -1
  130. data/spec/support/matchers/option.rb +35 -0
  131. data/spec/support/shared_contexts/aruba.rb +10 -8
  132. data/spec/support/shared_examples/configuration.rb +116 -0
  133. metadata +182 -33
  134. data/.rvmrc +0 -1
  135. data/features/before_cmd_hooks.feature +0 -61
  136. data/features/command_environment_variables.feature +0 -31
  137. data/features/custom_ruby_process.feature +0 -12
  138. data/features/exit_statuses.feature +0 -30
  139. data/features/support/custom_main.rb +0 -28
  140. data/lib/aruba/matchers/mode.rb +0 -52
  141. data/lib/aruba/utils.rb +0 -21
@@ -0,0 +1,208 @@
1
+ require 'contracts'
2
+ require 'aruba/basic_configuration/option'
3
+
4
+ module Aruba
5
+ # Basic configuration for ProxyPacRb
6
+ class BasicConfiguration
7
+ include Contracts
8
+
9
+ class << self
10
+ def known_options
11
+ @known_options ||= {}
12
+ end
13
+
14
+ def option_reader(name, opts = {})
15
+ contract = opts[:contract]
16
+ default = opts[:default]
17
+
18
+ fail ArgumentError, 'Either use block or default value' if block_given? && default
19
+ fail ArgumentError, 'contract-options is required' if contract.nil?
20
+
21
+ Contract contract
22
+ add_option(name, block_given? ? yield(ConfigWrapper.new(known_options)) : default)
23
+
24
+ define_method(name) { find_option(name).value }
25
+
26
+ self
27
+ end
28
+
29
+ # rubocop:disable Metrics/CyclomaticComplexity
30
+ def option_accessor(name, opts = {})
31
+ contract = opts[:contract]
32
+ default = opts[:default]
33
+
34
+ fail ArgumentError, 'Either use block or default value' if block_given? && default
35
+ fail ArgumentError, 'Either use block or default value' if !block_given? && default.nil? && default.empty?
36
+ fail ArgumentError, 'contract-options is required' if contract.nil?
37
+
38
+ # Add writer
39
+ add_option(name, block_given? ? yield(ConfigWrapper.new(known_options)) : default)
40
+
41
+ Contract contract
42
+ define_method("#{name}=") { |v| find_option(name).value = v }
43
+
44
+ # Add reader
45
+ option_reader name, :contract => { None => contract.values.first }
46
+ end
47
+ # rubocop:enable Metrics/CyclomaticComplexity
48
+
49
+ private
50
+
51
+ def add_option(name, value = nil)
52
+ return if known_options.key?(name)
53
+
54
+ known_options[name] = Option.new(:name => name, :value => value)
55
+
56
+ self
57
+ end
58
+ end
59
+
60
+ protected
61
+
62
+ attr_accessor :local_options
63
+ attr_writer :hooks
64
+
65
+ # attr_reader :hooks
66
+
67
+ public
68
+
69
+ def initialize
70
+ initialize_configuration
71
+ end
72
+
73
+ # @yield [Configuration]
74
+ #
75
+ # Yields self
76
+ def configure
77
+ yield self if block_given?
78
+ end
79
+
80
+ # Reset configuration
81
+ def reset
82
+ initialize_configuration
83
+ end
84
+
85
+ # Make deep dup copy of configuration
86
+ def make_copy
87
+ obj = self.dup
88
+ obj.local_options = Marshal.load(Marshal.dump(local_options))
89
+ obj.hooks = @hooks
90
+
91
+ obj
92
+ end
93
+
94
+ # Get access to hooks
95
+ def hooks
96
+ # rubocop:disable Metrics/LineLength
97
+ Aruba::Platform.deprecated 'The use of the "#aruba.config.hooks" is deprecated. Please use "#aruba.config.before(:name) {}" to define and "#aruba.config.before(:name, *args)" to run a hook. This method will become private in the next major version.'
98
+ # rubocop:enable Metrics/LineLength
99
+
100
+ @hooks
101
+ end
102
+
103
+ # @deprecated
104
+ def before_cmd(&block)
105
+ Aruba::Platform.deprecated 'The use of the "#before_cmd"-hook is deprecated. Please define with "#before(:command) {}" instead'
106
+
107
+ before(:command, &block)
108
+ end
109
+
110
+ # Define or run before-hook
111
+ #
112
+ # @param [Symbol, String] name
113
+ # The name of the hook
114
+ #
115
+ # @param [Proc] context
116
+ # The context a hook should run in. This is a runtime only option.
117
+ #
118
+ # @param [Array] args
119
+ # Arguments for the run of hook. This is a runtime only option.
120
+ #
121
+ # @yield
122
+ # The code block which should be run. This is a configure time only option
123
+ def before(name, context = proc {}, *args, &block)
124
+ name = format('%s_%s', 'before_', name.to_s).to_sym
125
+
126
+ if block_given?
127
+ @hooks.append(name, block)
128
+
129
+ self
130
+ else
131
+ @hooks.execute(name, context, *args)
132
+ end
133
+ end
134
+
135
+ # Define or run after-hook
136
+ #
137
+ # @param [Symbol, String] name
138
+ # The name of the hook
139
+ #
140
+ # @param [Proc] context
141
+ # The context a hook should run in. This is a runtime only option.
142
+ #
143
+ # @param [Array] args
144
+ # Arguments for the run of hook. This is a runtime only option.
145
+ #
146
+ # @yield
147
+ # The code block which should be run. This is a configure time only option
148
+ def after(name, context = proc {}, *args, &block)
149
+ name = format('%s_%s', 'after_', name.to_s).to_sym
150
+
151
+ if block_given?
152
+ @hooks.append(name, block)
153
+
154
+ self
155
+ else
156
+ @hooks.execute(name, context, *args)
157
+ end
158
+ end
159
+
160
+ # Check if before-hook <name> is defined
161
+ def before?(name)
162
+ name = format('%s_%s', 'before_', name.to_s).to_sym
163
+
164
+ @hooks.exist? name
165
+ end
166
+
167
+ # Check if after-hook <name> is defined
168
+ def after?(name)
169
+ name = format('%s_%s', 'after_', name.to_s).to_sym
170
+
171
+ @hooks.exist? name
172
+ end
173
+
174
+ # Check if <name> is option
175
+ #
176
+ # @param [String, Symbol] name
177
+ # The name of the option
178
+ def option?(name)
179
+ local_options.any? { |_, v| v.name == name.to_sym }
180
+ end
181
+
182
+ def ==(other)
183
+ local_options.values.map(&:value) == other.local_options.values.map(&:value)
184
+ end
185
+
186
+ # Set if name is option
187
+ def set_if_option(name, *args)
188
+ if RUBY_VERSION < '1.9'
189
+ send("#{name}=".to_sym, *args) if option? name
190
+ else
191
+ public_send("#{name}=".to_sym, *args) if option? name
192
+ end
193
+ end
194
+
195
+ private
196
+
197
+ def initialize_configuration
198
+ @local_options = Marshal.load(Marshal.dump(self.class.known_options))
199
+ @hooks = Hooks.new
200
+ end
201
+
202
+ def find_option(name)
203
+ fail NotImplementedError, %(Unknown option "#{name}") unless option? name
204
+
205
+ local_options[name]
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,25 @@
1
+ module Aruba
2
+ class BasicConfiguration
3
+ # A configuration option
4
+ class Option
5
+ attr_accessor :name, :value
6
+ attr_reader :default_value
7
+
8
+ def initialize(opts = {})
9
+ name = opts[:name]
10
+ value = opts[:value]
11
+
12
+ fail ArgumentError, '"name" is required' if name.nil?
13
+ fail ArgumentError, '"value" is required' if value.nil?
14
+
15
+ @name = name
16
+ @value = value
17
+ @default_value = value
18
+ end
19
+
20
+ def ==(other)
21
+ name == other.name && value == other.value
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,43 +1,56 @@
1
- module Aruba
2
- class Config
3
- attr_reader :hooks
1
+ require 'contracts'
2
+ require 'aruba/basic_configuration'
3
+ require 'aruba/config_wrapper'
4
+ require 'aruba/hooks'
5
+ require 'aruba/contracts/relative_path'
4
6
 
5
- def initialize
6
- @hooks = Hooks.new
7
+ module Aruba
8
+ # Aruba Configuration
9
+ class Configuration < BasicConfiguration
10
+ # As of 1.0.0 root_directory is read-only
11
+ # option_reader :root_directory, :contract => { None => String }, :default => Dir.getwd
12
+ option_accessor :root_directory, :contract => { String => String }, :default => Dir.getwd
13
+ option_accessor :working_directory, :contract => { Aruba::Contracts::RelativePath => Aruba::Contracts::RelativePath }, :default => 'tmp/aruba'
14
+
15
+ if RUBY_VERSION < '1.9'
16
+ option_reader :fixtures_path_prefix, :contract => { None => String }, :default => '%'
17
+ else
18
+ option_reader :fixtures_path_prefix, :contract => { None => String }, :default => ?%
7
19
  end
8
20
 
9
- # Register a hook to be called before Aruba runs a command
10
- def before_cmd(&block)
11
- @hooks.append(:before_cmd, block)
12
- end
21
+ option_accessor :exit_timeout, :contract => { Num => Num }, :default => 15
22
+ option_accessor :io_wait_timeout, :contract => { Num => Num }, :default => 0.1
23
+ option_accessor :fixtures_directories, :contract => { Array => ArrayOf[String] }, :default => %w(features/fixtures spec/fixtures test/fixtures)
24
+ option_accessor :command_runtime_environment, :contract => { Hash => Hash }, :default => ENV.to_hash
25
+ option_accessor(:command_search_paths, :contract => { ArrayOf[String] => ArrayOf[String] }) { |config| [File.join(config.root_directory.value, 'bin')] }
26
+ option_accessor :keep_ansi, :contract => { Bool => Bool }, :default => false
13
27
  end
28
+ end
14
29
 
15
- #nodoc
16
- class Hooks
17
- def initialize
18
- @store = Hash.new do |hash, key|
19
- hash[key] = []
20
- end
21
- end
30
+ # Main Module
31
+ module Aruba
32
+ @config = Configuration.new
22
33
 
23
- def append(label, block)
24
- @store[label] << block
25
- end
34
+ class << self
35
+ attr_reader :config
36
+
37
+ def configure(&block)
38
+ @config.configure(&block)
26
39
 
27
- def execute(label, context, *args)
28
- @store[label].each do |block|
29
- context.instance_exec(*args, &block)
30
- end
40
+ self
31
41
  end
32
42
  end
43
+ end
33
44
 
34
- class << self
35
- attr_accessor :config
36
-
37
- def configure
38
- yield config
45
+ module Aruba
46
+ # Old Config
47
+ #
48
+ # @private
49
+ class Config < Configuration
50
+ def initialize(*args)
51
+ warn('The use of "Aruba::Config" is deprecated. Use "Aruba::Configuration" instead.')
52
+
53
+ super
39
54
  end
40
55
  end
41
-
42
- self.config = Config.new
43
56
  end
@@ -0,0 +1,14 @@
1
+ require 'rbconfig'
2
+
3
+ # ideas taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
4
+ Aruba.configure do |config|
5
+ config.before :command do
6
+ next unless RUBY_PLATFORM == 'java'
7
+
8
+ # disable JIT since these processes are so short lived
9
+ ENV['JRUBY_OPTS'] = "-X-C #{ENV['JRUBY_OPTS']}"
10
+
11
+ # force jRuby to use client JVM for faster startup times
12
+ ENV['JAVA_OPTS'] = "-d32 #{ENV['JAVA_OPTS']}" if RbConfig::CONFIG['host_os'] =~ /solaris|sunos/i
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Aruba
2
+ class ConfigWrapper
3
+ attr_reader :config
4
+ private :config
5
+
6
+ def initialize(config)
7
+ @config = config.dup
8
+ end
9
+
10
+ def method_missing(name, *args)
11
+ fail ArgumentError, 'Options take no argument' if args.count > 0
12
+ fail UnknownOptionError, %(Option "#{name}" is unknown. Please use only earlier defined options) unless config.key? name
13
+
14
+ config[name]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'aruba/aruba_path'
2
+
3
+ module Aruba
4
+ module Contracts
5
+ class RelativePath
6
+ def self.valid?(value)
7
+ ArubaPath.new(value).relative?
8
+ rescue
9
+ false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module Aruba
2
+ # Create things to make aruba work
3
+ module Creators
4
+ # Normal File Creator
5
+ # This class is not meant to be used directly by users.
6
+ class ArubaFileCreator
7
+ # Write File
8
+ #
9
+ # @param [String] path
10
+ # The path to write content to
11
+ #
12
+ # @param [Object] content
13
+ # The content of the file
14
+ #
15
+ # @param [TrueClass, FalseClass] check_presence (false)
16
+ # Check if file exist
17
+ def write(path, content, check_presence = false)
18
+ fail "Expected #{path} to be present" if check_presence && !Aruba::Platform.file?(path)
19
+
20
+ Aruba::Platform.mkdir(File.dirname(path))
21
+
22
+ if RUBY_VERSION < '1.9'
23
+ File.open(path, 'w') { |f| f << content }
24
+ else
25
+ File.write(path, content)
26
+ end
27
+
28
+ self
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Aruba
2
+ # Create things to make aruba work
3
+ module Creators
4
+ # Create files with fixed size
5
+ #
6
+ # This class is not meant to be used directly by users.
7
+ #
8
+ # It uses a single null byte as content and really creates so called sparse
9
+ # files.
10
+ class ArubaFixedSizeFileCreator
11
+ # Write File
12
+ #
13
+ # @param [String] path
14
+ # The path to write content to
15
+ #
16
+ # @param [Numeric] size
17
+ # The size of the file
18
+ #
19
+ # @param [TrueClass, FalseClass] check_presence (false)
20
+ # Check if file exist
21
+ def write(path, size, check_presence)
22
+ fail "Expected #{path} to be present" if check_presence && !Aruba::Platform.file?(path)
23
+
24
+ Aruba::Platform.mkdir(File.dirname(path))
25
+
26
+ File.open(path, "wb"){ |f| f.seek(size - 1); f.write("\0") }
27
+
28
+ self
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,21 +1,21 @@
1
1
  require 'aruba/api'
2
+ World(Aruba::Api)
3
+
2
4
  require 'aruba/cucumber/hooks'
3
5
  require 'aruba/reporting'
4
6
 
5
- World(Aruba::Api)
6
-
7
7
  Given /the default aruba timeout is (\d+) seconds/ do |seconds|
8
- @aruba_timeout_seconds = seconds.to_i
8
+ aruba.config.exit_timeout = seconds.to_i
9
9
  end
10
10
 
11
11
  Given /I use (?:a|the) fixture(?: named)? "([^"]*)"/ do |name|
12
- copy File.join(Aruba::Api::FIXTURES_PATH_PREFIX, name), name
12
+ copy File.join(aruba.config.fixtures_path_prefix, name), name
13
13
  cd name
14
14
  end
15
15
 
16
16
  Given /The default aruba timeout is (\d+) seconds/ do |seconds|
17
17
  warn(%{\e[35m The /^The default aruba timeout is (\d+) seconds/ step definition is deprecated. Please use the one with `the` and not `The` at the beginning.\e[0m})
18
- @aruba_timeout_seconds = seconds.to_i
18
+ aruba.config.exit_timeout = seconds.to_i
19
19
  end
20
20
 
21
21
  Given /^I'm using a clean gemset "([^"]*)"$/ do |gemset|
@@ -23,12 +23,12 @@ Given /^I'm using a clean gemset "([^"]*)"$/ do |gemset|
23
23
  end
24
24
 
25
25
  Given /^(?:a|the) directory(?: named)? "([^"]*)"$/ do |dir_name|
26
- create_dir(dir_name)
26
+ create_directory(dir_name)
27
27
  end
28
28
 
29
29
  Given /^(?:a|the) directory(?: named)? "([^"]*)" with mode "([^"]*)"$/ do |dir_name, dir_mode|
30
- create_dir(dir_name)
31
- filesystem_permissions(dir_mode, dir_name)
30
+ create_directory(dir_name)
31
+ chmod(dir_mode, dir_name)
32
32
  end
33
33
 
34
34
  Given /^(?:a|the) file(?: named)? "([^"]*)" with:$/ do |file_name, file_content|
@@ -37,7 +37,7 @@ end
37
37
 
38
38
  Given /^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/ do |file_name, file_mode, file_content|
39
39
  write_file(file_name, file_content)
40
- filesystem_permissions(file_mode, file_name)
40
+ chmod(file_mode, file_name)
41
41
  end
42
42
 
43
43
  Given /^(?:a|the) (\d+) byte file(?: named)? "([^"]*)"$/ do |file_size, file_name|
@@ -50,15 +50,15 @@ end
50
50
 
51
51
  Given /^(?:an|the) empty file(?: named)? "([^"]*)" with mode "([^"]*)"$/ do |file_name, file_mode|
52
52
  write_file(file_name, "")
53
- filesystem_permissions(file_mode, file_name)
53
+ chmod(file_mode, file_name)
54
54
  end
55
55
 
56
56
  Given /^a mocked home directory$/ do
57
- set_env 'HOME', File.expand_path(current_dir)
57
+ set_environment_variable 'HOME', expand_path('.')
58
58
  end
59
59
 
60
60
  Given /^(?:a|the) directory(?: named)? "([^"]*)" does not exist$/ do |directory_name|
61
- remove_directory(directory_name, force: true)
61
+ remove_directory(directory_name, :force => true)
62
62
  end
63
63
 
64
64
  When /^I write to "([^"]*)" with:$/ do |file_name, file_content|
@@ -82,7 +82,7 @@ When /^I remove (?:a|the) file(?: named)? "([^"]*)"$/ do |file_name|
82
82
  end
83
83
 
84
84
  Given /^(?:a|the) file(?: named)? "([^"]*)" does not exist$/ do |file_name|
85
- remove_file(file_name, force: true)
85
+ remove_file(file_name, :force => true)
86
86
  end
87
87
 
88
88
  When(/^I remove (?:a|the) directory(?: named)? "(.*?)"$/) do |directory_name|
@@ -98,37 +98,37 @@ Given /^I set the environment variables to:/ do |table|
98
98
  variable = row['variable'].to_s.upcase
99
99
  value = row['value'].to_s
100
100
 
101
- set_env(variable, value)
101
+ set_environment_variable(variable, value)
102
102
  end
103
103
  end
104
104
 
105
105
  Given /^I append the value to the environment variable:/ do |table|
106
106
  table.hashes.each do |row|
107
107
  variable = row['variable'].to_s.upcase
108
- value = row['value'].to_s + row['value'].to_s
108
+ value = row['value'].to_s
109
109
 
110
- set_env(variable, value)
110
+ append_environment_variable(variable, value)
111
111
  end
112
112
  end
113
113
 
114
114
  When /^I run "(.*)"$/ do |cmd|
115
115
  warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
116
- run_simple(unescape(cmd), false)
116
+ run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false)
117
117
  end
118
118
 
119
119
  When /^I run `([^`]*)`$/ do |cmd|
120
- run_simple(unescape(cmd), false)
120
+ run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), false)
121
121
  end
122
122
 
123
123
  When /^I successfully run "(.*)"$/ do |cmd|
124
124
  warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
125
- run_simple(unescape(cmd))
125
+ run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi))
126
126
  end
127
127
 
128
128
  ## I successfully run `echo -n "Hello"`
129
129
  ## I successfully run `sleep 29` for up to 30 seconds
130
130
  When /^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/ do |cmd, secs|
131
- run_simple(unescape(cmd), true, secs && secs.to_i)
131
+ run_simple(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi), true, secs && secs.to_i)
132
132
  end
133
133
 
134
134
  When /^I run "([^"]*)" interactively$/ do |cmd|
@@ -137,7 +137,7 @@ When /^I run "([^"]*)" interactively$/ do |cmd|
137
137
  end
138
138
 
139
139
  When /^I run `([^`]*)` interactively$/ do |cmd|
140
- @interactive = run(unescape(cmd))
140
+ @interactive = run(Aruba::Platform.unescape(cmd, aruba.config.keep_ansi))
141
141
  end
142
142
 
143
143
  When /^I type "([^"]*)"$/ do |input|
@@ -318,68 +318,102 @@ Then /^the stderr from "([^"]*)" should not contain "([^"]*)"$/ do |cmd, unexpec
318
318
  assert_no_partial_output(unexpected, stderr_from(cmd))
319
319
  end
320
320
 
321
- Then /^the following files should (not )?exist:$/ do |expect_match, files|
322
- files.raw.each do |row|
323
- if expect_match
324
- expect(row[0]).not_to be_existing_file
325
- else
326
- expect(row[0]).to be_existing_file
327
- end
321
+ Then /^the following files should (not )?exist:$/ do |negated, files|
322
+ files = files.rows.flatten
323
+
324
+ if negated
325
+ expect(files).not_to include an_existing_file
326
+ else
327
+ expect(files).to all be_an_existing_file
328
328
  end
329
329
  end
330
330
 
331
331
  Then /^(?:a|the) file(?: named)? "([^"]*)" should (not )?exist$/ do |file, expect_match|
332
332
  if expect_match
333
- expect(file).not_to be_existing_file
333
+ expect(file).not_to be_an_existing_file
334
334
  else
335
- expect(file).to be_existing_file
335
+ expect(file).to be_an_existing_file
336
336
  end
337
337
  end
338
338
 
339
339
  Then /^(?:a|the) file matching %r<(.*?)> should (not )?exist$/ do |pattern, expect_match|
340
340
  if expect_match
341
- expect(all_paths).not_to match_path_pattern(Regexp.new(pattern))
341
+ expect(all_paths).not_to include match Regexp.new(pattern)
342
342
  else
343
- expect(all_paths).to match_path_pattern(Regexp.new(pattern))
343
+ expect(all_paths).to include match Regexp.new(pattern)
344
344
  end
345
345
  end
346
346
 
347
- Then /^(?:a|the) (\d+) byte file(?: named)? "([^"]*)" should exist$/ do |file_size, file_name|
348
- check_file_size([[file_name, file_size.to_i]])
347
+ Then /^(?:a|the) (\d+) byte file(?: named)? "([^"]*)" should (not )?exist$/ do |size, file, negated|
348
+ if negated
349
+ expect(file).not_to have_file_size(size)
350
+ else
351
+ expect(file).to have_file_size(size)
352
+ end
349
353
  end
350
354
 
351
- Then /^the following directories should (not )?exist:$/ do |expect_match, directories|
352
- check_directory_presence(directories.raw.map{|directory_row| directory_row[0]}, !expect_match)
353
- end
355
+ Then /^the following directories should (not )?exist:$/ do |negated, directories|
356
+ directories = directories.rows.flatten
354
357
 
355
- Then /^(?:a|the) directory(?: named)? "([^"]*)" should (not )?exist$/ do |directory, expect_match|
356
- check_directory_presence([directory], !expect_match)
358
+ if negated
359
+ expect(directories).not_to include an_existing_directory
360
+ else
361
+ expect(directories).to all be_an_existing_directory
362
+ end
357
363
  end
358
364
 
359
- Then /^(?:a|the) file "([^"]*)" should (not )?contain "([^"]*)"$/ do |file, expect_match, partial_content|
360
- check_file_content(file, Regexp.compile(Regexp.escape(partial_content)), !expect_match)
365
+ Then /^(?:a|the) directory(?: named)? "([^"]*)" should (not )?exist$/ do |directory, negated|
366
+ if negated
367
+ expect(directory).not_to be_an_existing_directory
368
+ else
369
+ expect(directory).to be_an_existing_directory
370
+ end
361
371
  end
362
372
 
363
- Then /^(?:a|the) file "([^"]*)" should (not )?contain:$/ do |file, expect_match, partial_content|
364
- check_file_content(file, Regexp.compile(Regexp.escape(partial_content)), !expect_match)
373
+ Then /^(?:a|the) file "([^"]*)" should (not )?contain "([^"]*)"$/ do |file, negated, content|
374
+ if negated
375
+ expect(file).not_to have_file_content Regexp.new(content)
376
+ else
377
+ expect(file).to have_file_content Regexp.new(content)
378
+ end
365
379
  end
366
380
 
367
- Then /^(?:a|the) file "([^"]*)" should (not )?contain exactly:$/ do |file, expect_match, exact_content|
368
- check_file_content(file, exact_content, !expect_match)
381
+ Then /^(?:a|the) file "([^"]*)" should (not )?contain:$/ do |file, negated, content|
382
+ if negated
383
+ expect(file).not_to have_file_content Regexp.new(content.chomp)
384
+ else
385
+ expect(file).to have_file_content Regexp.new(content.chomp)
386
+ end
369
387
  end
370
388
 
371
- Then /^(?:a|the) file "([^"]*)" should (not )?match \/([^\/]*)\/$/ do |file, expect_match, partial_content|
372
- check_file_content(file, /#{partial_content}/, !expect_match)
389
+ Then /^(?:a|the) file "([^"]*)" should (not )?contain exactly:$/ do |file, negated, content|
390
+ if negated
391
+ expect(file).not_to have_file_content content
392
+ else
393
+ expect(file).to have_file_content content
394
+ end
373
395
  end
374
396
 
375
- Then /^(?:a|the) file "([^"]*)" should (not )?be equal to file "([^"]*)"/ do |file, expect_match, reference_file|
376
- check_binary_file_content(file, reference_file, !expect_match)
397
+ Then /^(?:a|the) file "([^"]*)" should (not )?match \/([^\/]*)\/$/ do |file, negated, content|
398
+ if negated
399
+ expect(file).not_to have_file_content Regexp.new(content)
400
+ else
401
+ expect(file).to have_file_content Regexp.new(content)
402
+ end
377
403
  end
378
404
 
379
- Then /^the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)"$/ do |file, expect_match, mode|
380
- check_filesystem_permissions(mode, file, !expect_match)
405
+ Then /^(?:a|the) file "([^"]*)" should (not )?be equal to file "([^"]*)"/ do |file, negated, reference_file|
406
+ if negated
407
+ expect(file).not_to have_same_file_content_like(reference_file)
408
+ else
409
+ expect(file).to have_same_file_content_like(reference_file)
410
+ end
381
411
  end
382
412
 
383
- Before '@mocked_home_directory' do
384
- set_env 'HOME', expand_path('.')
413
+ Then /^the mode of filesystem object "([^"]*)" should (not )?match "([^"]*)"$/ do |file, negated, permissions|
414
+ if negated
415
+ expect(file).not_to have_permissions(permissions)
416
+ else
417
+ expect(file).to have_permissions(permissions)
418
+ end
385
419
  end