Class: Rspec::Bash::StubbedCommand
- Inherits:
-
Object
- Object
- Rspec::Bash::StubbedCommand
- Defined in:
- lib/rspec/bash/stubbed_command.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#call_log ⇒ Object
readonly
Returns the value of attribute call_log.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #call_count(*arg) ⇒ Object
- #called? ⇒ Boolean
- #called_with_args?(*args) ⇒ Boolean
- #called_with_no_args? ⇒ Boolean
- #command ⇒ Object
-
#initialize(command, dir) ⇒ StubbedCommand
constructor
A new instance of StubbedCommand.
- #inspect ⇒ Object
- #outputs(contents, to: :stdout) ⇒ Object
- #returns_exitstatus(exitcode) ⇒ Object
- #stdin ⇒ Object
- #with_args(*args) ⇒ Object
Constructor Details
#initialize(command, dir) ⇒ StubbedCommand
Returns a new instance of StubbedCommand.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rspec/bash/stubbed_command.rb', line 6 def initialize(command, dir) @path = create_stub_file(command, dir) @arguments = [] @call_configuration = CallConfiguration.new( Pathname.new(dir).join("#{command}_stub.yml"), command ) @call_log = CallLog.new( Pathname.new(dir).join("#{command}_calls.yml") ) end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
4 5 6 |
# File 'lib/rspec/bash/stubbed_command.rb', line 4 def arguments @arguments end |
#call_log ⇒ Object (readonly)
Returns the value of attribute call_log.
4 5 6 |
# File 'lib/rspec/bash/stubbed_command.rb', line 4 def call_log @call_log end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/rspec/bash/stubbed_command.rb', line 4 def path @path end |
Instance Method Details
#call_count(*arg) ⇒ Object
35 36 37 |
# File 'lib/rspec/bash/stubbed_command.rb', line 35 def call_count(*arg) @call_log.call_count(*arg) end |
#called? ⇒ Boolean
23 24 25 |
# File 'lib/rspec/bash/stubbed_command.rb', line 23 def called? @call_log.exist? && @call_log.called_with_args?(*@args) end |
#called_with_args?(*args) ⇒ Boolean
31 32 33 |
# File 'lib/rspec/bash/stubbed_command.rb', line 31 def called_with_args?(*args) @call_log.called_with_args?(*args) end |
#called_with_no_args? ⇒ Boolean
27 28 29 |
# File 'lib/rspec/bash/stubbed_command.rb', line 27 def called_with_no_args? @call_log.called_with_no_args? end |
#command ⇒ Object
39 40 41 |
# File 'lib/rspec/bash/stubbed_command.rb', line 39 def command @call_configuration.command end |
#inspect ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/rspec/bash/stubbed_command.rb', line 57 def inspect if @arguments.any? "<Stubbed #{@call_configuration.command.inspect} " \ "args: #{@arguments.join(' ').inspect}>" else "<Stubbed #{@call_configuration.command.inspect}>" end end |
#outputs(contents, to: :stdout) ⇒ Object
48 49 50 51 |
# File 'lib/rspec/bash/stubbed_command.rb', line 48 def outputs(contents, to: :stdout) @call_configuration.add_output(contents, to, @arguments) self end |
#returns_exitstatus(exitcode) ⇒ Object
43 44 45 46 |
# File 'lib/rspec/bash/stubbed_command.rb', line 43 def returns_exitstatus(exitcode) @call_configuration.set_exitcode(exitcode, @arguments) self end |
#stdin ⇒ Object
53 54 55 |
# File 'lib/rspec/bash/stubbed_command.rb', line 53 def stdin @call_log.stdin_for_args(*@arguments) if @call_log.exist? end |
#with_args(*args) ⇒ Object
18 19 20 21 |
# File 'lib/rspec/bash/stubbed_command.rb', line 18 def with_args(*args) @arguments = args self end |