Skip to content

Commit

Permalink
Merge pull request #131 from markedmondson/better-exception
Browse files Browse the repository at this point in the history
Return the property value in an empty value rule set
  • Loading branch information
grosser committed Sep 16, 2022
2 parents d6a04b3 + 96ec6cf commit 0bcc819
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

### Unreleased

* Improve exception message for missing value [#131](https://github.com/premailer/css_parser/pull/131)
* `:rule_set_exceptions` option added [#132](https://github.com/premailer/css_parser/pull/132)

### Version 1.11.0
Expand Down
2 changes: 2 additions & 0 deletions lib/css_parser/rule_set.rb
Expand Up @@ -93,6 +93,8 @@ def []=(property, value)
else
declarations[property] = Value.new(value)
end
rescue ArgumentError => e
raise e.exception, "#{property} #{e.message}"
end
alias add_declaration! []=

Expand Down
6 changes: 6 additions & 0 deletions test/rule_set/declarations/test_value.rb
Expand Up @@ -102,6 +102,12 @@ class RuleSetProperyTest < Minitest::Test

assert_equal true, CssParser::RuleSet::Declarations::Value.new('value').value.frozen?
end

it 'raises an exception when the value is empty' do
assert_raises ArgumentError do
CssParser::RuleSet::Declarations::Value.new
end
end
end

describe '#to_s' do
Expand Down
8 changes: 8 additions & 0 deletions test/rule_set/test_declarations.rb
Expand Up @@ -68,6 +68,14 @@ class RuleSetDeclarationsTest < Minitest::Test

assert_equal declarations.method(:[]=), declarations.method(:add_declaration!)
end

it 'raises an exception including the property when the value is empty' do
declarations = CssParser::RuleSet::Declarations.new

assert_raises ArgumentError, 'foo value is empty' do
declarations['foo'] = '!important'
end
end
end

describe '#[]' do
Expand Down

0 comments on commit 0bcc819

Please sign in to comment.