Back to Repositories

Testing Border Style Declarations in Bourbon

This test suite validates the border-style functionality in the Bourbon Sass library, ensuring proper CSS border style application across different usage patterns. The tests verify both single and multiple border style declarations, along with handling of null values.

Test Coverage Overview

The test suite provides comprehensive coverage of border-style implementations, including single-style, two-style, three-style, and four-style declarations. Key functionality tested includes:
  • Single style application to all borders
  • Alternating styles for two-value declarations
  • Three-value border style distribution
  • Four-value explicit border styling
  • Null value handling in border declarations

Implementation Analysis

The testing approach utilizes RSpec’s context-based structure to organize different border-style scenarios. The implementation leverages custom matchers (have_rule and have_ruleset) to verify CSS output patterns. Each test case validates specific border-style declarations against expected CSS output rules.

Pattern matching focuses on exact string comparison for CSS rules, with particular attention to proper formatting and spacing in the generated CSS.

Technical Details

Testing tools and configuration:
  • RSpec testing framework
  • Custom ParserSupport module for file parsing
  • Custom matchers for CSS rule validation
  • Before hooks for test setup
  • Specific test file organization under library/border-style

Best Practices Demonstrated

The test suite exemplifies several testing best practices for Sass library validation. Each test case is clearly isolated with specific contexts, maintaining single responsibility principle. The tests demonstrate proper setup isolation, clear naming conventions, and comprehensive edge case coverage including null value handling.

The code organization follows RSpec conventions with descriptive context blocks and expectation statements that clearly communicate the intended behavior.

thoughtbot/bourbon

spec/bourbon/library/border_style_spec.rb

            
require "spec_helper"

describe "border-style" do
  before(:all) do
    ParserSupport.parse_file("library/border-style")
  end

  context "called with one style" do
    it "applies same style to all sides" do
      rule = "border-style: solid"

      expect(".border-style-all").to have_rule(rule)
    end
  end

  context "called with two styles" do
    it "applies to alternating sides" do
      rule = "border-style: dotted dashed"

      expect(".border-style-alternate").to have_rule(rule)
    end
  end

  context "called with three styles" do
    it "applies second style to left and right" do
      rule = "border-style: dashed double solid"

      expect(".border-style-implied-left").to have_rule(rule)
    end
  end

  context "called with four styles" do
    it "applies different styles to all sides" do
      rule = "border-style: dotted groove ridge none"

      expect(".border-style-explicit").to have_rule(rule)
    end
  end

  context "called with null values" do
    it "writes rules for other three" do
      ruleset = "border-top-style: inset; " +
                "border-right-style: none; " +
                "border-left-style: double;"
      bad_rule = "border-bottom-style: null;"

      expect(".border-style-false-third").to have_ruleset(ruleset)
      expect(".border-style-false-third").to_not have_rule(bad_rule)
    end
  end
end