aruba 0.9.0 → 0.10.0.pre

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 (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
@@ -29,14 +29,11 @@ Given(/^(?:an|the) executable(?: named)? "([^"]*)" with:$/) do |file_name, file_
29
29
  end
30
30
 
31
31
  Given(/^(?:a|the) file(?: named)? "([^"]*)" with "([^"]*)"$/) do |file_name, file_content|
32
- file_content = unescape_text(file_content)
33
- file_content = extract_text(file_content) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
34
-
35
- write_file(file_name, file_content)
32
+ write_file(file_name, unescape_text(file_content))
36
33
  end
37
34
 
38
35
  Given(/^(?:a|the) file(?: named)? "([^"]*)" with mode "([^"]*)" and with:$/) do |file_name, file_mode, file_content|
39
- write_file(file_name, file_content)
36
+ write_file(file_name, unescape_text(file_content))
40
37
  chmod(file_mode, file_name)
41
38
  end
42
39
 
@@ -95,7 +92,7 @@ Then(/^the following files should (not )?exist:$/) do |negated, files|
95
92
  if negated
96
93
  expect(files).not_to include an_existing_file
97
94
  else
98
- expect(files).to all_objects be_an_existing_file
95
+ expect(files).to Aruba::Matchers.all be_an_existing_file
99
96
  end
100
97
  end
101
98
 
@@ -109,9 +106,9 @@ end
109
106
 
110
107
  Then(/^(?:a|the) file matching %r<(.*?)> should (not )?exist$/) do |pattern, expect_match|
111
108
  if expect_match
112
- expect(all_paths).not_to include match Regexp.new(pattern)
109
+ expect(all_paths).not_to include a_file_name_matching(pattern)
113
110
  else
114
- expect(all_paths).to include match Regexp.new(pattern)
111
+ expect(all_paths).to include match a_file_name_matching(pattern)
115
112
  end
116
113
  end
117
114
 
@@ -129,7 +126,7 @@ Then(/^the following directories should (not )?exist:$/) do |negated, directorie
129
126
  if negated
130
127
  expect(directories).not_to include an_existing_directory
131
128
  else
132
- expect(directories).to all_objects be_an_existing_directory
129
+ expect(directories).to Aruba::Matchers.all be_an_existing_directory
133
130
  end
134
131
  end
135
132
 
@@ -143,17 +140,17 @@ end
143
140
 
144
141
  Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain "([^"]*)"$/) do |file, negated, content|
145
142
  if negated
146
- expect(file).not_to have_file_content Regexp.new(Regexp.escape(content.chomp))
143
+ expect(file).not_to have_file_content file_content_including(content.chomp)
147
144
  else
148
- expect(file).to have_file_content Regexp.new(Regexp.escape(content.chomp))
145
+ expect(file).to have_file_content file_content_including(content.chomp)
149
146
  end
150
147
  end
151
148
 
152
149
  Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?contain:$/) do |file, negated, content|
153
150
  if negated
154
- expect(file).not_to have_file_content Regexp.new(Regexp.escape(content.chomp))
151
+ expect(file).not_to have_file_content file_content_including(content.chomp)
155
152
  else
156
- expect(file).to have_file_content Regexp.new(Regexp.escape(content.chomp))
153
+ expect(file).to have_file_content file_content_including(content.chomp)
157
154
  end
158
155
  end
159
156
 
@@ -167,17 +164,17 @@ end
167
164
 
168
165
  Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?match %r<([^\/]*)>$/) do |file, negated, content|
169
166
  if negated
170
- expect(file).not_to have_file_content Regexp.new(content)
167
+ expect(file).not_to have_file_content file_content_matching(content)
171
168
  else
172
- expect(file).to have_file_content Regexp.new(content)
169
+ expect(file).to have_file_content file_content_matching(content)
173
170
  end
174
171
  end
175
172
 
176
173
  Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?match \/([^\/]*)\/$/) do |file, negated, content|
177
174
  if negated
178
- expect(file).not_to have_file_content Regexp.new(content)
175
+ expect(file).not_to have_file_content file_content_matching(content)
179
176
  else
180
- expect(file).to have_file_content Regexp.new(content)
177
+ expect(file).to have_file_content file_content_matching(content)
181
178
  end
182
179
  end
183
180
 
@@ -118,6 +118,7 @@ end
118
118
 
119
119
  Before('@keep-ansi-escape-sequences') do
120
120
  aruba.config.remove_ansi_escape_sequences = false
121
+ aruba.config.keep_ansi = true
121
122
  end
122
123
 
123
124
  Before '@mocked_home_directory' do
