aruba 0.9.0 → 0.10.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -0
  3. data/Gemfile +2 -0
  4. data/History.md +23 -1
  5. data/README.md +2 -2
  6. data/aruba.gemspec +1 -1
  7. data/cucumber.yml +4 -0
  8. data/features/api/command/run.feature +18 -0
  9. data/features/api/environment/remove_environment_variable.feature +63 -0
  10. data/features/api/environment/set_environment_variable.feature +47 -10
  11. data/features/api/{command → text}/extract_text.feature +4 -24
  12. data/features/api/text/sanitize_text.feature +228 -0
  13. data/features/api/{command → text}/unescape_text.feature +9 -13
  14. data/features/cli/init.feature +79 -0
  15. data/features/commands/output/all_output.feature +1 -0
  16. data/features/getting_started/supported_testing_frameworks.feature +104 -0
  17. data/features/output.feature +3 -2
  18. data/features/step_definitions/aruba_dev_steps.rb +1 -60
  19. data/features/step_definitions/hooks.rb +6 -0
  20. data/fixtures/empty-app/README.md +1 -11
  21. data/lib/aruba/api.rb +2 -0
  22. data/lib/aruba/api/command.rb +0 -19
  23. data/lib/aruba/api/deprecated.rb +6 -3
  24. data/lib/aruba/api/environment.rb +18 -0
  25. data/lib/aruba/api/filesystem.rb +1 -1
  26. data/lib/aruba/api/text.rb +41 -0
  27. data/lib/aruba/cli.rb +11 -0
  28. data/lib/aruba/console.rb +3 -2
  29. data/lib/aruba/cucumber.rb +1 -0
  30. data/lib/aruba/cucumber/command.rb +44 -88
  31. data/lib/aruba/cucumber/environment.rb +7 -3
  32. data/lib/aruba/cucumber/file.rb +14 -17
  33. data/lib/aruba/cucumber/hooks.rb +1 -0
  34. data/lib/aruba/cucumber/testing_frameworks.rb +95 -0
  35. data/lib/aruba/initializer.rb +185 -0
  36. data/lib/aruba/matchers/collection/all.rb +9 -0
  37. data/lib/aruba/matchers/command/have_output.rb +1 -2
  38. data/lib/aruba/matchers/command/have_output_on_stderr.rb +1 -2
  39. data/lib/aruba/matchers/command/have_output_on_stdout.rb +1 -2
  40. data/lib/aruba/matchers/string.rb +1 -0
  41. data/lib/aruba/matchers/string/include_output_string.rb +36 -0
  42. data/lib/aruba/matchers/string/match_output_string.rb +37 -0
  43. data/lib/aruba/matchers/string/output_string_eq.rb +35 -0
  44. data/lib/aruba/platforms/local_environment.rb +2 -0
  45. data/lib/aruba/platforms/unix_environment_variables.rb +10 -0
  46. data/lib/aruba/platforms/unix_platform.rb +3 -1
  47. data/lib/aruba/platforms/windows_environment_variables.rb +4 -0
  48. data/lib/aruba/processes/spawn_process.rb +6 -2
  49. data/lib/aruba/version.rb +1 -1
  50. metadata +28 -16
  51. data/fixtures/empty-app/bin/cli +0 -6
  52. data/fixtures/empty-app/script/console +0 -14
  53. data/fixtures/empty-app/spec/spec_helper.rb +0 -9
  54. data/lib/aruba/matchers/collection/all_objects.rb +0 -2
@@ -1,11 +1,7 @@
1
- Feature: Extract text from output
1
+ Feature: Unescape special characters in text
2
2
 
