Skip to content

Commit

Permalink
Implement Slop#respond_to_missing?. (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
knu committed Nov 6, 2014
1 parent e7c4756 commit a655360
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
=== 1.6.5 / unreleased

==== Features

* Implement Slop#respond_to_missing?. (#1176)

==== Bug fixes

* Fix a bug where CFLAGS passed in are dropped.
Expand Down
8 changes: 8 additions & 0 deletions lib/nokogiri/decorators/slop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def method_missing name, *args, &block
super if list.empty?
list.length == 1 ? list.first : list
end

def respond_to_missing? name, include_private = false
prefix = implied_xpath_context

list = xpath("#{prefix}#{name.to_s.sub(/^_/, '')}")

!list.empty?
end
end
end
end
8 changes: 6 additions & 2 deletions test/decorators/test_slop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ def test_description_tag
<description>this is the foo thing</description>
</item>
eoxml
assert doc.item.title
assert doc.item._description, 'should have description'
assert doc.item.respond_to?(:title)
assert_equal 'foo', doc.item.title.text
assert doc.item.respond_to?(:_description), 'should have description'
assert 'this is the foo thing', doc.item._description.text
assert !doc.item.respond_to?(:foo)
assert_raise(NoMethodError) { doc.item.foo }
end
end
end

0 comments on commit a655360

Please sign in to comment.