@@ -0,0 +1,95 @@
1
+ # Cucumber
2
+ Then /^the feature(?:s)? should( not)?(?: all)? pass$/ do |negated|
3
+ if negated
4
+ step 'the output should contain " failed)"'
5
+ step 'the exit status should be 1'
6
+ else
7
+ step 'the output should not contain " failed)"'
8
+ step 'the output should not contain " undefined)"'
9
+ step 'the exit status should be 0'
10
+ end
11
+ end
12
+
13
+ # Cucumber
14
+ Then /^the feature(?:s)? should( not)?(?: all)? pass with( regex)?:$/ do |negated, regex, string|
15
+ if negated
16
+ step 'the output should contain " failed)"'
17
+ step 'the exit status should be 1'
18
+ else
19
+ step 'the output should not contain " failed)"'
20
+ step 'the output should not contain " undefined)"'
21
+ step 'the exit status should be 0'
22
+ end
23
+
24
+ if regex
25
+ step "the output should match %r<#{string}>"
26
+ else
27
+ step 'the output should contain:', string
28
+ end
29
+ end
30
+
31
+ # RSpec
32
+ Then /^the spec(?:s)? should( not)?(?: all)? pass(?: with (\d+) failures?)?$/ do |negated, count_failures|
33
+ if negated
34
+ if count_failures.nil?
35
+ step 'the output should not contain "0 failures"'
36
+ else
37
+ step %(the output should contain "#{count_failures} failures")
38
+ end
39
+
40
+ step 'the exit status should be 1'
41
+ else
42
+ step 'the output should contain "0 failures"'
43
+ step 'the exit status should be 0'
44
+ end
45
+ end
46
+
47
+ # RSpec
48
+ Then /^the spec(?:s)? should( not)?(?: all)? pass with( regex)?:$/ do |negated, regex, string|
49
+ if negated
50
+ step 'the output should contain " failed)"'
51
+ step 'the exit status should be 1'
52
+ else
53
+ step 'the output should not contain " failed)"'
54
+ step 'the exit status should be 0'
55
+ end
56
+
57
+ if regex
58
+ step "the output should match %r<#{string}>"
59
+ else
60
+ step 'the output should contain:', string
61
+ end
62
+ end
63
+
64
+ # Minitest
65
+ Then /^the tests(?:s)? should( not)?(?: all)? pass(?: with (\d+) failures?)?$/ do |negated, count_failures|
66
+ if negated
67
+ if count_failures.nil?
68
+ step 'the output should not contain "0 errors"'
69
+ else
70
+ step %(the output should contain "#{count_failures} errors")
71
+ end
72
+
73
+ step 'the exit status should be 1'
74
+ else
75
+ step 'the output should contain "0 errors"'
76
+ step 'the exit status should be 0'
77
+ end
78
+ end
79
+
80
+ # Minitest
81
+ Then /^the test(?:s)? should( not)?(?: all)? pass with( regex)?:$/ do |negated, regex, string|
82
+ if negated
83
+ step 'the output should contain "0 errors"'
84
+ step 'the exit status should be 1'
85
+ else
86
+ step 'the output should not contain "0 errors"'
87
+ step 'the exit status should be 0'
88
+ end
89
+
90
+ if regex
91
+ step "the output should match %r<#{string}>"
92
+ else
93
+ step 'the output should contain:', string
94
+ end
95
+ end
@@ -0,0 +1,185 @@
1
+ require 'thor/group'
2
+ require 'thor/actions'
3
+
4
+ module Aruba
5
+ module Initializers
6
+ class CommonInitializer < Thor::Group
7
+ include Thor::Actions
8
+
9
+ def add_gem
10
+ file = 'Gemfile'
11
+ creator = if File.exist? file
12
+ :append_to_file
13
+ else
14
+ :create_file
15
+ end
16
+
17
+ content = if File.exist? file
18
+ %(gem 'aruba', '~> #{Aruba::VERSION}')
19
+ else
20
+ %(source 'https://rubygems.org'\ngem 'aruba', '~> #{Aruba::VERSION}'\n)
21
+ end
22
+ send creator, file, content
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ module Aruba
29
+ module Initializers
30
+ class FailingInitializer
31
+ class << self
32
+ def match?(*)
33
+ true
34
+ end
35
+
36
+ def start(*)
37
+ fail ArgumentError, %(Unknown test framework. Please use one of :rspec, :cucumber or :minitest)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ module Aruba
45
+ module Initializers
46
+ class RSpecInitializer < Thor::Group
47
+ include Thor::Actions
48
+
49
+ no_commands do
50
+ def self.match?(framework)
51
+ :rspec == framework.downcase.to_sym
52
+ end
53
+ end
54
+
55
+ def create_helper
56
+ file = 'spec/spec_helper.rb'
57
+ creator = if File.exist? file
58
+ :append_to_file
59
+ else
60
+ :create_file
61
+ end
62
+
63
+ send creator, file, <<-EOS
64
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
65
+
66
+ if RUBY_VERSION < '1.9.3'
67
+ ::Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
68
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
69
+ else
70
+ ::Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
71
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
72
+ end
73
+ EOS
74
+ end
75
+
76
+ def create_support_file
77
+ create_file 'spec/support/aruba.rb', <<-EOS
78
+ require 'aruba/rspec'
79
+ EOS
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ module Aruba
86
+ module Initializers
87
+ class CucumberInitializer < Thor::Group
88
+ include Thor::Actions
89
+
90
+ no_commands do
91
+ def self.match?(framework)
92
+ :cucumber == framework.downcase.to_sym
93
+ end
94
+ end
95
+
96
+ def create_support_file
97
+ create_file 'features/support/aruba.rb', <<-EOS
98
+ require 'aruba/cucumber'
99
+ EOS
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ module Aruba
106
+ module Initializers
107
+ class MiniTestInitializer < Thor::Group
108
+ include Thor::Actions
109
+
110
+ no_commands do
111
+ def self.match?(framework)
112
+ :minitest == framework.downcase.to_sym
113
+ end
114
+ end
115
+
116
+ def create_helper
117
+ file = 'test/test_helper.rb'
118
+ creator = if File.exist? file
119
+ :append_to_file
120
+ else
121
+ :create_file
122
+ end
123
+
124
+ send creator, file, <<-EOS
125
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
126
+
127
+ if RUBY_VERSION < '1.9.3'
128
+ ::Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
129
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
130
+ else
131
+ ::Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
132
+ ::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
133
+ end
134
+ EOS
135
+ end
136
+
137
+ def create_example
138
+ create_file 'test/use_aruba_with_minitest.rb', <<-EOS
139
+ $LOAD_PATH.unshift File.expand_path('../test', __FILE__)
140
+
141
+ require 'test_helper'
142
+ require 'minitest/autorun'
143
+ require 'aruba/api'
144
+
145
+ class FirstRun < Minitest::Test
146
+ include Aruba::Api
147
+
148
+ def setup
149
+ aruba_setup
150
+ end
151
+ end
152
+ EOS
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ module Aruba
159
+ class Initializer
160
+ private
161
+
162
+ attr_reader :initializers
163
+
164
+ public
165
+
166
+ def initialize
167
+ @initializers = []
168
+ @initializers << Initializers::RSpecInitializer
169
+ @initializers << Initializers::CucumberInitializer
170
+ @initializers << Initializers::MiniTestInitializer
171
+ @initializers << Initializers::FailingInitializer
172
+ end
173
+
174
+ def call(test_framework)
175
+ begin
176
+ initializers.find { |i| i.match? test_framework }.start [], {}
177
+ rescue ArgumentError => e
178
+ $stderr.puts e.message
179
+ exit 0
180
+ end
181
+
182
+ Initializers::CommonInitializer.start [], {}
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec/expectations'
2
+
3
+ module Aruba
4
+ module Matchers
5
+ include ::RSpec::Matchers
6
+
7
+ module_function :all
8
+ end
9
+ end
@@ -30,8 +30,7 @@ RSpec::Matchers.define :have_output do |expected|
30
30
 
