Class: Azebiki::Checker::MyHaveSelector

Inherits:
Webrat::Matchers::HaveSelector
  • Object
show all
Defined in:
lib/azebiki/azebiki.rb

Instance Method Summary collapse

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
# 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 == :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



88
89
90
91
92
# File 'lib/azebiki/azebiki.rb', line 88

def add_content_condition_to(query)
  if @options[:content] and @expected != "meta"
    query << "[contains(., #{xpath_escape(@options[:content])})]"
  end
end

#matches?(stringlike, &block) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
102
103
# File 'lib/azebiki/azebiki.rb', line 94

def matches?(stringlike, &block)
  @block ||= block
  matched = matches(stringlike)

  if @options[:count]
    matched.size == @options[:count] && (!@block || @block.call(matched))
  else
    matched.any? && (!@block || @block.call(matched))
  end
end

#tag_inspectObject



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 = @options.dup
  count = options.delete(:count)
  content = options.delete(:content) unless @expected == "meta"

  html = "<#{@expected}"
  options.each do |k,v|
    html << " #{k}='#{v}'"
  end

  html << ">#{content}</#{@expected}>"

  html
end