aruba 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +167 -3
  4. data/.simplecov +32 -0
  5. data/.travis.yml +5 -2
  6. data/.yardopts +8 -0
  7. data/CONTRIBUTING.md +18 -8
  8. data/Gemfile +25 -0
  9. data/History.md +8 -0
  10. data/README.md +80 -18
  11. data/Rakefile +1 -1
  12. data/aruba.gemspec +6 -8
  13. data/cucumber.yml +5 -6
  14. data/features/debug.feature +15 -0
  15. data/features/file_system_commands.feature +14 -2
  16. data/features/fixtures/copy/file.txt +1 -0
  17. data/features/fixtures/fixtures-app/test.txt +1 -0
  18. data/features/fixtures/spawn_process/stderr.sh +3 -0
  19. data/features/interactive.feature +2 -2
  20. data/features/step_definitions/aruba_dev_steps.rb +1 -1
  21. data/features/support/custom_main.rb +10 -6
  22. data/features/support/env.rb +27 -2
  23. data/features/support/simplecov_setup.rb +8 -0
  24. data/lib/aruba.rb +2 -2
  25. data/lib/aruba/announcer.rb +161 -0
  26. data/lib/aruba/api.rb +490 -251
  27. data/lib/aruba/config.rb +0 -1
  28. data/lib/aruba/cucumber.rb +71 -59
  29. data/lib/aruba/cucumber/hooks.rb +18 -13
  30. data/lib/aruba/errors.rb +6 -0
  31. data/lib/aruba/in_process.rb +5 -45
  32. data/lib/aruba/matchers/command.rb +79 -0
  33. data/lib/aruba/matchers/directory.rb +59 -0
  34. data/lib/aruba/matchers/file.rb +177 -0
  35. data/lib/aruba/matchers/mode.rb +52 -0
  36. data/lib/aruba/matchers/path.rb +99 -0
  37. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +21 -1
  38. data/lib/aruba/process_monitor.rb +113 -0
  39. data/lib/aruba/processes/basic_process.rb +25 -0
  40. data/lib/aruba/processes/debug_process.rb +59 -0
  41. data/lib/aruba/processes/in_process.rb +86 -0
  42. data/lib/aruba/processes/spawn_process.rb +159 -0
  43. data/lib/aruba/reporting.rb +2 -2
  44. data/lib/aruba/rspec.rb +26 -0
  45. data/lib/aruba/spawn_process.rb +5 -104
  46. data/lib/aruba/utils.rb +21 -0
  47. data/script/bootstrap +22 -0
  48. data/script/console +17 -0
  49. data/script/test +3 -0
  50. data/spec/aruba/api_spec.rb +813 -147
  51. data/spec/aruba/hooks_spec.rb +0 -1
  52. data/spec/aruba/matchers/command_spec.rb +43 -0
  53. data/spec/aruba/matchers/directory_spec.rb +58 -0
  54. data/spec/aruba/matchers/file_spec.rb +131 -0
  55. data/spec/aruba/matchers/path_spec.rb +85 -0
  56. data/spec/aruba/spawn_process_spec.rb +46 -28
  57. data/spec/spec_helper.rb +18 -13
  58. data/{config/rubocop/include.yml → spec/support/configs/.keep} +0 -0
  59. data/spec/support/configs/rspec.rb +15 -0
  60. data/spec/support/helpers/.keep +0 -0
  61. data/spec/support/helpers/reporting.rb +44 -0
  62. data/spec/support/matchers/.keep +0 -0
  63. data/spec/support/shared_contexts/.keep +0 -0
  64. data/spec/support/shared_contexts/aruba.rb +45 -0
  65. data/spec/support/shared_examples/.keep +0 -0
  66. data/spec/support/shared_examples/directory.rb +7 -0
  67. data/spec/support/shared_examples/file.rb +7 -0
  68. data/templates/js/jquery-1.11.3.min.js +5 -0
  69. data/templates/main.erb +1 -1
  70. metadata +87 -96
  71. data/config/rubocop/exclude.yml +0 -160
  72. data/templates/js/jquery-1.6.1.min.js +0 -18
@@ -0,0 +1,59 @@
1
+
2
+ RSpec::Matchers.define :be_existing_directory do |_|
3
+ match do |actual|
4
+ directory?(actual)
5
+ end
6
+
7
+ failure_message do |actual|
8
+ format("expected that directory \"%s\" exists", actual)
9
+ end
10
+
11
+ failure_message_when_negated do |actual|
12
+ format("expected that directory \"%s\" does not exist", actual)
13
+ end
14
+ end
15
+
16
+ # @!method have_sub_directory(sub_directory)
17
+ # This matchers checks if <directory> has given sub-directory
18
+ #
19
+ # @param [Array] sub_directory
20
+ # A list of sub-directory relative to current directory
21
+ #
22
+ # @return [TrueClass, FalseClass] The result
23
+ #
24
+ # false:
25
+ # * if directory does not have sub-directory
26
+ # true:
27
+ # * if directory has sub-directory
28
+ #
29
+ # @example Use matcher with single directory
30
+ #
31
+ # RSpec.describe do
32
+ # it { expect('dir1.d').to have_sub_directory('subdir.1.d') }
33
+ # end
34
+ #
35
+ # @example Use matcher with multiple directories
36
+ #
37
+ # RSpec.describe do
38
+ # it { expect('dir1.d').to have_sub_directory(['subdir.1.d', 'subdir.2.d']) }
39
+ # end
40
+ RSpec::Matchers.define :have_sub_directory do |expected|
41
+ match do |actual|
42
+ next false unless directory?(actual)
43
+
44
+ expected_files = Array(expected).map { |p| File.join(actual, p) }
45
+ existing_files = list(actual)
46
+
47
+ (expected_files - existing_files).empty?
48
+ end
49
+
50
+ diffable
51
+
52
+ failure_message do |actual|
53
+ format("expected that directory \"%s\" has the following sub-directories: %s.", actual, Array(expected).join(', '))
54
+ end
55
+
56
+ failure_message_when_negated do |actual|
57
+ format("expected that directory \"%s\" does not have the following sub-directories: %s.", actual, Array(expected).join(', '))
58
+ end
59
+ end
@@ -0,0 +1,177 @@
1
+ # @!method have_same_file_content_like(file_name)
2
+ # This matchers checks if <file1> has the same content like <file2>
3
+ #
4
+ # @param [String] file_name
5
+ # The name of the file which should be compared with the file in the
6
+ # `expect()`-call.
7
+ #
8
+ # @return [TrueClass, FalseClass] The result
9
+ #
10
+ # false:
11
+ # * if file1 is not equal file2
12
+ # true:
13
+ # * if file1 is equal file2
14
+ #
15
+ # @example Use matcher
16
+ #
17
+ # RSpec.describe do
18
+ # it { expect(file1).to have_same_file_content_like(file2) }
19
+ # end
20
+ RSpec::Matchers.define :have_same_file_content_like do |expected|
21
+ match do |actual|
22
+ FileUtils.compare_file(
23
+ expand_path(actual),
24
+ expand_path(expected)
25
+ )
26
+ end
27
+
28
+ failure_message do |actual|
29
+ format("expected that file \"%s\" is the same as file \"%s\".", actual, expected)
30
+ end
31
+
32
+ failure_message_when_negated do |actual|
33
+ format("expected that file \"%s\" differs from file \"%s\".", actual, expected)
34
+ end
35
+ end
36
+
37
+ # @!method be_existing_file
38
+ # This matchers checks if <file> exists in filesystem
39
+ #
40
+ # @return [TrueClass, FalseClass] The result
41
+ #
42
+ # false:
43
+ # * if file does not exist
44
+ # true:
45
+ # * if file exists
46
+ #
47
+ # @example Use matcher
48
+ #
49
+ # RSpec.describe do
50
+ # it { expect(file1).to be_existing_file }
51
+ # end
52
+ RSpec::Matchers.define :be_existing_file do |_|
53
+ match do |actual|
54
+ next false unless actual.is_a? String
55
+
56
+ file?(actual)
57
+ end
58
+
59
+ failure_message do |actual|
60
+ format("expected that file \"%s\" exists", actual)
61
+ end
62
+
63
+ failure_message_when_negated do |actual|
64
+ format("expected that file \"%s\" does not exist", actual)
65
+ end
66
+ end
67
+
68
+ # @!method be_existing_files
69
+ # This matchers checks if <files> exists in filessystem
70
+ #
71
+ # @return [TrueClass, FalseClass] The result
72
+ #
73
+ # false:
74
+ # * if files does not exist
75
+ # true:
76
+ # * if files exists
77
+ #
78
+ # @example Use matcher
79
+ #
80
+ # RSpec.describe do
81
+ # it { expect(%w(file1 file2)).to be_existing_files }
82
+ # end
83
+ RSpec::Matchers.define :be_existing_files do |_|
84
+ match do |actual|
85
+ next false unless actual.is_a? Array
86
+
87
+ actual.all? { |f| file?(f) }
88
+ end
89
+
90
+ failure_message do |actual|
91
+ format("expected that files \"%s\" exists", actual.join(', '))
92
+ end
93
+
94
+ failure_message_when_negated do |actual|
95
+ format("expected that files \"%s\" does not exist", actual.join(', '))
96
+ end
97
+ end
98
+
99
+ # @!method have_file_content(content)
100
+ # This matchers checks if <file> has content. `content` can be a string,
101
+ # regexp or an RSpec matcher.
102
+ #
103
+ # @param [String, Regexp, Matcher] content
104
+ # Specifies the content of the file
105
+ #
106
+ # @return [TrueClass, FalseClass] The result
107
+ #
108
+ # false:
109
+ # * if file does not exist
110
+ # * if file content is not equal string
111
+ # * if file content does not include regexp
112
+ # * if file content does not match the content specification
113
+ #
114
+ # true:
115
+ # * if file content includes regexp
116
+ # * if file content is equal string
117
+ # * if file content matches the content specification
118
+ #
119
+ # @example Use matcher with string
120
+ #
121
+ # RSpec.describe do
122
+ # it { expect(file1).to have_file_content('a') }
123
+ # end
124
+ #
125
+ # @example Use matcher with regexp
126
+ #
127
+ # RSpec.describe do
128
+ # it { expect(file1).to have_file_content(/a/) }
129
+ # end
130
+ #
131
+ # @example Use matcher with an RSpec matcher
132
+ #
133
+ # RSpec.describe do
134
+ # it { expect(file1).to have_file_content(a_string_starting_with 'a') }
135
+ # end
136
+ RSpec::Matchers.define :have_file_content do |expected|
137
+ match do |actual|
138
+ next false unless file? actual
139
+
140
+ values_match?(expected, File.read(expand_path(actual)).chomp)
141
+ end
142
+
143
+ description { "have file content: #{description_of expected}" }
144
+ end
145
+
146
+ # @!method have_file_size(size)
147
+ # This matchers checks if path has file size
148
+ #
149
+ # @param [Fixnum] size
150
+ # The size to check
151
+ #
152
+ # @return [TrueClass, FalseClass] The result
153
+ #
154
+ # false:
155
+ # * if path does not have size
156
+ # true:
157
+ # * if path has size
158
+ #
159
+ # @example Use matcher
160
+ #
161
+ # RSpec.describe do
162
+ # it { expect('file.txt').to have_file_size(0) }
163
+ # end
164
+ RSpec::Matchers.define :have_file_size do |expected|
165
+ match do |actual|
166
+ next false unless File.file? expand_path(actual)
167
+ File.size(expand_path(actual)) == expected
168
+ end
169
+
170
+ failure_message do |actual|
171
+ format("expected that file \"%s\" has size \"%s\", but has \"%s\"", actual, File.size(expand_path(actual)), expected)
172
+ end
173
+
174
+ failure_message_when_negated do |actual|
175
+ format("expected that file \"%s\" does not have size \"%s\", but has \"%s\"", actual, File.size(expand_path(actual)), expected)
176
+ end
177
+ end
@@ -0,0 +1,52 @@
1
+ # @!method have_permissions(permissions)
2
+ # This matchers checks if <file> has <perm> permissions
3
+ #
4
+ # @param [Fixnum, String] permissions
5
+ # The permissions as octal number, e.g. `0700`, or String, e.g. `'0700'`
6
+ #
7
+ # @return [TrueClass, FalseClass] The result
8
+ #
9
+ # false:
10
+ # * if file has permissions
11
+ # true:
12
+ # * if file does not have permissions
13
+ #
14
+ # @example Use matcher with octal number
15
+ #
16
+ # RSpec.describe do
17
+ # it { expect(file).to have_permissions(0700) }
18
+ # end
19
+ #
20
+ # @example Use matcher with string
21
+ #
22
+ # RSpec.describe do
23
+ # it { expect(file).to have_permissions('0700') }
24
+ # end
25
+ RSpec::Matchers.define :have_permissions do |expected|
26
+ expected_permissions = if expected.kind_of? Integer
27
+ expected.to_s(8)
28
+ else
29
+ expected.gsub(/^0*/, '')
30
+ end
31
+
32
+ match do |actual|
33
+ file_name = actual
34
+ actual_permissions = format( "%o", File::Stat.new(expand_path(file_name)).mode )[-4,4].gsub(/^0*/, '')
35
+
36
+ actual_permissions == expected_permissions
37
+ end
38
+
39
+ failure_message do |actual|
40
+ file_name = actual
41
+ actual_permissions = format( "%o", File::Stat.new(expand_path(file_name)).mode )[-4,4].gsub(/^0*/, '')
42
+
43
+ format("expected that file \"%s\" would have permissions \"%s\", but has \"%s\".", file_name, expected_permissions, actual_permissions)
44
+ end
45
+
46
+ failure_message_when_negated do |actual|
47
+ file_name = actual
48
+ actual_permissions = format( "%o", File::Stat.new(expand_path(file_name)).mode )[-4,4].gsub(/^0*/, '')
49
+
50
+ format("expected that file \"%s\" would not have permissions \"%s\", but has \"%s\".", file_name, expected_permissions, actual_permissions)
51
+ end
52
+ end
@@ -0,0 +1,99 @@
1
+ # @!method match_path_pattern(pattern)
2
+ # This matchers checks if <files>/directories match <pattern>
3
+ #
4
+ # @param [String, Regexp] pattern
5
+ # The pattern to use.
6
+ #
7
+ # @return [TrueClass, FalseClass] The result
8
+ #
9
+ # false:
10
+ # * if there are no files/directories which match the pattern
11
+ # true:
12
+ # * if there are files/directories which match the pattern
13
+ #
14
+ # @example Use matcher with regex
15
+ #
16
+ # RSpec.describe do
17
+ # it { expect(Dir.glob(**/*)).to match_file_pattern(/.txt$/) }
18
+ # end
19
+ #
20
+ # @example Use matcher with string
21
+ #
22
+ # RSpec.describe do
23
+ # it { expect(Dir.glob(**/*)).to match_file_pattern('.txt$') }
24
+ # end
25
+ RSpec::Matchers.define :match_path_pattern do |_|
26
+ match do |actual|
27
+ next !actual.select { |a| a == expected }.empty? if expected.is_a? String
28
+
29
+ !actual.grep(expected).empty?
30
+ end
31
+
32
+ failure_message do |actual|
33
+ format("expected that path \"%s\" matches pattern \"%s\".", actual.join(", "), expected)
34
+ end
35
+
36
+ failure_message_when_negated do |actual|
37
+ format("expected that path \"%s\" does not match pattern \"%s\".", actual.join(", "), expected)
38
+ end
39
+ end
40
+
41
+ # @!method be_existing_path
42
+ # This matchers checks if <path> exists in filesystem
43
+ #
44
+ # @return [TrueClass, FalseClass] The result
45
+ #
46
+ # false:
47
+ # * if path does not exist
48
+ # true:
49
+ # * if path exists
50
+ #
51
+ # @example Use matcher
52
+ #
53
+ # RSpec.describe do
54
+ # it { expect(file).to be_existing_path }
55
+ # it { expect(directory).to be_existing_path }
56
+ # end
57
+ RSpec::Matchers.define :be_existing_path do |_|
58
+ match do |actual|
59
+ exist?(actual)
60
+ end
61
+
62
+ failure_message do |actual|
63
+ format("expected that path \"%s\" exists", actual)
64
+ end
65
+
66
+ failure_message_when_negated do |actual|
67
+ format("expected that path \"%s\" does not exist", actual)
68
+ end
69
+ end
70
+
71
+ # @!method be_absolute_path
72
+ # This matchers checks if <path> exists in filesystem
73
+ #
74
+ # @return [TrueClass, FalseClass] The result
75
+ #
76
+ # false:
77
+ # * if path is not absolute
78
+ # true:
79
+ # * if path is absolute
80
+ #
81
+ # @example Use matcher
82
+ #
83
+ # RSpec.describe do
84
+ # it { expect(file).to be_absolute_path }
85
+ # it { expect(directory).to be_absolute_path }
86
+ # end
87
+ RSpec::Matchers.define :be_absolute_path do |_|
88
+ match do |actual|
89
+ absolute?(actual)
90
+ end
91
+
92
+ failure_message do |actual|
93
+ format("expected that path \"%s\" is absolute, but it's not", actual)
94
+ end
95
+
96
+ failure_message_when_negated do |actual|
97
+ format("expected that path \"%s\" is not absolute, but it is", actual)
98
+ end
99
+ end
@@ -1,5 +1,25 @@
1
+ # @!method include_regexp(regexp)
2
+ # This matchers checks if items of an <array> matches regexp
3
+ #
4
+ # @param [Regexp] regexp
5
+ # The regular expression to use
6
+ #
7
+ # @return [TrueClass, FalseClass] The result
8
+ #
9
+ # false:
10
+ # * if regexp does not match
11
+ # true:
12
+ # * if regexp matches
13
+ #
14
+ # @example Use matcher
15
+ #
16
+ # RSpec.describe do
17
+ # it { expect(%w(asdf qwert)).to include_regexp(/asdf/) }
18
+ # end
1
19
  RSpec::Matchers.define :include_regexp do |expected|
2
20
  match do |actual|
3
- ! actual.grep(expected).empty?
21
+ warn('The use of "include_regexp"-matchers is deprecated. It will be removed soon.')
22
+
23
+ !actual.grep(expected).empty?
4
24
  end
5
25
  end
@@ -0,0 +1,113 @@
1
+ module Aruba
2
+ class ProcessMonitor
3
+ private
4
+
5
+ attr_reader :processes, :announcer
6
+
7
+ public
8
+
9
+ def initialize(announcer)
10
+ @processes = []
11
+ @announcer = announcer
12
+ end
13
+
14
+ def last_exit_status
15
+ return @last_exit_status if @last_exit_status
16
+ stop_processes!
17
+ @last_exit_status
18
+ end
19
+
20
+ def stop_process(process)
21
+ @last_exit_status = process.stop(announcer)
22
+ end
23
+
24
+ def terminate_process!(process)
25
+ process.terminate
26
+ end
27
+
28
+ def stop_processes!
29
+ processes.each do |_, process|
30
+ stop_process(process)
31
+ end
32
+ end
33
+
34
+ # Terminate all running processes
35
+ def terminate_processes
36
+ processes.each do |_, process|
37
+ terminate_process(process)
38
+ stop_process(process)
39
+ end
40
+ end
41
+
42
+ def register_process(name, process)
43
+ processes << [name, process]
44
+ end
45
+
46
+ def get_process(wanted)
47
+ matching_processes = processes.reverse.find{ |name, _| name == wanted }
48
+ raise ArgumentError.new("No process named '#{wanted}' has been started") unless matching_processes
49
+ matching_processes.last
50
+ end
51
+
52
+ def only_processes
53
+ processes.collect{ |_, process| process }
54
+ end
55
+
56
+ # Fetch output (stdout, stderr) from command
57
+ #
58
+ # @param [String] cmd
59
+ # The command
60
+ def output_from(cmd)
61
+ cmd = Utils.detect_ruby(cmd)
62
+ get_process(cmd).output
63
+ end
64
+
65
+ # Fetch stdout from command
66
+ #
67
+ # @param [String] cmd
68
+ # The command
69
+ def stdout_from(cmd)
70
+ cmd = Utils.detect_ruby(cmd)
71
+ get_process(cmd).stdout
72
+ end
73
+
74
+ # Fetch stderr from command
75
+ #
76
+ # @param [String] cmd
77
+ # The command
78
+ def stderr_from(cmd)
79
+ cmd = Utils.detect_ruby(cmd)
80
+ get_process(cmd).stderr
81
+ end
82
+
83
+ # Get stdout of all processes
84
+ #
85
+ # @return [String]
86
+ # The stdout of all process which have run before
87
+ def all_stdout
88
+ stop_processes!
89
+ only_processes.each_with_object("") { |ps, out| out << ps.stdout }
90
+ end
91
+
92
+ # Get stderr of all processes
93
+ #
94
+ # @return [String]
95
+ # The stderr of all process which have run before
96
+ def all_stderr
97
+ stop_processes!
98
+ only_processes.each_with_object("") { |ps, out| out << ps.stderr }
99
+ end
100
+
101
+ # Get stderr and stdout of all processes
102
+ #
103
+ # @return [String]
104
+ # The stderr and stdout of all process which have run before
105
+ def all_output
106
+ all_stdout << all_stderr
107
+ end
108
+
109
+ def clear
110
+ processes.clear
111
+ end
112
+ end
113
+ end