Module: Cuprum::Rails::RSpec::Contracts::Actions::IndexContracts::ShouldBeAnIndexActionContract

Extended by:
RSpec::SleepingKingStudios::Contract
Defined in:
lib/cuprum/rails/rspec/contracts/actions/index_contracts.rb

Overview

Contract asserting the action implements the index action interface.

Instance Method Summary collapse

Instance Method Details

#apply(example_group, existing_entities: , **options) { ... } ⇒ Object

Adds the contract to the example group.

Parameters:

  • example_group (RSpec::Core::ExampleGroup)

    The example group to which the contract is applied.

  • existing_entities (Object) (defaults to: )

    The existing entities to find.

Options Hash (**options):

  • examples_on_success (#to_proc)

    Extra examples to run for the passing case.

  • expected_value_on_success (Hash<String>)

    The expected value for the passing result. Defaults to a Hash with the found entity.

  • params (Hash<String>)

    The parameters used to build the request. Defaults to an empty hash.

Yields:

  • Additional examples to run for the passing case.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cuprum/rails/rspec/contracts/actions/index_contracts.rb', line 30

contract do |existing_entities:, **options, &block|
  include Cuprum::Rails::RSpec::Contracts::ActionContracts
  include Cuprum::Rails::RSpec::Contracts::Actions::IndexContracts

  # :nocov:
  if options[:examples_on_success] && block
    raise ArgumentError, 'provide either :examples_on_success or a block'
  elsif block
    options[:examples_on_success] = block
  end
  # :nocov:

  include_contract 'should be a resource action'

  include_contract 'should find the entities',
    existing_entities: existing_entities,
    expected_value:    options[:expected_value_on_success],
    params:            options[:params],
    &options[:examples_on_success]
end