Class: Cog::SpecHelpers::Matchers::MatchMaker
- Inherits:
-
Object
- Object
- Cog::SpecHelpers::Matchers::MatchMaker
- Defined in:
- lib/cog/spec_helpers/matchers/match_maker.rb
Overview
Within #match_maker blocks, self
is set to an instance of this class
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
A list of lines read from STDERR after executing the Invocation.
-
#lines ⇒ Object
readonly
A list of lines read from STDOUT after executing the Invocation.
Instance Method Summary collapse
-
#before { ... } ⇒ nil
Define a block which runs before the Invocation.
-
#failure_message ⇒ String
Positive interpretation of the #message block result.
-
#failure_message_when_negated ⇒ String
Negative interpretation of the #message block result.
-
#matches?(invocation) ⇒ Boolean
Result of the #test block.
-
#message { ... } ⇒ nil
Define a block which runs after a test fails and should return a failure message template.
-
#test { ... } ⇒ nil
Define the test which runs after the Invocation.
-
#trace ⇒ String
STDOUT and STDERR.
Instance Attribute Details
#error ⇒ Object (readonly)
A list of lines read from STDERR after executing the Invocation
13 14 15 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 13 def error @error end |
#lines ⇒ Object (readonly)
A list of lines read from STDOUT after executing the Invocation
10 11 12 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 10 def lines @lines end |
Instance Method Details
#before { ... } ⇒ nil
Define a block which runs before the Invocation.
This is not required, but can be used to save context that is used the in post invocation #test.
44 45 46 47 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 44 def before(&block) @before_block = block nil end |
#failure_message ⇒ String
Returns positive interpretation of the #message block result.
75 76 77 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 75 def '\1' end |
#failure_message_when_negated ⇒ String
Returns negative interpretation of the #message block result.
81 82 83 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 81 def '\2' end |
#matches?(invocation) ⇒ Boolean
Returns result of the #test block.
63 64 65 66 67 68 69 70 71 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 63 def matches?(invocation) @invocation = invocation instance_eval &@before_block unless @before_block.nil? @invocation.exec do |input, output, error| @lines = output.readlines @error = error.readlines end instance_eval &@test_block end |
#message { ... } ⇒ nil
Define a block which runs after a test fails and should return a failure message template.
The template is used for both positive and negative failures. Substrings which look like this "[positive|negative]
“ will be replaced with the appropriate section.
would read “expected cog to show the default help text” for a positive failure and “expected cog to not show the default help text” for a negative failure. The “expected cog” part is inserted automatically.
32 33 34 35 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 32 def (&block) @msg_block = block nil end |
#test { ... } ⇒ nil
Define the test which runs after the Invocation
This can make use of instance variables set during #before.
55 56 57 58 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 55 def test(&block) @test_block = block nil end |
#trace ⇒ String
Returns STDOUT and STDERR.
87 88 89 |
# File 'lib/cog/spec_helpers/matchers/match_maker.rb', line 87 def trace "STDOUT:\n#{@lines.join "\n"}\nSTDERR:\n#{@error.join "\n"}" end |