aruba 0.8.0 → 0.8.1

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +56 -2
  3. data/appveyor.yml +32 -0
  4. data/aruba.gemspec +5 -23
  5. data/features/api/core/expand_path.feature +72 -0
  6. data/features/configuration/fixtures_directories.feature +8 -1
  7. data/features/configuration/home_directory.feature +81 -0
  8. data/features/fixtures/empty-app/.gitignore +9 -0
  9. data/features/fixtures/empty-app/.rspec +2 -0
  10. data/features/fixtures/empty-app/README.md +34 -0
  11. data/features/fixtures/empty-app/Rakefile +1 -0
  12. data/features/fixtures/empty-app/bin/cli +6 -0
  13. data/features/fixtures/empty-app/cli-app.gemspec +26 -0
  14. data/features/fixtures/empty-app/lib/cli/app.rb +13 -0
  15. data/features/fixtures/empty-app/lib/cli/app/version.rb +5 -0
  16. data/features/fixtures/empty-app/script/console +14 -0
  17. data/features/fixtures/empty-app/spec/spec_helper.rb +9 -0
  18. data/features/integration/rspec/getting_started.feature +148 -0
  19. data/features/step_definitions/aruba_dev_steps.rb +7 -6
  20. data/features/steps/environment/home_variable.feature +21 -8
  21. data/features/support/aruba.rb +2 -1
  22. data/lib/aruba/announcer.rb +83 -19
  23. data/lib/aruba/api.rb +6 -1
  24. data/lib/aruba/api/command.rb +15 -5
  25. data/lib/aruba/api/core.rb +8 -6
  26. data/lib/aruba/api/environment.rb +4 -2
  27. data/lib/aruba/config.rb +20 -3
  28. data/lib/aruba/contracts/absolute_path.rb +13 -0
  29. data/lib/aruba/cucumber.rb +8 -0
  30. data/lib/aruba/cucumber/hooks.rb +33 -18
  31. data/lib/aruba/matchers/environment.rb +1 -0
  32. data/lib/aruba/process_monitor.rb +1 -1
  33. data/lib/aruba/rspec.rb +42 -26
  34. data/lib/aruba/version.rb +3 -0
  35. data/script/test +1 -1
  36. metadata +34 -25
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cli/app"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'cli/app'
4
+
5
+ if RUBY_VERSION < '1.9.'
6
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
7
+ else
8
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
9
+ end
@@ -0,0 +1,148 @@
1
+ Feature: Getting started with RSpec and aruba
2
+
3
+ Background:
4
+ Given I use the fixture "empty-app"
5
+
6
+ Scenario: Simple Integration
7
+
8
+ To use the simple integration just require `aruba/rspec` in your
9
+ `spec_helper.rb`. After that you only need to flag your tests with `type:
10
+ :aruba` and some things are set up for.
11
+
12
+ The simple integration adds some `before(:each)`-hooks for you:
13
+
14
+ \* Setup Aruba Test directory
15
+ \* Clear environment (ENV)
16
+ \* Make HOME-variable configarable via `arub.config.home_directory`
17
+ \* Configure `aruba` via `RSpec`-metadata
18
+ \* Activate announcers based on `RSpec`-metadata
19
+
20
+ Be careful, if you are going to use a `before(:all)`-hook to set up
21
+ files/directories. Those will be deleted by the `setup_aruba`-call within
22
+ the `before(:each)`-hook. Look for some custom integration further down the
23
+ documentation for a solution.
24
+
25
+ Given a file named "spec/spec_helper.rb" with:
26
+ """
27
+ require 'aruba/rspec'
28
+ """
29
+ And a file named "spec/getting_started_spec.rb" with:
30
+ """
31
+ require 'spec_helper'
32
+
33
+ RSpec.describe 'Integrate Aruba into RSpec', :type => :aruba do
34
+ context 'when to be or not be...' do
35
+ it { expect(aruba).to be }
36
+ end
37
+
38
+ context 'when write file' do
39
+ let(:file) { 'file.txt' }
40
+
41
+ before(:each) { write_file file, 'Hello World' }
42
+
43
+ it { expect(file).to be_an_existing_file }
44
+ it { expect([file]).to include an_existing_file }
45
+ end
46
+ end
47
+ """
48
+ When I run `rspec`
49
+ Then the specs should all pass
50
+
51
+ Scenario: Simple Custom Integration
52
+
53
+ There might be some use cases where you want to build an aruba integration
54
+ of your own. You need to include the API and make sure, that you run
55
+
56
+ \* `restore_env` (only for aruba < 1.0.0)
57
+ \* `setup_aruba`
58
+
59
+ before any method of aruba is used.
60
+
61
+ Given a file named "spec/spec_helper.rb" with:
62
+ """
63
+ require 'aruba/api'
64
+
65
+ RSpec.configure do |config|
66
+ config.include Aruba::Api
67
+ end
68
+ """
69
+ And a file named "spec/getting_started_spec.rb" with:
70
+ """
71
+ require 'spec_helper'
72
+
73
+ RSpec.describe 'Custom Integration of aruba' do
74
+ let(:file) { 'file.txt' }
75
+
76
+ before(:each) { setup_aruba }
77
+ before(:each) { write_file file, 'Hello World' }
78
+
79
+ it { expect(file).to be_an_existing_file }
80
+ end
81
+ """
82
+ When I run `rspec`
83
+ Then the specs should all pass
84
+
85
+ Scenario: Custom Integration using before(:all)-hook
86
+
87
+ You can even use `aruba` within a `before(:all)`-hook. But again, make sure
88
+ that `setup_aruba` is run before you use any method of `aruba`. Using
89
+ `setup_aruba` both in `before(:all)`- and `before(:each)`-hook is not
90
+ possible and therefor not supported:
91
+
92
+ Running `setup_aruba` removes `tmp/aruba`, creates a new one `tmp/aruba`
93
+ and make it the working directory. Running it within a `before(:all)`-hook,
94
+ run some `aruba`-method and then run `setup_arub` again within a
95
+ `before(:each)`-hook, will remove the files/directories created within the
96
+ `before(:all)`-hook.
97
+
98
+ Given a file named "spec/spec_helper.rb" with:
99
+ """
100
+ require 'aruba/api'
101
+
102
+ RSpec.configure do |config|
103
+ config.include Aruba::Api
104
+ end
105
+ """
106
+ And a file named "spec/getting_started_spec.rb" with:
107
+ """
108
+ require 'spec_helper'
109
+
110
+ RSpec.describe 'Custom Integration of aruba' do
111
+ before(:all) { setup_aruba }
112
+ before(:all) { write_file 'file.txt', 'Hello World' }
113
+
114
+ it { expect('file.txt').to be_an_existing_file }
115
+ end
116
+ """
117
+ When I run `rspec`
118
+ Then the specs should all pass
119
+
120
+ Scenario: Fail-safe use if "setup_aruba" is not used
121
+
122
+ If you forgot to run `setup_aruba` before the first method of aruba is
123
+ used, you might see an error. Although we did our best to prevent this.
124
+
125
+ Make sure that you run `setup_aruba` before any method of aruba is used. At
126
+ best before each and every test.
127
+
128
+ Given a file named "spec/spec_helper.rb" with:
129
+ """
130
+ require 'aruba/api'
131
+
132
+ RSpec.configure do |config|
133
+ config.include Aruba::Api
134
+ end
135
+ """
136
+ And a file named "spec/getting_started_spec.rb" with:
137
+ """
138
+ require 'spec_helper'
139
+
140
+ RSpec.describe 'Custom Integration of aruba' do
141
+ let(:file) { 'file.txt' }
142
+
143
+ it { expect { write_file file, 'Hello World' }.not_to raise_error }
144
+ it { expect(aruba.current_directory.directory?).to be true }
145
+ end
146
+ """
147
+ When I run `rspec`
148
+ Then the specs should all pass
@@ -51,9 +51,14 @@ Then /^the feature(?:s)? should( not)?(?: all)? pass with:$/ do |negated, string
51
51
  step 'the output should contain:', string if string
