Module: Cuprum::Collections::RSpec::Contracts::ScopeContracts::ShouldBeAContainerScopeContract 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 Container 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.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/cuprum/collections/rspec/contracts/scope_contracts.rb', line 100

contract do |invertible: false|
  message =
    'Use deferred examples "should implement the Scope methods" and ' \
    '"should define child scopes"'
  SleepingKingStudios::Tools::Toolbelt
    .instance
    .core_tools
    .deprecate(
      'ShouldBeADisjunctionScopeContract',
      message:
    )

  shared_context 'with scopes' do
    let(:scopes) do
      [
        build_scope({ 'title'    => 'J.R.R. Tolkien' }),
        build_scope({ 'series'   => 'The Lord of the Rings' }),
        build_scope({ 'category' => 'Science Fiction and Fantasy' })
      ]
    end
  end

  describe '.new' do
    it 'should define the constructor' do
      expect(described_class)
        .to be_constructible
        .with(0).arguments
        .and_keywords(:scopes)
        .and_any_keywords
    end
  end

  include_contract('should be a scope', invertible:)

  describe '#==' do
    describe 'with a scope with the same class' do
      let(:other) { described_class.new(scopes: other_scopes) }

      describe 'with empty scopes' do
        let(:other_scopes) { [] }

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

      describe 'with non-matching scopes' do
        let(:other_scopes) do
          Array.new(3) do
            Cuprum::Collections::Scope.new({ 'ok' => true })
          end
        end

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

      wrap_context 'with scopes' do
        describe 'with empty scopes' do
          let(:other_scopes) { [] }

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

        describe 'with non-matching scopes' do
          let(:other_scopes) do
            Array.new(3) do
              Cuprum::Collections::Scope.new({ 'ok' => true })
            end
          end

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

        describe 'with matching scopes' do
          let(:other_scopes) { subject.scopes }

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

    describe 'with a scope with the same type' do
      let(:other) { Spec::CustomScope.new(scopes: other_scopes) }

      example_class 'Spec::CustomScope',
        Cuprum::Collections::Scopes::Base \
      do |klass|
        klass.include Cuprum::Collections::Scopes::Container
      end

      before(:example) do
        allow(other).to receive(:type).and_return(scope.type)
      end

      describe 'with empty scopes' do
        let(:other_scopes) { [] }

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

      describe 'with non-matching scopes' do
        let(:other_scopes) do
          Array.new(3) do
            Cuprum::Collections::Scope.new({ 'ok' => true })
          end
        end

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

      wrap_context 'with scopes' do
        describe 'with empty scopes' do
          let(:other_scopes) { [] }

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

        describe 'with non-matching scopes' do
          let(:other_scopes) do
            Array.new(3) do
              Cuprum::Collections::Scope.new({ 'ok' => true })
            end
          end

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

        describe 'with matching scopes' do
          let(:other_scopes) { subject.scopes }

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

  describe '#as_json' do
    it { expect(subject.as_json['scopes']).to be == [] }

    wrap_context 'with scopes' do
      let(:expected) { subject.scopes.map(&:as_json) }

      it { expect(subject.as_json['scopes']).to be == expected }
    end
  end

  describe '#empty?' do
    it { expect(subject.empty?).to be true }

    wrap_context 'with scopes' do
      it { expect(subject.empty?).to be false }
    end
  end

  describe '#scopes' do
    include_examples 'should define reader', :scopes, -> { scopes }

    wrap_context 'with scopes' do
      it { expect(subject.scopes).to be == scopes }
    end
  end

  describe '#with_scopes' do
    let(:new_scopes) do
      [
        described_class.new(scopes: []),
        described_class.new(scopes: [])
      ]
    end

    it { expect(subject).to respond_to(:with_scopes).with(1).arguments }

    it 'should return a scope' do
      expect(subject.with_scopes(new_scopes)).to be_a described_class
    end

    it "should not change the original scope's child scopes" do
      expect { subject.with_scopes(new_scopes) }
        .not_to change(subject, :scopes)
    end

    it "should set the copied scope's child scopes" do
      expect(subject.with_scopes(new_scopes).scopes)
        .to be == new_scopes
    end

    wrap_context 'with scopes' do
      it "should not change the original scope's child scopes" do
        expect { subject.with_scopes(new_scopes) }
          .not_to change(subject, :scopes)
      end

      it "should set the copied scope's child scopes" do
        expect(subject.with_scopes(new_scopes).scopes)
          .to be == new_scopes
      end
    end
  end
end