3
- If you need to strip down some command output to plain text, you can use the
4
- `#unescape_text`-method for this.
5
-
6
- You may want to have a look
7
- [here](http://www.unixwerk.eu/unix/ansicodes.html) for a good overview for
8
- ANSI escape sequences.
3
+ If have got some text include \n, \t and the like and need them to become
4
+ special characters again, you can use the `#unescape_text`-method for this.
9
5
 
10
6
  Background:
11
7
  Given I use a fixture named "cli-app"
@@ -16,7 +12,7 @@ Feature: Extract text from output
16
12
  #!/bin/bash
17
13
  echo -n 'text\ntext'
18
14
  """
19
- And a file named "spec/which_spec.rb" with:
15
+ And a file named "spec/unescape_text_spec.rb" with:
20
16
  """
21
17
  require 'spec_helper'
22
18
 
@@ -36,7 +32,7 @@ Feature: Extract text from output
36
32
  #!/bin/bash
37
33
  echo -n 'text\etext'
38
34
  """
39
- And a file named "spec/which_spec.rb" with:
35
+ And a file named "spec/unescape_text_spec.rb" with:
40
36
  """
41
37
  require 'spec_helper'
42
38
 
@@ -56,7 +52,7 @@ Feature: Extract text from output
56
52
  #!/bin/bash
57
53
  echo -n 'text\"text'
58
54
  """
59
- And a file named "spec/which_spec.rb" with:
55
+ And a file named "spec/unescape_text_spec.rb" with:
60
56
  """
61
57
  require 'spec_helper'
62
58
 
@@ -76,7 +72,7 @@ Feature: Extract text from output
76
72
  #!/bin/bash
77
73
  echo -n 'text\033text'
78
74
  """
79
- And a file named "spec/which_spec.rb" with:
75
+ And a file named "spec/unescape_text_spec.rb" with:
80
76
  """
81
77
  require 'spec_helper'
82
78
 
@@ -96,7 +92,7 @@ Feature: Extract text from output
96
92
  #!/bin/bash
97
93
  echo -n 'text\017text'
98
94
  """
99
- And a file named "spec/which_spec.rb" with:
95
+ And a file named "spec/unescape_text_spec.rb" with:
100
96
  """
101
97
  require 'spec_helper'
102
98
 
@@ -116,7 +112,7 @@ Feature: Extract text from output
116
112
  #!/bin/bash
117
113
  echo -n 'text\016text'
118
114
  """
119
- And a file named "spec/which_spec.rb" with:
115
+ And a file named "spec/unescape_text_spec.rb" with:
120
116
  """
121
117
  require 'spec_helper'
122
118
 
@@ -0,0 +1,79 @@
1
+ Feature: Initialize project with aruba
2
+
3
+ To add `aruba` to your project you can use the `aruba init`-command.
4
+
5
+ Background:
6
+ Given I use the fixture "empty-app"
7
+
8
+ Scenario: Create files for RSpec
9
+ When I successfully run `aruba init --test-framework rspec`
10
+ Then the following files should exist:
11
+ | spec/spec_helper.rb |
12
+ And the file "spec/support/aruba.rb" should contain:
13
+ """
14
+ require 'aruba/rspec'
15
+ """
16
+ And the file "Gemfile" should contain:
17
+ """
18
+ gem 'aruba'
19
+ """
20
+ When I successfully run `rspec`
21
+ Then the output should contain:
22
+ """
23
+ 0 examples, 0 failures
24
+ """
25
+
26
+ Scenario: Create files for Cucumber
27
+ When I successfully run `aruba init --test-framework cucumber`
28
+ Then the file "features/support/aruba.rb" should contain:
29
+ """
30
+ require 'aruba/cucumber'
31
+ """
32
+ And the file "Gemfile" should contain:
33
+ """
34
+ gem 'aruba'
35
+ """
36
+ When I successfully run `cucumber`
37
+ Then the output should contain:
38
+ """
39
+ 0 scenarios
40
+ 0 steps
41
+ """
42
+
43
+ Scenario: Create files for Cucumber (Default)
44
+ When I successfully run `aruba init`
45
+ Then the file "features/support/aruba.rb" should contain:
46
+ """
47
+ require 'aruba/cucumber'
48
+ """
49
+ And the file "Gemfile" should contain:
50
+ """
51
+ gem 'aruba'
52
+ """
53
+ When I successfully run `cucumber`
54
+ Then the output should contain:
55
+ """
56
+ 0 scenarios
57
+ 0 steps
58
+ """
59
+
60
+ Scenario: Create files for Minitest
61
+ When I successfully run `aruba init --test-framework minitest`
62
+ Then the following files should exist:
63
+ | test/test_helper.rb |
64
+ And the file "Gemfile" should contain:
65
+ """
66
+ gem 'aruba'
67
+ """
68
+ When I successfully run `ruby -Ilib:test test/use_aruba_with_minitest.rb`
69
+ Then the output should contain:
70
+ """
71
+ 0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
72
+ """
73
+
74
+ Scenario: Unknown Test Framework
75
+ When I run `aruba init --test-framework unknown`
76
+ Then the output should contain:
77
+ """
78
+ got unknown
79
+ """
@@ -385,6 +385,7 @@ Feature: All output of commands which were executed
385
385
  When I run `cucumber`
386
386
  Then the features should all pass
387
387
 
388
+ @requires-aruba-version-1
388
389
  Scenario: Detect output from all processes
389
390
  Given an executable named "bin/cli1" with:
390
391
  """bash
@@ -0,0 +1,104 @@
1
+ Feature: Supported Testing Frameworks
2
+
3
+ You can use `aruba` with all major testing frameworks from the Ruby World:
4
+
5
+ \* Cucumber
6
+ \* RSpec
7
+ \* Minitest
8
+
9
+ Background:
10
+ Given I use a fixture named "cli-app"
11
+
12
+ Scenario: Use "aruba" with "Cucumber"
13
+ Given a file named "features/support/env.rb" with:
14
+ """
15
+ require 'aruba/cucumber'
16
+ """
17
+ And a file named "features/use_aruba_with_cucumber.feature" with:
18
+ """
19
+ Feature: Cucumber
20
+ Scenario: First Run
21
+ Given a file named "file.txt" with:
22
+ \"\"\"
23
+ Hello World
24
+ \"\"\"
25
+ Then the file "file.txt" should contain:
26
+ \"\"\"
27
+ Hello World
28
+ \"\"\"
29
+ """
30
+ When I run `cucumber`
31
+ Then the features should all pass
32
+
33
+ Scenario: Use "aruba" with "RSpec"
34
+ Given a file named "spec/support/aruba.rb" with:
35
+ """
36
+ require 'aruba/rspec'
37
+ """
38
+ And a file named "spec/spec_helper.rb" with:
39
+ """
40
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
41
+
42
+ if RUBY_VERSION < '1.9.3'
43
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
44
+ else
45
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
46
+ end
47
+ """
48
+ And a file named "spec/use_aruba_with_rspec_spec.rb" with:
49
+ """
50
+ require 'spec_helper'
51
+
52
+ RSpec.describe 'First Run', :type => :aruba do
53
+ let(:file) { 'file.txt' }
54
+ let(:content) { 'Hello World' }
55
+
56
+ before(:each) { write_file file, content }
57
+
58
+ it { expect(read(file)).to eq [content] }
59
+ end
60
+ """
61
+ When I run `rspec`
62
+ Then the specs should all pass
63
+
64
+
65
+ Scenario: Use "aruba" with "Minitest"
66
+ Given a file named "test/support/aruba.rb" with:
67
+ """
68
+ require 'aruba/api'
69
+ """
70
+ And a file named "test/test_helper.rb" with:
71
+ """
72
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
73
+
74
+ if RUBY_VERSION < '1.9.3'
75
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
76
+ else
77
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
78
+ end
79
+ """
80
+ And a file named "test/use_aruba_with_minitest.rb" with:
81
+ """
82
+ $LOAD_PATH.unshift File.expand_path('../test', __FILE__)
83
+
84
+ require 'test_helper'
85
+ require 'minitest/autorun'
86
+
87
+ class FirstRun < Minitest::Test
88
+ include Aruba::Api
89
+
90
+ def setup
91
+ aruba_setup
92
+ end
93
+
94
+ def getting_started_with_aruba
95
+ file = 'file.txt'
96
+ content = 'Hello World'
97
+
98
+ write_file file, content
99
+ read(file).must_equal [content]
100
+ end
101
+ end
102
+ """
103
+ When I run `ruby -Ilib:test test/use_aruba_with_minitest.rb`
104
+ Then the tests should all pass
@@ -7,6 +7,7 @@ Feature: All output of commands which were executed
7
7
  Background:
8
8
  Given I use a fixture named "cli-app"
9
9
 
10
+ @requires-aruba-version-1
10
11
  Scenario: Detect output from all processes normal and interactive ones
11
12
  Given an executable named "bin/cli1" with:
12
13
  """
@@ -122,9 +123,9 @@ Feature: All output of commands which were executed
122
123
  And the stderr from "printf goodbye" should not contain "hello"
123
124
 
124
125
  Scenario: Detect second output from named source with custom name
125
- When I set env variable "ARUBA_TEST_VAR" to "first"
126
+ When I set the environment variable "ARUBA_TEST_VAR" to "first"
126
127
  And I run `bash -c 'printf $ARUBA_TEST_VAR'`
127
128
  Then the output from "bash -c 'printf $ARUBA_TEST_VAR'" should contain "first"
128
- When I set env variable "ARUBA_TEST_VAR" to "second"
129
+ When I set the environment variable "ARUBA_TEST_VAR" to "second"
129
130
  And I run `bash -c 'printf $ARUBA_TEST_VAR'`
130
131
  Then the output from "bash -c 'printf $ARUBA_TEST_VAR'" should contain "second"
@@ -18,72 +18,13 @@ When /^I set env variable "(\w+)" to "([^"]*)"$/ do |var, value|
18
18
  end
