Class: Azebiki::Checker::MyHaveSelector
- Inherits:
-
Webrat::Matchers::HaveSelector
- Object
- Webrat::Matchers::HaveSelector
- Azebiki::Checker::MyHaveSelector
- Defined in:
- lib/azebiki/azebiki.rb
Instance Method Summary collapse
- #add_attributes_conditions_to(query) ⇒ Object
- #add_content_condition_to(query) ⇒ Object
- #matches?(stringlike, &block) ⇒ Boolean
- #nokogiri_matches(stringlike) ⇒ Object
- #tag_inspect ⇒ Object
Instance Method Details
#add_attributes_conditions_to(query) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/azebiki/azebiki.rb', line 68 def add_attributes_conditions_to(query) attribute_conditions = [] @options.each do |key, value| next if key == :failure_message next if key == :not next if key == :content unless @expected == "meta" next if key == :count if value.is_a?(Hash) func, match = value.keys.first, value.values.first attribute_conditions << "#{func}(@#{key}, #{xpath_escape(match)})" else attribute_conditions << "@#{key} = #{xpath_escape(value)}" end end if attribute_conditions.any? query << "[#{attribute_conditions.join(' and ')}]" end end |
#add_content_condition_to(query) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/azebiki/azebiki.rb', line 89 def add_content_condition_to(query) if @options[:content] and @expected != "meta" if @options[:content].is_a?(Hash) and @options[:content][:regex] query << "[regex(., #{xpath_escape(@options[:content][:to_s])})]" else query << "[contains(., #{xpath_escape(@options[:content])})]" end end end |
#matches?(stringlike, &block) ⇒ Boolean
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/azebiki/azebiki.rb', line 119 def matches?(stringlike, &block) @block ||= block matched = matches(stringlike) result = if @options[:count] matched.size == @options[:count] && (!@block || @block.call(matched)) else matched.any? && (!@block || @block.call(matched)) end if @options[:not] !result else result end end |
#nokogiri_matches(stringlike) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/azebiki/azebiki.rb', line 99 def nokogiri_matches(stringlike) if Nokogiri::XML::NodeSet === stringlike @query = query.gsub(%r'^//', './/') else @query = query end (@query) args = [@query] args << Class.new { def self.regex(node_set, regex) node_set.find_all { |node| node.content =~ /#{regex}/i } end } @document = Webrat::XML.document(stringlike) @document.xpath(*args) end |
#tag_inspect ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/azebiki/azebiki.rb', line 53 def tag_inspect = @options.dup count = .delete(:count) content = .delete(:content) unless @expected == "meta" html = "<#{@expected}" .each do |k,v| html << " #{k}='#{v}'" end html << ">#{content}</#{@expected}>" html end |