Class: RSpec::ShellCommand::Matchers::Output
- Inherits:
-
Base
- Object
- Base
- RSpec::ShellCommand::Matchers::Output
show all
- Includes:
- Matchers::Composable
- Defined in:
- lib/rspec/shell_command/matchers/output.rb
Overview
Provide implementation of out matcher
Check whether given command output expected string or pattern
to stdout or stderr
Instance Method Summary
collapse
Methods inherited from Base
#actual_status, #actual_status_message, #make_expected_and_got_message
Constructor Details
#initialize(expected, orig) ⇒ Output
Returns a new instance of Output.
14
15
16
17
|
# File 'lib/rspec/shell_command/matchers/output.rb', line 14
def initialize(expected, orig)
@expected = expected
@orig = orig
end
|
Instance Method Details
#description ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/rspec/shell_command/matchers/output.rb', line 66
def description
if @command
"output #{description_of(@expected)} to #{@stream}"
else
"output to #{@stream}"
end
end
|
#failure_message ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/rspec/shell_command/matchers/output.rb', line 34
def failure_message
if @actual_is_command
"expect command to #{description}"
else
@orig.failure_message
end
end
|
#failure_message_when_negated ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/rspec/shell_command/matchers/output.rb', line 42
def failure_message_when_negated
if @actual_is_command
"expect command to not #{description}"
else
@orig.failure_message_when_negated
end
end
|
#matches?(actual) ⇒ Boolean
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/rspec/shell_command/matchers/output.rb', line 19
def matches?(actual)
@actual_is_command = actual.is_a?(ShellCommand)
return @orig.matches?(actual) unless @actual_is_command
@actual = actual.execute
return false unless @stream == :stdout || @stream == :stderr
if @expected
values_match?(@expected, actual_output)
else
!actual_output.empty?
end
end
|
#supports_block_expectations? ⇒ Boolean
50
51
52
|
# File 'lib/rspec/shell_command/matchers/output.rb', line 50
def supports_block_expectations?
true
end
|
#to_stderr ⇒ Object
60
61
62
63
64
|
# File 'lib/rspec/shell_command/matchers/output.rb', line 60
def to_stderr
@stream = :stderr
@orig.to_stderr
self
end
|
#to_stdout ⇒ Object
54
55
56
57
58
|
# File 'lib/rspec/shell_command/matchers/output.rb', line 54
def to_stdout
@stream = :stdout
@orig.to_stdout
self
end
|