Compare commits

...

4 commits

Author SHA1 Message Date
3b5b13c172 Fewer slowest examples in RSpec, cuz these are fast and it's fine
I want to not turn it off entirely, so that if there's a nasty one it
becomes visible, but we don't need all that vertical space for this
small test suite rn!
2024-10-21 16:47:51 -07:00
5b1d1f0695 Add assets to modeling tests, and also uhh some other fixes
I forget, there was some tricky debugging about getting the fixtures
right, I think the previous commit doesn't *actually* pass from a clean
setting. Ah well, looks good now!
2024-10-21 16:46:10 -07:00
e92e315743 Move modeling tests to RSpec
Also note the jsbundling bump, that was so I can us the relatively-new
`SKIP_YARN_INSTALL=1` flag when running tests, to be a bit faster.
2024-10-21 16:03:58 -07:00
eb2fb125b9 Basic modeling test!
Just getting a basic foothold here. I'm thinking about moving this to
RSpec, cuz I feel like the assertions are gonna get pretty specific
and groupable.
2024-10-21 15:29:22 -07:00
17 changed files with 600 additions and 2 deletions

1
.gitignore vendored
View file

@ -4,6 +4,7 @@ log/*.log
tmp/**/*
.env
.env.*
/spec/examples.txt
/app/assets/builds/*
!/app/assets/builds/.keep

1
.rspec Normal file
View file

@ -0,0 +1 @@
--require spec_helper

View file

@ -19,7 +19,7 @@ gem 'haml', '~> 6.1', '>= 6.1.1'
gem 'sass-rails', '~> 6.0'
gem 'terser', '~> 1.1', '>= 1.1.17'
gem 'react-rails', '~> 2.7', '>= 2.7.1'
gem 'jsbundling-rails', '~> 1.1'
gem 'jsbundling-rails', '~> 1.3'
gem 'turbo-rails', '~> 2.0'
# For authentication.
@ -86,3 +86,8 @@ gem "shell", "~> 0.8.1"
# For workspace autocomplete.
gem "solargraph", "~> 0.50.0", group: :development
gem "solargraph-rails", "~> 1.1", group: :development
# For automated tests.
group :development, :test do
gem "rspec-rails", "~> 7.0"
end

View file

@ -376,6 +376,23 @@ GEM
reverse_markdown (2.1.1)
nokogiri
rexml (3.3.7)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (7.0.1)
actionpack (>= 7.0)
activesupport (>= 7.0)
railties (>= 7.0)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.66.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
@ -503,7 +520,7 @@ DEPENDENCIES
haml (~> 6.1, >= 6.1.1)
http_accept_language (~> 2.1, >= 2.1.1)
httparty (~> 0.22.0)
jsbundling-rails (~> 1.1)
jsbundling-rails (~> 1.3)
letter_opener (~> 1.8, >= 1.8.1)
memory_profiler (~> 1.0)
mysql2 (~> 0.5.5)
@ -518,6 +535,7 @@ DEPENDENCIES
rails-i18n (~> 7.0, >= 7.0.7)
rdiscount (~> 2.2, >= 2.2.7.1)
react-rails (~> 2.7, >= 2.7.1)
rspec-rails (~> 7.0)
sanitize (~> 6.0, >= 6.0.2)
sass-rails (~> 6.0)
sentry-rails (~> 5.12)

3
spec/fixtures/colors.yml vendored Normal file
View file

@ -0,0 +1,3 @@
purple:
id: 57
name: purple

3
spec/fixtures/species.yml vendored Normal file
View file

@ -0,0 +1,3 @@
chia:
id: 7
name: chia

282
spec/fixtures/zones.yml vendored Normal file
View file

@ -0,0 +1,282 @@
music:
id: 1
depth: 1
type_id: 4
label: Music
plain_label: music
soundeffects:
id: 2
depth: 2
type_id: 4
label: Sound Effects
plain_label: soundeffects
background:
id: 3
depth: 3
type_id: 3
label: Background
plain_label: background
biologyeffects:
id: 4
depth: 6
type_id: 1
label: Biology Effects
plain_label: biologyeffects
hindbiology:
id: 5
depth: 7
type_id: 1
label: Hind Biology
plain_label: hindbiology
markings:
id: 31
depth: 35
type_id: 2
label: Markings
plain_label: markings
hinddisease:
id: 7
depth: 9
type_id: 1
label: Hind Disease
plain_label: hinddisease
hindcover:
id: 8
depth: 10
type_id: 2
label: Hind Cover
plain_label: hindcover
hindtransientbiology:
id: 9
depth: 11
type_id: 1
label: Hind Transient Biology
plain_label: hindtransientbiology
hinddrippings:
id: 10
depth: 12
type_id: 1
label: Hind Drippings
plain_label: hinddrippings
backpack:
id: 11
depth: 13
type_id: 2
label: Backpack
plain_label: backpack
wingstransientbiology:
id: 12
depth: 14
type_id: 1
label: Wings Transient Biology
plain_label: wingstransientbiology
wings:
id: 13
depth: 15
type_id: 2
label: Wings
plain_label: wings
hairback:
id: 14
depth: 17
type_id: 1
label: Hair Back
plain_label: hairback
body:
id: 15
depth: 18
type_id: 1
label: Body
plain_label: body
bodydisease:
id: 17
depth: 20
type_id: 1
label: Body Disease
plain_label: bodydisease
feettransientbiology:
id: 18
depth: 21
type_id: 1
label: Feet Transient Biology
plain_label: feettransientbiology
shoes:
id: 19
depth: 22
type_id: 2
label: Shoes
plain_label: shoes
lowerbodytransientbiology:
id: 20
depth: 23
type_id: 1
label: Lower-body Transient Biology
plain_label: lowerbodytransientbiology
trousers:
id: 21
depth: 24
type_id: 2
label: Trousers
plain_label: trousers
upperbodytransientbiology:
id: 22
depth: 25
type_id: 1
label: Upper-body Transient Biology
plain_label: upperbodytransientbiology
shirtdress:
id: 23
depth: 26
type_id: 2
label: Shirt/Dress
plain_label: shirtdress
necklace:
id: 24
depth: 28
type_id: 2
label: Necklace
plain_label: necklace
gloves:
id: 25
depth: 29
type_id: 2
label: Gloves
plain_label: gloves
jacket:
id: 26
depth: 30
type_id: 2
label: Jacket
plain_label: jacket
collar:
id: 27
depth: 31
type_id: 2
label: Collar
plain_label: collar
bodydrippings:
id: 28
depth: 32
type_id: 1
label: Body Drippings
plain_label: bodydrippings
ruff:
id: 29
depth: 33
type_id: 1
label: Ruff
plain_label: ruff
head:
id: 30
depth: 34
type_id: 1
label: Head
plain_label: head
headdisease:
id: 32
depth: 36
type_id: 1
label: Head Disease
plain_label: headdisease
eyes:
id: 33
depth: 37
type_id: 1
label: Eyes
plain_label: eyes
mouth:
id: 34
depth: 38
type_id: 1
label: Mouth
plain_label: mouth
glasses:
id: 35
depth: 41
type_id: 2
label: Glasses
plain_label: glasses
earrings:
id: 41
depth: 45
type_id: 2
label: Earrings
plain_label: earrings
hairfront:
id: 37
depth: 40
type_id: 1
label: Hair Front
plain_label: hairfront
headtransientbiology:
id: 38
depth: 42
type_id: 1
label: Head Transient Biology
plain_label: headtransientbiology
headdrippings:
id: 39
depth: 43
type_id: 1
label: Head Drippings
plain_label: headdrippings
hat:
id: 50
depth: 16
type_id: 2
label: Hat
plain_label: hat
righthanditem:
id: 49
depth: 5
type_id: 2
label: Right-hand Item
plain_label: righthanditem
lefthanditem:
id: 43
depth: 47
type_id: 2
label: Left-hand Item
plain_label: lefthanditem
higherforegrounditem:
id: 44
depth: 49
type_id: 3
label: Higher Foreground Item
plain_label: higherforegrounditem
lowerforegrounditem:
id: 45
depth: 50
type_id: 3
label: Lower Foreground Item
plain_label: lowerforegrounditem
static:
id: 46
depth: 48
type_id: 2
label: Static
plain_label: static
thoughtbubble:
id: 47
depth: 51
type_id: 3
label: Thought Bubble
plain_label: thoughtbubble
backgrounditem:
id: 48
depth: 4
type_id: 3
label: Background Item
plain_label: backgrounditem
belt:
id: 51
depth: 27
type_id: 2
label: Belt
plain_label: belt
foreground:
id: 52
depth: 52
type_id: 3
label: Foreground
plain_label: foreground

16
spec/mocks/custom_pets.rb Normal file
View file

@ -0,0 +1,16 @@
# We replace Neopets::CustomPets methods with a mocked implementation.
module Neopets::CustomPets
def self.fetch_viewer_data(pet_name, ...)
File.open(Rails.root / "spec/mocks/custom_pets/#{pet_name}.json") do |file|
HashWithIndifferentAccess.new JSON.load(file)
end
end
def self.fetch_metadata(...)
raise NotImplementedError
end
def self.fetch_image_hash(pet_name, ...)
"m:#{pet_name}"[0, 8] # A mock hash, like `m:thyass` for "thyassa".
end
end

View file

@ -0,0 +1,60 @@
{
"custom_pet": {
"name": "thyassa",
"owner": "donna",
"slot": 1.0,
"scale": 0.5,
"muted": false,
"body_id": 212.0,
"species_id": 7.0,
"color_id": 57.0,
"alt_style": false,
"alt_color": 57.0,
"style_closet_id": null,
"biology_by_zone": {
"37": {
"part_id": 10083.0,
"zone_id": 37.0,
"asset_url": "https://images.neopets.com/cp/bio/swf/000/000/010/10083_8a1111a13f.swf",
"manifest": "https://images.neopets.com/cp/bio/data/000/000/010/10083_8a1111a13f/manifest.json",
"zones_restrict": "0000000000000000000000000000000000000000000000000000"
},
"15": {
"part_id": 11613.0,
"zone_id": 15.0,
"asset_url": "https://images.neopets.com/cp/bio/swf/000/000/011/11613_f7d8d377ab.swf",
"manifest": "https://images.neopets.com/cp/bio/data/000/000/011/11613_f7d8d377ab/manifest.json",
"zones_restrict": "0000000000000000000000000000000000000000000000000000"
},
"34": {
"part_id": 14187.0,
"zone_id": 34.0,
"asset_url": "https://images.neopets.com/cp/bio/swf/000/000/014/14187_0e65c2082f.swf",
"manifest": "https://images.neopets.com/cp/bio/data/000/000/014/14187_0e65c2082f/manifest.json",
"zones_restrict": "0000000000000000000000000000000000000000000000000000"
},
"33": {
"part_id": 14189.0,
"zone_id": 33.0,
"asset_url": "https://images.neopets.com/cp/bio/swf/000/000/014/14189_102e4991e9.swf",
"manifest": "https://images.neopets.com/cp/bio/data/000/000/014/14189_102e4991e9/manifest.json",
"zones_restrict": "0000000000000000000000000000000000000000000000000000"
}
},
"equipped_by_zone": [
],
"original_biology": [
]
},
"closet_items": [
],
"object_info_registry": [
],
"object_asset_registry": [
]
}

63
spec/models/pet_spec.rb Normal file
View file

@ -0,0 +1,63 @@
require 'rails_helper'
require_relative '../mocks/custom_pets'
RSpec.describe Pet, type: :model do
fixtures :colors, :species, :zones
context "#load" do
context "for thyassa, the Purple Chia" do
subject { Pet.load "thyassa" }
it "is named thyassa" do
expect(subject.name).to eq("thyassa")
end
it "has a new Purple Chia pet type" do
expect(subject.pet_type.new_record?).to be true
expect(subject.pet_type.color).to eq Color.find_by_name!("purple")
expect(subject.pet_type.species).to eq Species.find_by_name!("chia")
expect(subject.pet_type.body_id).to eq 212
expect(subject.pet_type.image_hash).to eq "m:thyass"
end
it "has a new unlabeled Purple Chia pet state" do
expect(subject.pet_state.new_record?).to be true
expect(subject.pet_state.color).to eq Color.find_by_name!("purple")
expect(subject.pet_state.species).to eq Species.find_by_name!("chia")
expect(subject.pet_state.pose).to eq "UNKNOWN"
end
it "has new assets for the biology layers" do
subject.save! # TODO: I wish this were set up before saving.
s = subject.pet_state.swf_assets.sort_by(&:id)
expect(s.size).to eq 4
expect(s[0].type).to eq "biology"
expect(s[0].remote_id).to eq 10083
expect(s[0].zone_id).to eq 37
expect(s[0].url).to eq "https://images.neopets.com/cp/bio/swf/000/000/010/10083_8a1111a13f.swf"
expect(s[0].manifest_url).to eq "https://images.neopets.com/cp/bio/data/000/000/010/10083_8a1111a13f/manifest.json"
expect(s[0].zones_restrict).to eq "0000000000000000000000000000000000000000000000000000"
expect(s[1].type).to eq "biology"
expect(s[1].remote_id).to eq 11613
expect(s[1].zone_id).to eq 15
expect(s[1].url).to eq "https://images.neopets.com/cp/bio/swf/000/000/011/11613_f7d8d377ab.swf"
expect(s[1].manifest_url).to eq "https://images.neopets.com/cp/bio/data/000/000/011/11613_f7d8d377ab/manifest.json"
expect(s[1].zones_restrict).to eq "0000000000000000000000000000000000000000000000000000"
expect(s[2].type).to eq "biology"
expect(s[2].remote_id).to eq 14187
expect(s[2].zone_id).to eq 34
expect(s[2].url).to eq "https://images.neopets.com/cp/bio/swf/000/000/014/14187_0e65c2082f.swf"
expect(s[2].manifest_url).to eq "https://images.neopets.com/cp/bio/data/000/000/014/14187_0e65c2082f/manifest.json"
expect(s[2].zones_restrict).to eq "0000000000000000000000000000000000000000000000000000"
expect(s[3].type).to eq "biology"
expect(s[3].remote_id).to eq 14189
expect(s[3].zone_id).to eq 33
expect(s[3].url).to eq "https://images.neopets.com/cp/bio/swf/000/000/014/14189_102e4991e9.swf"
expect(s[3].manifest_url).to eq "https://images.neopets.com/cp/bio/data/000/000/014/14189_102e4991e9/manifest.json"
expect(s[3].zones_restrict).to eq "0000000000000000000000000000000000000000000000000000"
end
end
end
end

68
spec/rails_helper.rb Normal file
View file

@ -0,0 +1,68 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
# Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file
# that will avoid rails generators crashing because migrations haven't been run yet
# return unless Rails.env.test?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
abort e.to_s.strip
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_paths = [
Rails.root.join('spec/fixtures')
]
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# You can uncomment this line to turn off ActiveRecord support entirely.
# config.use_active_record = false
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, type: :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://rspec.info/features/7-0/rspec-rails
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
end

78
spec/spec_helper.rb Normal file
View file

@ -0,0 +1,78 @@
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
# have no way to turn it off -- the option exists only for backwards
# compatibility in RSpec 3). It causes shared context metadata to be
# inherited by the metadata hash of host groups and examples, rather than
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# This allows you to limit a spec run to individual examples or groups
# you care about by tagging them with `:focus` metadata. When nothing
# is tagged with `:focus`, all examples get run. RSpec also provides
# aliases for `it`, `describe`, and `context` that include `:focus`
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
config.filter_run_when_matching :focus
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = "doc"
end
# Print some of the slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 2
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
end

BIN
vendor/cache/rspec-core-3.13.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/rspec-mocks-3.13.2.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/rspec-rails-7.0.1.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/rspec-support-3.13.1.gem vendored Normal file

Binary file not shown.