diff --git a/lib/cuprum/collections/rspec.rb b/lib/cuprum/collections/rspec.rb index 838d592..4465f5a 100644 --- a/lib/cuprum/collections/rspec.rb +++ b/lib/cuprum/collections/rspec.rb @@ -6,5 +6,6 @@ module Cuprum::Collections # Namespace for RSpec contracts, which validate collection implementations. module RSpec autoload :Contracts, 'cuprum/collections/rspec/contracts' + autoload :Fixtures, 'cuprum/collections/rspec/fixtures' end end diff --git a/lib/cuprum/collections/rspec/contracts/basic/command_contracts.rb b/lib/cuprum/collections/rspec/contracts/basic/command_contracts.rb index de3f7d9..bb7f0ff 100644 --- a/lib/cuprum/collections/rspec/contracts/basic/command_contracts.rb +++ b/lib/cuprum/collections/rspec/contracts/basic/command_contracts.rb @@ -428,7 +428,7 @@ module WithBasicCommandContextsContract Stannum::Constraints::Types::HashWithStringKeys.new end let(:fixtures_data) do - Cuprum::Collections::RSpec::BOOKS_FIXTURES.dup + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup end let(:query) do Cuprum::Collections::Basic::Query.new(mapped_data) diff --git a/lib/cuprum/collections/rspec/contracts/query_contracts.rb b/lib/cuprum/collections/rspec/contracts/query_contracts.rb index 4595d19..341de34 100644 --- a/lib/cuprum/collections/rspec/contracts/query_contracts.rb +++ b/lib/cuprum/collections/rspec/contracts/query_contracts.rb @@ -11,7 +11,7 @@ module QueryContracts module ShouldBeAQuery extend RSpec::SleepingKingStudios::Contract - BOOKS_FIXTURES = Cuprum::Collections::RSpec::BOOKS_FIXTURES + BOOKS_FIXTURES = Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES private_constant :BOOKS_FIXTURES OPERATORS = Cuprum::Collections::Queries::Operators diff --git a/lib/cuprum/collections/rspec/fixtures.rb b/lib/cuprum/collections/rspec/fixtures.rb index afeb9d8..7fc189b 100644 --- a/lib/cuprum/collections/rspec/fixtures.rb +++ b/lib/cuprum/collections/rspec/fixtures.rb @@ -4,86 +4,89 @@ module Cuprum::Collections::RSpec # Sample data for validating collection implementations. - BOOKS_FIXTURES = [ - { - 'id' => 0, - 'title' => 'The Hobbit', - 'author' => 'J.R.R. Tolkien', - 'series' => nil, - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1937-09-21' - }, - { - 'id' => 1, - 'title' => 'The Silmarillion', - 'author' => 'J.R.R. Tolkien', - 'series' => nil, - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1977-09-15' - }, - { - 'id' => 2, - 'title' => 'The Fellowship of the Ring', - 'author' => 'J.R.R. Tolkien', - 'series' => 'The Lord of the Rings', - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1954-07-29' - }, - { - 'id' => 3, - 'title' => 'The Two Towers', - 'author' => 'J.R.R. Tolkien', - 'series' => 'The Lord of the Rings', - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1954-11-11' - }, - { - 'id' => 4, - 'title' => 'The Return of the King', - 'author' => 'J.R.R. Tolkien', - 'series' => 'The Lord of the Rings', - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1955-10-20' - }, - { - 'id' => 5, - 'title' => 'The Word for World is Forest', - 'author' => 'Ursula K. LeGuin', - 'series' => nil, - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1972-03-13' - }, - { - 'id' => 6, - 'title' => 'The Ones Who Walk Away From Omelas', - 'author' => 'Ursula K. LeGuin', - 'series' => nil, - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1973-10-01' - }, - { - 'id' => 7, - 'title' => 'A Wizard of Earthsea', - 'author' => 'Ursula K. LeGuin', - 'series' => 'Earthsea', - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1968-11-01' - }, - { - 'id' => 8, - 'title' => 'The Tombs of Atuan', - 'author' => 'Ursula K. LeGuin', - 'series' => 'Earthsea', - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1970-12-01' - }, - { - 'id' => 9, - 'title' => 'The Farthest Shore', - 'author' => 'Ursula K. LeGuin', - 'series' => 'Earthsea', - 'category' => 'Science Fiction and Fantasy', - 'published_at' => '1972-09-01' - } - ].map(&:freeze).freeze + module Fixtures + # Sample data for Book objects. + BOOKS_FIXTURES = [ + { + 'id' => 0, + 'title' => 'The Hobbit', + 'author' => 'J.R.R. Tolkien', + 'series' => nil, + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1937-09-21' + }, + { + 'id' => 1, + 'title' => 'The Silmarillion', + 'author' => 'J.R.R. Tolkien', + 'series' => nil, + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1977-09-15' + }, + { + 'id' => 2, + 'title' => 'The Fellowship of the Ring', + 'author' => 'J.R.R. Tolkien', + 'series' => 'The Lord of the Rings', + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1954-07-29' + }, + { + 'id' => 3, + 'title' => 'The Two Towers', + 'author' => 'J.R.R. Tolkien', + 'series' => 'The Lord of the Rings', + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1954-11-11' + }, + { + 'id' => 4, + 'title' => 'The Return of the King', + 'author' => 'J.R.R. Tolkien', + 'series' => 'The Lord of the Rings', + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1955-10-20' + }, + { + 'id' => 5, + 'title' => 'The Word for World is Forest', + 'author' => 'Ursula K. LeGuin', + 'series' => nil, + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1972-03-13' + }, + { + 'id' => 6, + 'title' => 'The Ones Who Walk Away From Omelas', + 'author' => 'Ursula K. LeGuin', + 'series' => nil, + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1973-10-01' + }, + { + 'id' => 7, + 'title' => 'A Wizard of Earthsea', + 'author' => 'Ursula K. LeGuin', + 'series' => 'Earthsea', + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1968-11-01' + }, + { + 'id' => 8, + 'title' => 'The Tombs of Atuan', + 'author' => 'Ursula K. LeGuin', + 'series' => 'Earthsea', + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1970-12-01' + }, + { + 'id' => 9, + 'title' => 'The Farthest Shore', + 'author' => 'Ursula K. LeGuin', + 'series' => 'Earthsea', + 'category' => 'Science Fiction and Fantasy', + 'published_at' => '1972-09-01' + } + ].map(&:freeze).freeze + end end diff --git a/spec/cuprum/collections/basic/collection_spec.rb b/spec/cuprum/collections/basic/collection_spec.rb index 78b1054..9d4368f 100644 --- a/spec/cuprum/collections/basic/collection_spec.rb +++ b/spec/cuprum/collections/basic/collection_spec.rb @@ -20,7 +20,7 @@ end shared_context 'when the collection has many items' do - let(:data) { Cuprum::Collections::RSpec::BOOKS_FIXTURES } + let(:data) { Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup } let(:items) { data } end diff --git a/spec/cuprum/collections/basic/command_spec.rb b/spec/cuprum/collections/basic/command_spec.rb index ed8dcfe..b890e0d 100644 --- a/spec/cuprum/collections/basic/command_spec.rb +++ b/spec/cuprum/collections/basic/command_spec.rb @@ -15,8 +15,10 @@ ) end + let(:data) do + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup + end let(:collection_name) { 'books' } - let(:data) { Cuprum::Collections::RSpec::BOOKS_FIXTURES } let(:constructor_options) { {} } describe '.new' do diff --git a/spec/cuprum/collections/basic/repository_spec.rb b/spec/cuprum/collections/basic/repository_spec.rb index 120d567..6852b4b 100644 --- a/spec/cuprum/collections/basic/repository_spec.rb +++ b/spec/cuprum/collections/basic/repository_spec.rb @@ -94,7 +94,7 @@ describe 'with data: an Array' do let(:data) do - Cuprum::Collections::RSpec::BOOKS_FIXTURES + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup end let(:collection_options) { super().merge(data: data) } @@ -103,7 +103,7 @@ context 'when initialized with data: value' do let(:data) do - { 'books' => Cuprum::Collections::RSpec::BOOKS_FIXTURES } + { 'books' => Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup } end let(:constructor_options) { super().merge(data: data) } @@ -141,7 +141,7 @@ describe 'with data: an Array' do let(:data) do - Cuprum::Collections::RSpec::BOOKS_FIXTURES + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup end let(:collection_options) { super().merge(data: data) } @@ -150,7 +150,7 @@ context 'when initialized with data: value' do let(:data) do - { 'books' => Cuprum::Collections::RSpec::BOOKS_FIXTURES } + { 'books' => Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup } end let(:constructor_options) { super().merge(data: data) } diff --git a/spec/cuprum/collections/commands/find_one_matching_spec.rb b/spec/cuprum/collections/commands/find_one_matching_spec.rb index ba109c1..ccf8bb7 100644 --- a/spec/cuprum/collections/commands/find_one_matching_spec.rb +++ b/spec/cuprum/collections/commands/find_one_matching_spec.rb @@ -71,7 +71,7 @@ end context 'when there are many entities' do - let(:data) { Cuprum::Collections::RSpec::BOOKS_FIXTURES } + let(:data) { Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup } describe 'with attributes: a Hash that does not match any entities' do let(:attributes) { { 'author' => 'Jules Verne' } } diff --git a/spec/integration/commands/create_spec.rb b/spec/integration/commands/create_spec.rb index 192085d..75bae2d 100644 --- a/spec/integration/commands/create_spec.rb +++ b/spec/integration/commands/create_spec.rb @@ -11,8 +11,10 @@ RSpec.describe Spec::Support::Commands::Create do subject(:command) { described_class.new(collection) } + let(:data) do + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup + end let(:collection_name) { 'books' } - let(:data) { Cuprum::Collections::RSpec::BOOKS_FIXTURES.dup } let(:collection_options) do { name: collection_name, diff --git a/spec/integration/commands/destroy_spec.rb b/spec/integration/commands/destroy_spec.rb index 7c3f7a7..5736ee3 100644 --- a/spec/integration/commands/destroy_spec.rb +++ b/spec/integration/commands/destroy_spec.rb @@ -8,8 +8,10 @@ RSpec.describe Spec::Support::Commands::Destroy do subject(:command) { described_class.new(collection) } + let(:data) do + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup + end let(:collection_name) { 'books' } - let(:data) { Cuprum::Collections::RSpec::BOOKS_FIXTURES.dup } let(:collection_options) do { name: collection_name, diff --git a/spec/integration/commands/index_spec.rb b/spec/integration/commands/index_spec.rb index 9a1b9c5..76f00d8 100644 --- a/spec/integration/commands/index_spec.rb +++ b/spec/integration/commands/index_spec.rb @@ -8,8 +8,10 @@ RSpec.describe Spec::Support::Commands::Index do subject(:command) { described_class.new(collection) } + let(:data) do + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup + end let(:collection_name) { 'books' } - let(:data) { Cuprum::Collections::RSpec::BOOKS_FIXTURES.dup } let(:collection_options) do { name: collection_name, diff --git a/spec/integration/commands/show_spec.rb b/spec/integration/commands/show_spec.rb index a07e996..9fd723b 100644 --- a/spec/integration/commands/show_spec.rb +++ b/spec/integration/commands/show_spec.rb @@ -8,8 +8,10 @@ RSpec.describe Spec::Support::Commands::Show do subject(:command) { described_class.new(collection) } + let(:data) do + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup + end let(:collection_name) { 'books' } - let(:data) { Cuprum::Collections::RSpec::BOOKS_FIXTURES.dup } let(:collection_options) do { name: collection_name, diff --git a/spec/integration/commands/update_spec.rb b/spec/integration/commands/update_spec.rb index e6e48bc..7ea5610 100644 --- a/spec/integration/commands/update_spec.rb +++ b/spec/integration/commands/update_spec.rb @@ -11,8 +11,10 @@ RSpec.describe Spec::Support::Commands::Update do subject(:command) { described_class.new(collection) } + let(:data) do + Cuprum::Collections::RSpec::Fixtures::BOOKS_FIXTURES.dup + end let(:collection_name) { 'books' } - let(:data) { Cuprum::Collections::RSpec::BOOKS_FIXTURES.dup } let(:collection_options) do { name: collection_name,