Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore previously removed behaviors #644

Merged
merged 6 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ Feature: All output of commands which were executed
When I run `cucumber`
Then the features should not all pass with:
"""
expected `aruba-test-cli` to have output string includes: "goodbye world"
but was:
hello world (RSpec::Expectations::ExpectationNotMetError)
expected "hello world" to string includes: "goodbye world"
"""

Scenario: Detect subset of multiline output
Expand Down Expand Up @@ -222,10 +220,13 @@ Feature: All output of commands which were executed
When I run `cucumber`
Then the features should not all pass with:
"""
expected `aruba-test-cli` to have output output string is eq: "hello\nworld"
but was:
goodbye
world (RSpec::Expectations::ExpectationNotMetError)
expected "goodbye\nworld" to output string is eq: "hello\nworld"
Diff:
@@ -1,3 +1,3 @@
-hello
+goodbye
world
(RSpec::Expectations::ExpectationNotMetError)
"""

Scenario: Detect subset of one-line output with regex
Expand Down Expand Up @@ -439,9 +440,6 @@ Feature: All output of commands which were executed
Then the stdout should contain exactly:
\"\"\"
This is cli1
\"\"\"
And the stdout should contain exactly:
\"\"\"
This is cli2
\"\"\"
"""
Expand Down Expand Up @@ -545,9 +543,6 @@ Feature: All output of commands which were executed
Then the stdout should contain exactly:
\"\"\"
This is cli1
\"\"\"
And the stdout should contain exactly:
\"\"\"
This is cli2
\"\"\"
"""
Expand Down
24 changes: 24 additions & 0 deletions lib/aruba/api/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ def terminate_all_commands(&block)
self
end

# Get stdout of all processes
#
# @return [String]
# The stdout of all processes which have run before
def all_stdout
aruba.command_monitor.all_stdout
end

# Get stderr of all processes
#
# @return [String]
# The stderr of all processes which have run before
def all_stderr
aruba.command_monitor.all_stderr
end

# Get stderr and stdout of all processes
#
# @return [String]
# The stderr and stdout of all processes which have run before
def all_output
aruba.command_monitor.all_output
end

# Find a started command
#
# @param [String, Command] commandline
Expand Down
9 changes: 9 additions & 0 deletions lib/aruba/api/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ def setup_aruba(clobber = true)
self
end

# Execute block in Aruba's current directory
#
# @yield
# The block which should be run in current directory
def in_current_directory(&block)
create_directory '.' unless directory?('.')
cd('.', &block)
end

# Switch to directory
#
# @param [String] dir
Expand Down
76 changes: 56 additions & 20 deletions lib/aruba/cucumber/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,32 @@
expect(last_command_started.output).to have_output_size size.to_i
end

Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain( exactly)? "([^"]*)"$/) do |channel, cmd, negated, exactly, expected|
## the stderr should contain "hello"
Then(/^(?:the )?(output|stderr|stdout) should( not)? contain( exactly)? "([^"]*)"$/) do |channel, negated, exactly, expected|
combined_output = case channel.to_sym
when :output
all_output
when :stderr
all_stderr
when :stdout
all_stdout
end

output_string_matcher = if exactly
:an_output_string_being_eq
else
:an_output_string_including
end

if negated
expect(combined_output).not_to send(output_string_matcher, expected)
else
expect(combined_output).to send(output_string_matcher, expected)
end
end

## the stderr from "echo -n 'Hello'" should contain "hello"
Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should( not)? contain( exactly)? "([^"]*)"$/) do |channel, cmd, negated, exactly, expected|
matcher = case channel.to_sym
when :output
:have_output
Expand All @@ -129,11 +154,7 @@
:have_output_on_stdout
end

commands = if cmd
[aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))]
else
all_commands
end
command = aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))

output_string_matcher = if exactly
:an_output_string_being_eq
Expand All @@ -142,33 +163,48 @@
end

if negated
expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected))
expect(command).not_to send(matcher, send(output_string_matcher, expected))
else
expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected))
expect(command).to send(matcher, send(output_string_matcher, expected))
end
end

## the stderr should contain "hello"
## the stderr from "echo -n 'Hello'" should contain "hello"
## the stderr should contain exactly:
Then(/^(?:the )?(output|stderr|stdout) should( not)? contain( exactly)?:$/) do |channel, negated, exactly, expected|
combined_output = case channel.to_sym
when :output
all_output
when :stderr
all_stderr
when :stdout
all_stdout
end