19
19
 
20
20
  Then /^aruba should fail with "([^"]*)"$/ do |error_message|
21
- expect(@aruba_exception.message).to include(extract_text(unescape_text(error_message)))
21
+ expect(@aruba_exception.message).to include sanitize_text(error_message)
22
22
  end
23
23
 
24
24
  Then /^the following step should fail with Spec::Expectations::ExpectationNotMetError:$/ do |multiline_step|
25
25
  expect{steps multiline_step.to_s}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
26
26
  end
27
27
 
28
- Then /^the feature(?:s)? should( not)?(?: all)? pass$/ do |negated|
29
- if negated
30
- step 'the output should contain " failed)"'
31
- step 'the exit status should be 1'
32
- else
33
- step 'the output should not contain " failed)"'
34
- step 'the output should not contain " undefined)"'
35
- step 'the exit status should be 0'
36
- end
37
- end
38
-
39
- Then /^the feature(?:s)? should( not)?(?: all)? pass with( regex)?:$/ do |negated, regex, string|
40
- if negated
41
- step 'the output should contain " failed)"'
42
- step 'the exit status should be 1'
43
- else
44
- step 'the output should not contain " failed)"'
45
- step 'the output should not contain " undefined)"'
46
- step 'the exit status should be 0'
47
- end
48
-
49
- if regex
50
- step "the output should match %r<#{string}>"
51
- else
52
- step 'the output should contain:', string
53
- end
54
- end
55
-
56
- Then /^the spec(?:s)? should( not)?(?: all)? pass(?: with (\d+) failures?)?$/ do |negated, count_failures|
57
- if negated
58
- if count_failures.nil?
59
- step 'the output should not contain "0 failures"'
60
- else
61
- step %(the output should contain "#{count_failures} failures")
62
- end
63
-
64
- step 'the exit status should be 1'
65
- else
66
- step 'the output should contain "0 failures"'
67
- step 'the exit status should be 0'
68
- end
69
- end
70
-
71
- Then /^the spec(?:s)? should( not)?(?: all)? pass with( regex)?:$/ do |negated, regex, string|
72
- if negated
73
- step 'the output should contain " failed)"'
74
- step 'the exit status should be 1'
75
- else
76
- step 'the output should not contain " failed)"'
77
- step 'the exit status should be 0'
78
- end
79
-
80
- if regex
81
- step "the output should match %r<#{string}>"
82
- else
83
- step 'the output should contain:', string
84
- end
85
- end
86
-
87
28
  Given(/^the default executable$/) do
