Class: RSpec::Bash::StubBehavior

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/bash/stub_behavior.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args: nil, body:, charges: 1, subshell: true) ⇒ StubBehavior

Returns a new instance of StubBehavior.



6
7
8
9
10
11
# File 'lib/rspec/bash/stub_behavior.rb', line 6

def initialize(args: nil, body:, charges: 1, subshell: true)
  @args = args
  @body = body
  @subshell = subshell
  @charges = charges
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



4
5
6
# File 'lib/rspec/bash/stub_behavior.rb', line 4

def args
  @args
end

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/rspec/bash/stub_behavior.rb', line 4

def body
  @body
end

Instance Method Details

#applicable?(args) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rspec/bash/stub_behavior.rb', line 17

def applicable?(args)
  @args == args
end

#apply!(args) ⇒ Object



29
30
31
32
# File 'lib/rspec/bash/stub_behavior.rb', line 29

def apply!(args)
  @charges -= 1
  @body.call(args)
end

#context_free?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rspec/bash/stub_behavior.rb', line 21

def context_free?
  @args.nil?
end

#requires_subshell?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rspec/bash/stub_behavior.rb', line 25

def requires_subshell?
  @subshell
end

#usable?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rspec/bash/stub_behavior.rb', line 13

def usable?
  @charges > 0
end