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

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

Overview

Contract asserting the action queries the repository for the entities.

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):

  • expected_value (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.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/cuprum/rails/rspec/contracts/actions/index_contracts.rb', line 71

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

  describe '#call' do
    include Cuprum::Rails::RSpec::ContractHelpers

    let(:request) do
      Cuprum::Rails::Request.new(params: configured_params)
    end
    let(:configured_params) do
      option_with_default(options[:params], default: {})
    end
    let(:configured_existing_entities) do
      option_with_default(existing_entities)
    end
    let(:configured_expected_value) do
      resource_name = configured_resource.name

      option_with_default(
        options[:expected_value],
        default: {
          resource_name => configured_existing_entities
        }
      )
    end

    it 'should return a passing result' do
      expect(call_action)
        .to be_a_passing_result
        .with_value(configured_expected_value)
    end

    instance_exec(&block) if block
  end
end