Skip to content

Commit

Permalink
feat: Improve undefined method msg for style builder (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephannv authored Sep 29, 2024
1 parent b47ba00 commit 146d55d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/phlex/variants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def variants(&)
def defaults(**variants)
view_class::STYLE_DEFAULTS.merge!(variants)
end

def method_missing(method, *args, &) # standard:disable Style/MissingRespondToMissing
message = "undefined method '#{method}' for an instance of Phlex::Variants::StyleBuilder. The available methods are: 'base', 'variants' and 'defaults'"
raise NoMethodError, message
end
end

# @api private
Expand Down
14 changes: 14 additions & 0 deletions spec/phlex/variants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ def view_template
expect(actual_classes).to eq expected_classes
end

it "explains propery when calling undefined method from StyleBuilder" do
msg = "undefined method 'color' for an instance of Phlex::Variants::StyleBuilder. The available methods are: 'base', 'variants' and 'defaults'"

expect do
phlex_class do
style do
color do
red "bg-red-200 hover:bg-red-400"
end
end
end
end.to raise_error(NoMethodError, msg)
end

def phlex_class(&)
Class.new(Phlex::HTML) do
include Phlex::Variants
Expand Down

0 comments on commit 146d55d

Please sign in to comment.