52
52
  end
53
53
 
54
- Then /^the spec(?:s)? should( not)?(?: all)? pass$/ do |negated|
54
+ Then /^the spec(?:s)? should( not)?(?: all)? pass(?: with (\d+) failures?)?$/ do |negated, count_failures|
55
55
  if negated
56
- step 'the output should not contain "0 failures"'
56
+ if count_failures.nil?
57
+ step 'the output should not contain "0 failures"'
58
+ else
59
+ step %(the output should contain "#{count_failures} failures")
60
+ end
61
+
57
62
  step 'the exit status should be 1'
58
63
  else
59
64
  step 'the output should contain "0 failures"'
@@ -87,10 +92,6 @@ Given(/^the default feature-test$/) do
87
92
  )
88
93
  end
89
94
 
90
- Before do
91
- aruba.config.exit_timeout = 15
92
- end
93
-
94
95
  Given(/^(?:an|the) executable(?: named)? "([^"]*)" with:$/) do |file_name, file_content|
95
96
  step %(a file named "#{file_name}" with mode "0755" and with:), file_content
96
97
  end
@@ -25,10 +25,7 @@ Feature: Mock the HOME variable
25
25
  Scenario: Run command
26
26
  Given a mocked home directory
27
27
  When I run `cli`
28
- Then the output should contain:
29
- \"\"\"
30
- tmp/aruba
31
- \"\"\"
28
+ Then the output should match %r<HOME:.*tmp/aruba$>
32
29
  """
33
30
  When I run `cucumber`
34
31
  Then the features should all pass
@@ -40,10 +37,26 @@ Feature: Mock the HOME variable
40
37
  @mocked-home-directory
41
38
  Scenario: Run command
42
39
  When I run `cli`
43
- Then the output should contain:
44
- \"\"\"
45
- tmp/aruba
46
- \"\"\"
40
+ Then the output should match %r<HOME:.*tmp/aruba$>
41
+ """
42
+ When I run `cucumber`
43
+ Then the features should all pass
44
+
45
+ Scenario: Redefine home directory by using the aruba configuration
46
+ Given a file named "features/support/home_variable.rb" with:
47
+ """
48
+ require 'aruba/cucumber'
49
+
50
+ Aruba.configure do |config|
51
+ config.home_directory = File.join(config.root_directory, config.working_directory)
52
+ end
53
+ """
54
+ Given a file named "features/home_variable.feature" with:
55
+ """
56
+ Feature: Home Variable
57
+ Scenario: Run command
58
+ When I run `cli`
59
+ Then the output should match %r<HOME:.*tmp/aruba$>
47
60
  """