88
29
  step 'an executable named "bin/cli" with:', <<-EOS
89
30
  #!/usr/bin/env ruby
@@ -9,3 +9,9 @@ Before '@requires-ruby-version-193' do
9
9
  skip_this_scenario
10
10
  end
11
11
  end
12
+
13
+ Before '@requires-aruba-version-1' do
14
+ next unless Aruba::VERSION > '1'
15
+
16
+ skip_this_scenario if Cucumber::VERSION >= '2'
17
+ end
@@ -1,4 +1,4 @@
1
- # Simple Cli App
1
+ # Empty Cli App
2
2
 
3
3
  This is a simple test cli app
4
4
 
@@ -22,13 +22,3 @@ Or install it yourself as:
22
22
 
23
23
  Place files in `lib/cli/app/`. They are loaded automatically. If you need a
24
24
  specific load order, use `require` in your files.
25
-
26
- ### CLI
27
-
28
- ```
29
- cli
30
- ```
31
-
32
- ### Library
33
-
34
- You can use `script/console` to load your library.
data/lib/aruba/api.rb CHANGED
@@ -14,6 +14,7 @@ end
14
14
 
15
15
  require 'aruba/api/environment'
16
16
  require 'aruba/api/filesystem'
17
+ require 'aruba/api/text'
17
18
  require 'aruba/api/rvm'
