Class: Pact::Provider::ProviderStateConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/provider/provider_state_configuration.rb

Defined Under Namespace

Classes: ProviderStateConfigurationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts: {}) ⇒ ProviderStateConfiguration

Returns a new instance of ProviderStateConfiguration.



10
11
12
13
14
15
# File 'lib/pact/provider/provider_state_configuration.rb', line 10

def initialize(name, opts: {})
  @name = name
  @opts = opts
  @setup_proc = nil
  @teardown_proc = nil
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/pact/provider/provider_state_configuration.rb', line 6

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/pact/provider/provider_state_configuration.rb', line 6

def opts
  @opts
end

#setup_procObject (readonly)

Returns the value of attribute setup_proc.



6
7
8
# File 'lib/pact/provider/provider_state_configuration.rb', line 6

def setup_proc
  @setup_proc
end

#teardown_procObject (readonly)

Returns the value of attribute teardown_proc.



6
7
8
# File 'lib/pact/provider/provider_state_configuration.rb', line 6

def teardown_proc
  @teardown_proc
end

Instance Method Details

#set_up(&block) ⇒ Object



17
18
19
# File 'lib/pact/provider/provider_state_configuration.rb', line 17

def set_up(&block)
  @setup_proc = block
end

#tear_down(&block) ⇒ Object



21
22
23
# File 'lib/pact/provider/provider_state_configuration.rb', line 21

def tear_down(&block)
  @teardown_proc = block
end

#validate!Object



25
26
27
28
29
# File 'lib/pact/provider/provider_state_configuration.rb', line 25

def validate!
  return if @setup_proc || @teardown_proc

  raise ProviderStateConfigurationError.new("no hooks configured for state #{@name}: \"provider_state\" declaration only needed if setup/teardown hooks are used for that state. Please add hooks or remove \"provider_state\" declaration") # rubocop:disable Layout/LineLength
end