48
61
  When I run `cucumber`
49
62
  Then the features should all pass
@@ -1,5 +1,6 @@
1
1
  require 'aruba/cucumber'
2
2
 
3
3
  Aruba.configure do |config|
4
- config.exit_timeout = 5
4
+ config.exit_timeout = 120
5
+ config.io_wait_timeout = 2
5
6
  end
@@ -52,7 +52,7 @@ module Aruba
52
52
 
53
53
  private
54
54
 
55
- attr_reader :announcers, :default_announcer, :announcer, :channels, :format_strings
55
+ attr_reader :announcers, :default_announcer, :announcer, :channels, :output_formats
56
56
 
57
57
  public
58
58
 
@@ -65,19 +65,23 @@ module Aruba
65
65
  @default_announcer = @announcers.last
66
66
  @announcer = @announcers.first
67
67
  @channels = {}
68
- @format_strings = {}
68
+ @output_formats = {}
69
69
 
70
70
  @options = options
71
71
 
72
72
  after_init
73
73
  end
74
74
 
75
+ private
76
+
75
77
  # rubocop:disable Metrics/MethodLength
76
78
  def after_init
77
- format_string :directory, '$ cd %s'
78
- format_string :command, '$ %s'
79
- format_string :environment, '$ export %s=%s"'
80
- format_string :timeout, '# %s-timeout: %s seconds'
79
+ output_format :directory, '$ cd %s'
80
+ output_format :command, '$ %s'
81
+ output_format :environment, '$ export %s=%s"'
82
+ output_format :modified_environment, '$ export %s=%s"'
83
+ output_format :full_environment, proc { |h| environment_table(h) }
84
+ output_format :timeout, '# %s-timeout: %s seconds'
81
85
 
82
86
  # rubocop:disable Metrics/LineLength
83
87
  if @options[:stdout]
@@ -97,66 +101,126 @@ module Aruba
97
101
  activate :command
98
102
  end
99
103
  if @options[:env]
100
- warn('The use of "@announce_env-instance" variable and "options[:env] = true" for Announcer.new is deprecated. Please use "announcer.activate(:environment)" instead.')
101
- activate :enviroment
104
+ warn('The use of "@announce_env-instance" variable and "options[:env] = true" for Announcer.new is deprecated. Please use "announcer.activate(:modified_environment)" instead.')
105
+ activate :modified_enviroment
102
106
  end
103
107
  # rubocop:enable Metrics/LineLength
104
108
  end
105
109
  # rubocop:enable Metrics/MethodLength
106
110
 
