Skip to content

Commit

Permalink
More tests, fix bugs, make config not blow up if not initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
edk committed Feb 23, 2024
1 parent e1f7830 commit 3b902fd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source "https://rubygems.org"
gemspec

group :development, :test do
gem "pry"
gem "standard"
gem "standard-rails"
gem "standard-performance"
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GEM
thor (>= 0.14.0)
ast (2.4.2)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.2.3)
crass (1.0.6)
erubi (1.12.0)
Expand All @@ -37,6 +38,7 @@ GEM
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
method_source (1.0.0)
minitest (5.22.2)
nokogiri (1.16.2-aarch64-linux)
racc (~> 1.4)
Expand All @@ -54,6 +56,9 @@ GEM
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
racc (1.7.3)
rack (3.0.9.1)
rails-dom-testing (2.2.0)
Expand Down Expand Up @@ -122,6 +127,7 @@ DEPENDENCIES
appraisal
heroic_icons!
minitest (>= 5.16)
pry
standard
standard-performance
standard-rails
Expand Down
1 change: 1 addition & 0 deletions heroic_icons.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "minitest", ">= 5.16"
spec.add_development_dependency "appraisal"
spec.add_development_dependency "pry"
end
13 changes: 8 additions & 5 deletions lib/heroic_icons/config.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# lib/heroic_icons/config.rb

module HeroicIcons
class << self
attr_accessor :configuration
end
def configuration
@configuration ||= Configuration.new
end

def self.configure
self.configuration ||= Configuration.new
yield(configuration)
def configure
yield(configuration)
end
end

class Configuration
Expand Down
6 changes: 4 additions & 2 deletions lib/heroic_icons/heroic_icons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class Icons
# Updated method signature to accept name and a hash for additional options
def icon(name, **options)
# append or replace? hmmm.
if options[:override_class].present? || options[:class].blank?
options[:class] = HeroicIcons.configuration.default_classes
if options[:override_class].present?
options[:class] = options.delete(:override_class)
elsif options[:class].present?
options[:class] = "#{HeroicIcons.configuration.default_classes} #{options[:class]}"
else
options[:class] = HeroicIcons.configuration.default_classes
end
file_path = determine_file_path(name, options)

Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "heroic_icons"
require "pry"

require "minitest/autorun"
19 changes: 19 additions & 0 deletions test/test_heroic_icons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ def test_that_it_has_a_version_number
refute_nil ::HeroicIcons::VERSION
end

def test_icon_with_default_classes
HeroicIcons.configure do |config|
config.default_classes = "default-class"
end

rendered_icon = HeroicIcons::Icons.new.icon("plus")
assert_includes rendered_icon, "default-class"
end

def test_icon_with_default_class_override
HeroicIcons.configure do |config|
config.default_classes = "default-class"
end

rendered_icon = HeroicIcons::Icons.new.icon("plus", override_class: "override-class")
refute_includes rendered_icon, "default-class"
assert_includes rendered_icon, "override-class"
end

def test_icon_not_found
assert_raises(HeroicIcons::IconNotFound) do
HeroicIcons::Icons.new.icon("nonexistent")
Expand Down

0 comments on commit 3b902fd

Please sign in to comment.