Back to Repositories

Testing Font Face Mixin Implementation in Bourbon

This test suite validates the font-face mixin functionality in Bourbon, focusing on proper CSS @font-face rule generation. It ensures correct font family declarations and source URL formatting for web font implementations.

Test Coverage Overview

The test suite provides comprehensive coverage of the font-face mixin’s default behavior. It verifies:

  • Proper @font-face rule generation
  • Font family name declaration
  • Multiple font source URL formatting
  • WOFF and WOFF2 format support

Implementation Analysis

The testing approach utilizes RSpec’s describe/context structure to organize font-face related tests. It leverages custom parser support for analyzing CSS output and implements expectation matchers for ruleset validation.

The implementation focuses on string concatenation for complex CSS rule verification and employs before hooks for file parsing setup.

Technical Details

  • Testing Framework: RSpec
  • Custom Support: ParserSupport module
  • File Processing: Library file parsing
  • Matcher Types: Custom ruleset matchers
  • Setup: Global before hook configuration

Best Practices Demonstrated

The test suite exemplifies several testing best practices including isolated test contexts, clear expectation definitions, and proper test setup separation. It demonstrates effective use of RSpec’s context blocks for organizing related tests and employs custom matchers for readable CSS rule validation.

The implementation shows proper separation of concerns between test setup and assertions.

thoughtbot/bourbon

spec/bourbon/library/font_face_spec_1.rb

            
require "spec_helper"

describe "font-face" do
  before(:all) do
    ParserSupport.parse_file("library/font-face-1")
  end

  context "called with defaults" do
    it "outputs defaults" do
      ruleset = 'font-family: "source-sans-pro"; ' +
                'src: url("/fonts/source-sans-pro/source-sans-pro-regular.woff2") format("woff2"), url("/fonts/source-sans-pro/source-sans-pro-regular.woff") format("woff");'

      expect("@font-face").to have_ruleset(ruleset)
    end
  end
end