Module: Cuprum::Collections::RSpec::Contracts::ScopeContracts::ShouldBeAScopeContract Deprecated

Extended by:
RSpec::SleepingKingStudios::Contract
Defined in:
lib/cuprum/collections/rspec/contracts/scope_contracts.rb

Overview

Deprecated.

0.6.0

Contract validating the behavior of a scope implementation.

Instance Method Summary collapse

Instance Method Details

#apply(example_group, invertible: false) ⇒ Object

Adds the contract to the example group.

Parameters:

  • example_group (RSpec::Core::ExampleGroup)

    the example group to which the contract is applied.

  • invertible (Boolean) (defaults to: false)

    if true, the scope defines an implementation of the #invert method. Defaults to false.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cuprum/collections/rspec/contracts/scope_contracts.rb', line 23

contract do |invertible: false|
  message = 'Use deferred examples "should implement the Scope methods"'

  SleepingKingStudios::Tools::Toolbelt
    .instance
    .core_tools
    .deprecate(
      'ShouldBeAScopeContract',
      message:
    )

  describe '#==' do
    it { expect(subject == nil).to be false } # rubocop:disable Style/NilComparison

    it { expect(subject == Object.new.freeze).to be false }

    describe 'with a scope of different type' do
      let(:other) { Spec::OtherScope.new }

      example_class 'Spec::OtherScope',
        Cuprum::Collections::Scopes::Base \
      do |klass|
        klass.define_method(:type) { :invalid }
      end

      it { expect(subject == other).to be false }
    end
  end

  describe '#as_json' do
    it { expect(subject).to respond_to(:as_json).with(0).arguments }

    it { expect(subject.as_json).to be_a Hash }

    it { expect(subject.as_json['type']).to be subject.type }
  end

  describe '#empty?' do
    include_examples 'should define predicate', :empty?, -> { be_boolean }
  end

  describe '#invert' do
    let(:error_class) do
      Cuprum::Collections::Scopes::Base::UninvertibleScopeException
    end
    let(:error_message) do
      "Scope class #{described_class} does not implement #invert"
    end

    it { expect(subject).to respond_to(:invert).with(0).arguments }

    next if invertible

    it 'should raise an exception' do
      expect { subject.invert }.to raise_error error_class, error_message
    end
  end

  describe '#type' do
    include_examples 'should define reader', :type, -> { be_a(Symbol) }
  end
end