Skip to content

Commit

Permalink
Refactor fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepingkingstudios committed Nov 28, 2023
1 parent fced2c5 commit 9d1a784
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 96 deletions.
1 change: 1 addition & 0 deletions lib/cuprum/collections/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/cuprum/collections/rspec/contracts/query_contracts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
167 changes: 85 additions & 82 deletions lib/cuprum/collections/rspec/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/cuprum/collections/basic/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion spec/cuprum/collections/basic/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/cuprum/collections/basic/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand All @@ -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) }

Expand Down Expand Up @@ -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) }

Expand All @@ -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) }

Expand Down
2 changes: 1 addition & 1 deletion spec/cuprum/collections/commands/find_one_matching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' } }
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/commands/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/commands/destroy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/commands/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/commands/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/commands/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9d1a784

Please sign in to comment.