Testing Type Model Implementation in DevDocs Documentation System
This test suite validates the core Type model functionality in the DevDocs documentation system. It ensures proper handling of documentation type names, counts, and slug generation while maintaining data integrity through comprehensive unit testing.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
freecodecamp/devdocs
test/lib/docs/core/models/type_test.rb
require_relative '../../../../test_helper'
require_relative '../../../../../lib/docs'
class DocsTypeTest < Minitest::Spec
Type = Docs::Type
describe ".new" do
it "stores a name" do
assert_equal 'name', Type.new('name').name
end
it "stores a count" do
assert_equal 10, Type.new(nil, 10).count
end
it "defaults the count to 0" do
assert_equal 0, Type.new.count
end
end
describe "#slug" do
it "parameterizes the #name" do
name = 'a.b c\/%?#'
assert_equal 'a-b-c', Type.new(name).slug
end
end
describe "#as_json" do
it "returns a hash with the name, count and slug" do
as_json = Type.new('name', 10).as_json
assert_instance_of Hash, as_json
assert_equal [:name, :count, :slug], as_json.keys
assert_equal ['name', 10, 'name'], as_json.values
end
end
end