output_string_matcher = if exactly
:an_output_string_being_eq
else
:an_output_string_including
end

if negated
expect(combined_output).not_to send(output_string_matcher, expected)
else
expect(combined_output).to send(output_string_matcher, expected)
end
end

## the stderr from "echo -n 'Hello'" should contain exactly:
Then(/^(?:the )?(output|stderr|stdout)(?: from "([^"]*)")? should( not)? contain( exactly)?:$/) do |channel, cmd, negated, exactly, expected|
Then(/^(?:the )?(output|stderr|stdout) from "([^"]*)" should( not)? contain( exactly)?:$/) do |channel, cmd, negated, exactly, expected|
matcher = case channel.to_sym
when :output
:have_output
when :stderr
:have_output_on_stderr
when :stdout
:have_output_on_stdout
else
fail ArgumentError, %(Invalid channel "#{channel}" chosen. Only "output", "stderr" or "stdout" are allowed.)
end

commands = if cmd
[aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))]
else
all_commands
end
command = aruba.command_monitor.find(Aruba.platform.detect_ruby(cmd))

output_string_matcher = if exactly
:an_output_string_being_eq
Expand All @@ -177,9 +213,9 @@
end

if negated
expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected))
expect(command).not_to send(matcher, send(output_string_matcher, expected))
else
expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected))
expect(command).to send(matcher, send(output_string_matcher, expected))
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/matchers/command/have_exit_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@old_actual.stop
@actual = actual.exit_status

next false unless @old_actual.respond_to? :exit_status
raise "Expected #{@old_actual} to respond to #exit_status" unless @old_actual.respond_to? :exit_status

values_match? expected, @actual
end
Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/matchers/command/have_finished_in_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@old_actual = actual
@actual = @old_actual.commandline

next false unless @old_actual.respond_to? :timed_out?
raise "Expected #{@old_actual} to respond to #timed_out?" unless @old_actual.respond_to? :timed_out?

@old_actual.stop

Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/matchers/command/have_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
match do |actual|
@old_actual = actual

next false unless @old_actual.respond_to? :output
raise "Expected #{@old_actual} to respond to #output" unless @old_actual.respond_to? :output

@old_actual.stop

Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/matchers/command/have_output_on_stderr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
match do |actual|
@old_actual = actual

next false unless @old_actual.respond_to? :stderr
raise "Expected #{@old_actual} to respond to #stderr" unless @old_actual.respond_to? :stderr

@old_actual.stop

Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/matchers/command/have_output_on_stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
match do |actual|
@old_actual = actual

next false unless @old_actual.respond_to? :stdout
raise "Expected #{@old_actual} to respond to #stdout" unless @old_actual.respond_to? :stdout

@old_actual.stop

Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/matchers/command/have_output_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# end
RSpec::Matchers.define :have_output_size do |expected|
match do |actual|
next false unless actual.respond_to? :size
raise "Expected #{actual} to respond to #size" unless actual.respond_to? :size

@actual = actual.size
values_match? expected, @actual
Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/matchers/directory/be_an_existing_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
match do |actual|
stop_all_commands

next false unless actual.is_a? String
raise 'String expected' unless actual.is_a? String

directory?(actual)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/matchers/file/be_an_existing_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
match do |actual|
stop_all_commands

next false unless actual.is_a? String
raise 'String expected' unless actual.is_a? String

file?(actual)
end
Expand Down
28 changes: 28 additions & 0 deletions lib/aruba/platforms/command_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ def clear
self
end

# Get stdout of all commands
#
# @return [String]
# The stdout of all command which have run before
def all_stdout
registered_commands.each(&:stop)

registered_commands.each_with_object('') { |e, a| a << e.stdout }
end

# Get stderr of all commands
#
# @return [String]
# The stderr of all command which have run before
def all_stderr
registered_commands.each(&:stop)

registered_commands.each_with_object('') { |e, a| a << e.stderr }
end

# Get stderr and stdout of all commands
#
# @return [String]
# The stderr and stdout of all command which have run before
def all_output
all_stdout << all_stderr
end

# Register command to monitor
def register_command(cmd)
registered_commands << cmd
Expand Down
Loading