Back to Repositories

Testing Font Source Declaration Utilities in Bourbon Framework

This test suite validates the font-source-declaration utility in Bourbon, focusing on proper font URL generation with and without asset pipeline integration. It ensures correct formatting of font source declarations for different file formats and pipeline configurations.

Test Coverage Overview

The test suite provides comprehensive coverage of font source declaration functionality:

  • Tests font URL generation with asset pipeline enabled
  • Verifies URL formatting without pipeline integration
  • Validates proper format string inclusion for different font types
  • Ensures correct concatenation of multiple font sources

Implementation Analysis

The testing approach utilizes RSpec’s context-based structure to isolate pipeline and non-pipeline scenarios. It leverages custom parser support for preprocessing Sass/SCSS files and implements expectation matchers for CSS rule validation.

The implementation uses RSpec’s describe/context/it blocks for clear test organization and custom matchers for CSS rule verification.

Technical Details

  • RSpec testing framework
  • Custom ParserSupport module for Sass parsing
  • have_rule matcher for CSS validation
  • Before hooks for test setup
  • String concatenation for complex CSS rules

Best Practices Demonstrated

The test suite exemplifies several testing best practices including isolation of test scenarios, clear context separation, and focused test cases. It demonstrates proper setup handling through before blocks and maintains readable test structure through appropriate string formatting and expectation clarity.

  • Isolated test contexts
  • Clear scenario separation
  • Focused test cases
  • Proper setup management

thoughtbot/bourbon

spec/bourbon/utilities/font_source_declaration_spec.rb

            
require "spec_helper"

describe "font-source-declaration" do
  before(:all) do
    ParserSupport.parse_file("utilities/font-source-declaration")
  end

  context "called with pipeline" do
    it "returns pipeline path" do
      rule = 'src: font-url("b.woff2") format("woff2"), ' +
             'font-url("b.woff") format("woff")'
      expect(".has-pipeline").to have_rule(rule)
    end
  end

  context "called with no pipeline" do
    it "does not return pipeline path" do
      rule = 'src: url("b.woff2") format("woff2"), ' +
             'url("b.woff") format("woff")'
      expect(".no-pipeline").to have_rule(rule)
    end
  end
end