31
31
  @old_actual.stop(@announcer) unless @old_actual.stopped?
32
32
 
33
- @actual = unescape_text(actual.output.chomp)
34
- @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
33
+ @actual = sanitize_text(actual.output)
35
34
 
36
35
  values_match?(expected, @actual)
37
36
  end
@@ -30,8 +30,7 @@ RSpec::Matchers.define :have_output_on_stderr do |expected|
30
30
 
31
31
  @old_actual.stop(@announcer) unless @old_actual.stopped?
32
32
 
33
- @actual = unescape_text(actual.stderr.chomp)
34
- @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
33
+ @actual = sanitize_text(actual.stderr)
35
34
 
36
35
  values_match?(expected, @actual)
37
36
  end
@@ -30,8 +30,7 @@ RSpec::Matchers.define :have_output_on_stdout do |expected|
30
30
 
31
31
  @old_actual.stop(@announcer) unless @old_actual.stopped?
32
32
 
33
- @actual = unescape_text(actual.stdout.chomp)
34
- @actual = extract_text(@actual) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
33
+ @actual = sanitize_text(actual.stdout)
35
34
 
36
35
  values_match?(expected, @actual)
37
36
  end
@@ -0,0 +1 @@
1
+ Aruba.platform.require_matching_files('../string/**/*.rb', __FILE__)
@@ -0,0 +1,36 @@
1
+ # @!method include_output_string(string)
2
+ # This matchers checks if the output string of a command includes string.
3
+ #
4
+ # @param [Integer] status
5
+ # The value of the exit status
6
+ #
7
+ # @return [TrueClass, FalseClass] The result
8
+ #
9
+ # false:
10
+ # * if the output string does not include string
11
+ # true:
12
+ # * if the output string includes string
13
+ #
14
+ # @example Use matcher
15
+ #
16
+ # RSpec.describe do
17
+ # it { expect(last_command_started).to have_output an_output_string_including string) }
18
+ # it { expect(last_command_started).to have_output include_output_string string) }
19
+ # end
20
+ RSpec::Matchers.define :include_output_string do |expected|
21
+ match do |actual|
22
+ @expected = Regexp.new(Regexp.escape(sanitize_text(expected.to_s)), Regexp::MULTILINE)
23
+ @actual = sanitize_text(actual)
24
+
25
+ values_match? @expected, @actual
26
+ end
27
+
28
+ diffable
29
+
30
+ description { "string includes: #{description_of expected}" }
31
+ end
32
+
33
+ if RSpec::Expectations::Version::STRING >= '3.0'
34
+ RSpec::Matchers.alias_matcher :an_output_string_including, :include_output_string
35
+ RSpec::Matchers.alias_matcher :file_content_including, :include_output_string
36
+ end