18
19
 
19
20
  Aruba.platform.require_matching_files('../matchers/**/*.rb', __FILE__)
@@ -26,5 +27,6 @@ module Aruba
26
27
  include Aruba::Api::Filesystem
27
28
  include Aruba::Api::Rvm
28
29
  include Aruba::Api::Deprecated
30
+ include Aruba::Api::Text
29
31
  end
30
32
  end
@@ -19,25 +19,6 @@ end
19
19
  module Aruba
20
20
  module Api
21
21
  module Commands
22
- # Unescape text
23
- #
24
- # '\n' => "\n"
25
- # '\e' => "\e"
26
- # '\033' => "\e"
27
- # '\"' => '"'
28
- def unescape_text(text)
29
- text.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e").gsub('\033', "\e").gsub('\016', "\016").gsub('\017', "\017").gsub('\t', "\t")
30
- end
31
-
32
- # Remove ansi characters from text
33
- def extract_text(text)
34
- if Aruba::VERSION < '1'
35
- text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '')
36
- else
37
- text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '').gsub(/\\\[|\\\]/, '').gsub(/\007|\016|\017/, '')
38
- end
39
- end
40
-
41
22
  # Resolve path for command using the PATH-environment variable
42
23
  #
43
24
  # @param [#to_s] program
@@ -133,7 +133,7 @@ module Aruba
133
133
  def mod?(file, perms, &block)
134
134
  Aruba.platform.deprecated('The use of "#mod?" is deprecated. Use "expect().to have_permissions()" instead')
135
135
 
136
- expect(Array(file)).to all_objects have_permissions(perms)
136
+ expect(Array(file)).to Aruba::Matchers.all have_permissions(perms)
137
137
  end
138
138
 
139
139
  # @deprecated
@@ -392,11 +392,13 @@ module Aruba
392
392
  def restore_env
393
393
  # No output because we need to reset env on each scenario/spec run
394
394
  # Aruba.platform.deprecated('The use of "#restore_env" is deprecated. If you use "set_environment_variable" there\'s no need to restore the environment')
395
-
395
+ #
396
396
  original_env.each do |key, value|
397
397
  if value
398
398
  ENV[key] = value
399
+ aruba.environment[key] = value
399
400
  else
401
+ aruba.environment.delete key
400
402
  ENV.delete key
401
403
  end
402
404
  end
@@ -414,6 +416,7 @@ module Aruba
414
416
  Aruba.platform.deprecated('The use of "#set_env" is deprecated. Please use "set_environment_variable" instead. But be careful, this method uses a different kind of implementation')
415
417
 
416
418
  announcer.announce(:environment, key, value)
419
+ set_environment_variable key, value
417
420
  original_env[key] = ENV.delete(key) unless original_env.key? key
418
421
  ENV[key] = value
419
422
  end
@@ -486,7 +489,7 @@ module Aruba
486
489
  # @return
487
490
  # The string stripped from escape sequences
488
491
  def unescape(string, keep_ansi = false)
489
- Aruba.platform.deprecated('The use of "#unescape" is deprecated. Please use "#unescape_text" and "#extract_text" intead')
492
+ Aruba.platform.deprecated('The use of "#unescape" is deprecated. Please use "#sanitize_text" intead')
490
493
 
491
494
  string = unescape_text(string)
492
495
  string = extract_text(string) if !keep_ansi || !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences