Top Level Namespace
Defined Under Namespace
Modules: Aruba
Instance Method Summary collapse
-
#a_path_matching_pattern(/pattern/) ⇒ Boolean
This matchers checks if <path> matches pattern.
-
#be_a_command_found_in_path ⇒ Boolean
This matchers checks if <command> can be found in path.
-
#be_an_absolute_path ⇒ Boolean
This matchers checks if <path> exists in filesystem.
-
#be_an_existing_directory ⇒ Boolean
This matchers checks if <directory> exists in filesystem.
-
#be_an_existing_executable ⇒ Boolean
This matchers checks if <file> exists in filesystem.
-
#be_an_existing_file ⇒ Boolean
This matchers checks if <file> exists in filesystem.
-
#be_an_existing_path ⇒ Boolean
This matchers checks if <path> exists in filesystem.
-
#be_successfuly_executed ⇒ Boolean
This matchers checks if execution of <command> was successful.
-
#have_exit_status(status) ⇒ Boolean
This matchers checks if <command> has exit status <status>.
-
#have_file_content(content) ⇒ Boolean
This matchers checks if <file> has content.
-
#have_file_size(size) ⇒ Boolean
This matchers checks if path has file size.
-
#have_output ⇒ Boolean
This matchers checks if <command> has created output.
-
#have_output_on_stderr ⇒ Boolean
This matchers checks if <command> has created output on stderr.
-
#have_output_on_stdout ⇒ Boolean
This matchers checks if <command> has created output on stdout.
-
#have_output_size(output) ⇒ Boolean
This matchers checks if output has size.
-
#have_permissions(permissions) ⇒ Boolean
This matchers checks if <file> or <directory> has <perm> permissions.
-
#have_same_file_content_as(file_name) ⇒ Boolean
This matchers checks if <file1> has the same content like <file2>.
-
#have_sub_directory(sub_directory) ⇒ Boolean
This matchers checks if <directory> has given sub-directory.
-
#include_output_string(string) ⇒ Boolean
This matchers checks if the output string of a command includes string.
-
#match_output_string(string) ⇒ Boolean
This matchers checks if the output string of a command matches regular expression.
-
#output_string_eq(string) ⇒ Boolean
This matchers checks if the output string of a command includes string.
-
#run_too_long ⇒ Boolean
This matchers checks if <command> run too long.
Instance Method Details
#a_path_matching_pattern(/pattern/) ⇒ Boolean
This matchers checks if <path> matches pattern. ‘pattern` can be a string, regexp or an RSpec matcher.
21 |
# File 'lib/aruba/matchers/path/a_path_matching_pattern.rb', line 21 RSpec::Matchers.alias_matcher :a_path_matching_pattern, :match |
#be_a_command_found_in_path ⇒ Boolean
This matchers checks if <command> can be found in path
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/aruba/matchers/file/be_a_command_found_in_path.rb', line 16 RSpec::Matchers.define :be_a_command_found_in_path do match do |actual| !which(actual).nil? end do |actual| format(%(expected that command "%s" can be found in PATH "%s".), actual, aruba.environment["PATH"]) end do |actual| format(%(expected that command "%s" cannot be found in PATH "%s".), actual, aruba.environment["PATH"]) end end |
#be_an_absolute_path ⇒ Boolean
This matchers checks if <path> exists in filesystem
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/aruba/matchers/path/be_an_absolute_path.rb', line 18 RSpec::Matchers.define :be_an_absolute_path do |_| match do |actual| absolute?(actual) end do |actual| format("expected that path \"%s\" is absolute, but it's not", actual) end do |actual| format('expected that path "%s" is not absolute, but it is', actual) end end |
#be_an_existing_directory ⇒ Boolean
This matchers checks if <directory> exists in filesystem
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aruba/matchers/directory/be_an_existing_directory.rb', line 16 RSpec::Matchers.define :be_an_existing_directory do |_| match do |actual| stop_all_commands raise "String expected" unless actual.is_a? String directory?(actual) end do |actual| format('expected that directory "%s" exists', actual) end do |actual| format('expected that directory "%s" does not exist', actual) end end |
#be_an_existing_executable ⇒ Boolean
This matchers checks if <file> exists in filesystem
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aruba/matchers/file/be_an_existing_executable.rb', line 18 RSpec::Matchers.define :be_an_existing_executable do |_| match do |actual| @actual = Shellwords.split(actual.commandline).first if actual.respond_to? :commandline executable?(@actual) end do |actual| format('expected that executable "%s" exists', actual) end do |actual| format('expected that executable "%s" does not exist', actual) end end |
#be_an_existing_file ⇒ Boolean
This matchers checks if <file> exists in filesystem
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aruba/matchers/file/be_an_existing_file.rb', line 16 RSpec::Matchers.define :be_an_existing_file do |_| match do |actual| stop_all_commands raise "String expected" unless actual.is_a? String file?(actual) end do |actual| format('expected that file "%s" exists', actual) end do |actual| format('expected that file "%s" does not exist', actual) end end |
#be_an_existing_path ⇒ Boolean
This matchers checks if <path> exists in filesystem
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aruba/matchers/path/be_an_existing_path.rb', line 19 RSpec::Matchers.define :be_an_existing_path do |_| match do |actual| exist?(actual) end do |actual| format('expected that path "%s" exists', actual) end do |actual| format('expected that path "%s" does not exist', actual) end end |
#be_successfuly_executed ⇒ Boolean
This matchers checks if execution of <command> was successful
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/aruba/matchers/command/be_successfully_executed.rb', line 21 RSpec::Matchers.define :be_successfully_executed do match do |actual| @old_actual = actual @actual = @old_actual.commandline expect(@old_actual).to have_exit_status(0) end do |_actual| "Expected `#{@actual}` to succeed" \ " but got non-zero exit status and the following output:" \ "\n\n#{@old_actual.output}\n" end end |
#have_exit_status(status) ⇒ Boolean
This matchers checks if <command> has exit status <status>
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aruba/matchers/command/have_exit_status.rb', line 19 RSpec::Matchers.define :have_exit_status do |expected| match do |actual| actual.stop @actual_exit_status = actual.exit_status values_match? expected, @actual_exit_status end do |actual| format( %(expected that command "%s" has exit status of "%s", but has "%s".), actual.commandline, expected.to_s, @actual_exit_status.to_s ) end do |actual| format( %(expected that command "%s" does not have exit status of "%s", but has "%s".), actual.commandline, expected.to_s, @actual_exit_status.to_s ) end end |
#have_file_content(content) ⇒ Boolean
This matchers checks if <file> has content. ‘content` can be a string, regexp or an RSpec matcher.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aruba/matchers/file/have_file_content.rb', line 39 RSpec::Matchers.define :have_file_content do |expected| match do |actual| stop_all_commands next false unless file? actual @actual = read(actual).join("\n").chomp @expected = if expected.is_a? String expected.chomp else expected end values_match?(@expected, @actual) end diffable if expected.is_a? String description { "have file content: #{description_of expected}" } end |
#have_file_size(size) ⇒ Boolean
This matchers checks if path has file size
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/aruba/matchers/file/have_file_size.rb', line 21 RSpec::Matchers.define :have_file_size do |expected| match do |actual| stop_all_commands next false unless file?(actual) @old_actual = actual @actual = file_size(actual) @expected = expected.to_i values_match?(@expected, @actual) end do |_actual| format('expected that file "%s" has size "%s", but has "%s"', @old_actual, @actual, @expected) end do |_actual| format('expected that file "%s" does not have size "%s", but has "%s"', @old_actual, @actual, @expected) end end |
#have_output ⇒ Boolean
This matchers checks if <command> has created output
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/aruba/matchers/command/have_output.rb', line 18 RSpec::Matchers.define :have_output do |expected| match do |actual| @old_actual = actual unless @old_actual.respond_to? :output raise "Expected #{@old_actual} to respond to #output" end @old_actual.stop @actual = sanitize_text(actual.output) values_match?(expected, @actual) end diffable description { "have output: #{description_of expected}" } do |_actual| "expected `#{@old_actual.commandline}` to have output #{description_of expected}\n" \ "but was:\n#{Aruba::Matchers::Base::MessageIndenter. @actual}" end end |
#have_output_on_stderr ⇒ Boolean
This matchers checks if <command> has created output on stderr
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/aruba/matchers/command/have_output_on_stderr.rb', line 16 RSpec::Matchers.define :have_output_on_stderr do |expected| match do |actual| @old_actual = actual unless @old_actual.respond_to? :stderr raise "Expected #{@old_actual} to respond to #stderr" end @old_actual.stop @actual = sanitize_text(actual.stderr) values_match?(expected, @actual) end diffable description { "have output on stderr: #{description_of expected}" } end |
#have_output_on_stdout ⇒ Boolean
This matchers checks if <command> has created output on stdout
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/aruba/matchers/command/have_output_on_stdout.rb', line 16 RSpec::Matchers.define :have_output_on_stdout do |expected| match do |actual| @old_actual = actual unless @old_actual.respond_to? :stdout raise "Expected #{@old_actual} to respond to #stdout" end @old_actual.stop @actual = sanitize_text(actual.stdout) values_match?(expected, @actual) end diffable description { "have output on stdout: #{description_of expected}" } end |
#have_output_size(output) ⇒ Boolean
This matchers checks if output has size.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/aruba/matchers/command/have_output_size.rb', line 19 RSpec::Matchers.define :have_output_size do |expected| match do |actual| raise "Expected #{actual} to respond to #size" unless actual.respond_to? :size @actual = actual.size values_match? expected, @actual end description { "output has size #{description_of expected}" } end |
#have_permissions(permissions) ⇒ Boolean
This matchers checks if <file> or <directory> has <perm> permissions
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aruba/matchers/path/have_permissions.rb', line 29 RSpec::Matchers.define :have_permissions do |expected| def (file) @actual = Aruba.platform.filesystem_status.new(file).mode end match do |actual| stop_all_commands @old_actual = actual @actual = ((@old_actual)) @expected = case expected when Integer expected.to_s(8) when String expected.gsub(/^0*/, "") else expected end values_match? @expected, @actual end do |_actual| format('expected that path "%s" has permissions "%s", but has "%s".', @old_actual, @expected, @actual) end do |_actual| format('expected that path "%s" does not have permissions "%s", but has "%s".', @old_actual, @expected, @actual) end end |
#have_same_file_content_as(file_name) ⇒ Boolean
This matchers checks if <file1> has the same content like <file2>
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aruba/matchers/file/have_same_file_content.rb', line 23 RSpec::Matchers.define :have_same_file_content_as do |expected| match do |actual| stop_all_commands next false unless file?(actual) && file?(expected) @actual = (actual) @expected = (expected) FileUtils.compare_file(@actual, @expected) end do |actual| format('expected that file "%s" is the same as file "%s".', actual, expected) end do |actual| format('expected that file "%s" differs from file "%s".', actual, expected) end end |
#have_sub_directory(sub_directory) ⇒ Boolean
This matchers checks if <directory> has given sub-directory
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/aruba/matchers/directory/have_sub_directory.rb', line 27 RSpec::Matchers.define :have_sub_directory do |expected| match do |actual| next false unless directory?(actual) @old_actual = actual @actual = list(actual) @expected = Array(expected).map { |p| File.join(@old_actual, p) } (@expected - @actual).empty? end diffable do |actual| format('expected that directory "%s" has the following sub-directories: %s.', actual.join(", "), expected) end do |actual| format('expected that directory "%s" does not have the following sub-directories: %s.', actual.join(", "), expected) end end |
#include_output_string(string) ⇒ Boolean
This matchers checks if the output string of a command includes string.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aruba/matchers/string/include_output_string.rb', line 19 RSpec::Matchers.define :include_output_string do |expected| match do |actual| actual.force_encoding("UTF-8") @expected = Regexp.new(Regexp.escape(sanitize_text(expected.to_s)), Regexp::MULTILINE) @actual = sanitize_text(actual) values_match? @expected, @actual end diffable description { "string includes: #{description_of expected}" } end |
#match_output_string(string) ⇒ Boolean
This matchers checks if the output string of a command matches regular expression.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aruba/matchers/string/match_output_string.rb', line 19 RSpec::Matchers.define :match_output_string do |expected| match do |actual| actual.force_encoding("UTF-8") @expected = Regexp.new(unescape_text(expected), Regexp::MULTILINE) @actual = sanitize_text(actual) values_match? @expected, @actual end diffable description { "output string matches: #{description_of expected}" } end |
#output_string_eq(string) ⇒ Boolean
This matchers checks if the output string of a command includes string.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aruba/matchers/string/output_string_eq.rb', line 19 RSpec::Matchers.define :output_string_eq do |expected| match do |actual| actual.force_encoding("UTF-8") @expected = sanitize_text(expected.to_s) @actual = sanitize_text(actual.to_s) values_match? @expected, @actual end diffable description { "output string is eq: #{description_of expected}" } end |
#run_too_long ⇒ Boolean
This matchers checks if <command> run too long. Say the timeout is 10 seconds and it takes <command> to finish in 15. This matchers will succeed.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aruba/matchers/command/have_finished_in_time.rb', line 20 RSpec::Matchers.define :have_finished_in_time do match do |actual| @old_actual = actual @actual = @old_actual.commandline unless @old_actual.respond_to? :timed_out? raise "Expected #{@old_actual} to respond to #timed_out?" end @old_actual.stop @old_actual.timed_out? == false end end |