111
+ def output_format(channel, string = '%s', &block)
112
+ if block_given?
113
+ output_formats[channel.to_sym] = block
114
+ elsif string.is_a?(Proc)
115
+ output_formats[channel.to_sym] = string
116
+ else
117
+ output_formats[channel.to_sym] = proc { |*args| format(string, *args) }
118
+ end
119
+
120
+ self
121
+ end
122
+
123
+ def environment_table(h)
124
+ name_size = h.keys.max_by(&:length).length
125
+ value_size = h.values.max_by(&:length).length
126
+
127
+ result = []
128
+
129
+ h.each do |k,v|
130
+ result << format('%s => %s', k + ' ' * (name_size - k.to_s.size), v + ' ' * (value_size - v.to_s.size))
131
+ end
132
+
133
+ result
134
+ end
135
+
136
+ public
137
+
138
+ # Reset announcer
107
139
  def reset
108
140
  @default_announcer = @announcers.last
109
141
  @announcer = @announcers.first
110
142
  end
111
143
 
112
- def format_string(channel, string)
113
- format_strings[channel] = string
144
+ # Change mode of announcer
145
+ #
146
+ # @param [Symbol] m
147
+ # The mode to set
148
+ def mode=(m)
149
+ @announcer = @announcers.find { |a| f.mode? m.to_sym }
114
150
 
115
151
  self
116
152
  end
117
153
 
118
- def mode=(m)
119
- @announcer = @announcers.find { |a| f.mode? m }
120
-
121
- self
154
+ # Check if channel is activated
155
+ #
156
+ # @param [Symbol] channel
157
+ # The name of the channel to check
158
+ def activated?(channel)
159
+ channels[channel.to_sym] == true
122
160
  end
123
161
 
162
+ # Activate a channel
163
+ #
164
+ # @param [Symbol] channel
165
+ # The name of the channel to activate
124
166
  def activate(channel)
125
- channels[channel] = true
167
+ channels[channel.to_sym] = true
126
168
 
127
169
  self
128
170
  end
129
171
 
172
+ # Announce information to channel
173
+ #
174
+ # @param [Symbol] channel
175
+ # The name of the channel to check
176
+ #
177
+ # @param [Array] args
178
+ # Arguments
130
179
  def announce(channel, *args)
131
- message = format(format_strings.fetch(channel, '%s'), *args)
132
- announcer.announce(message) if @channels[channel]
180
+ channel = channel.to_sym
181
+
182
+ the_output_format = if output_formats.key? channel
183
+ output_formats[channel]
184
+ else
185
+ proc { |v| format('%s', v) }
186
+ end
187
+
188
+ message = the_output_format.call(*args)
189
+
190
+ announcer.announce(message) if channels[channel]
133
191
 
134
192
  default_announcer.announce message
135
193
  end
136
194
 
195
+ # @deprecated
137
196
  def stdout(content)
138
197
  warn('The announcer now has a new api to activate channels. Please use this one: announce(:stdout, message)')
139
198
  announce :stdout, content
140
199
  end
141
200
 
201
+ # @deprecated
142
202
  def stderr(content)
143
203
  warn('The announcer now has a new api to activate channels. Please use this one: announce(:stderr, message)')
144
204
  announce :stderr, content
145
205
  end
146
206
 
207
+ # @deprecated
147
208
  def dir(dir)
148
209
  warn('The announcer now has a new api to activate channels. Please use this one announce(:directory, message)')
149
210
  announce :directory, dir
150
211
  end
151
212
 
213
+ # @deprecated
152
214
  def cmd(cmd)
153
215
  warn('The announcer now has a new api to activate channels. Please use this one announce(:command, message)')
154
216
  announce :command, cmd
155
217
  end
156
218
 
219
+ # @deprecated
157
220
  def env(key, value)
158
- warn('The announcer now has a new api to activate channels. Please use this one: announce(:environment, key, value)')
159
- announce :environment, key, value
221
+ warn('The announcer now has a new api to activate channels. Please use this one: announce(:modified_environment, key, value)')
222
+
223
+ announce :modified_environment, key, value
160
224
  end
161
225
  end
162
226
  end
@@ -1,12 +1,17 @@
1
1
  require 'rspec/expectations'
2
2
  require 'shellwords'
3
3
 
4
+ require 'aruba/version'
4
5
  require 'aruba/extensions/string/strip'
5
6
 
6
7
  require 'aruba/platform'
7
8
  require 'aruba/api/core'
8
9
  require 'aruba/api/command'
9
- require 'aruba/api/deprecated'
10
+
11
+ if Aruba::VERSION <= '1.0.0'
12
+ require 'aruba/api/deprecated'
13
+ end
14
+
10
15
  require 'aruba/api/environment'
11
16
  require 'aruba/api/filesystem'
12
17
  require 'aruba/api/rvm'