class Wrapybara::TableCell

Attributes

element[R]
parent[R]

Public Class Methods

new(parent, *args) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 7
def initialize(parent, *args)
        args = args.first if args.first.is_a?(Array)
        
        @parent = parent
        t_what = parent.is_a?(TableHead) ? 'th' : 'td'
        xpath =
                if args.first.to_i == 0
                        @content = args.first
                        "*/#{t_what}[contains(normalize-space(), '#{@content}')]"
                else
                        @row = args.first.to_i
                        @column = args.last.to_i
                        "tr[#{@row}]/#{t_what}[#{@column}]"
                end

        @element = parent.element.find(xpath) rescue nil
end

Public Instance Methods

contains?(element, identifier, how) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 53
def contains?(element, identifier, how)
        child = "Wrapybara::#{element.camelize}".constantize.new(identifier, self.element.path, how)
        child.exists?
end
contains_message(element, identifier, how) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 80
def contains_message(element, identifier, how)
        parent = @parent.is_a?(TableHead) ? 'head' : 'body'
        message = "#{parent} cell at row #{@row} column #{@column} of table #{@parent.parent.how} '#{@parent.parent.identifier}'#{within(@parent.parent.scope)}"
        message += " to contain a[n] #{element} #{how} '#{identifier}'"
        message
end
exists?() click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 58
def exists?
        !@element.nil?
end
exists_message() click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 66
def exists_message
        parent = @parent.is_a?(TableHead) ? 'head' : 'body'
        message = "#{parent} of table #{@parent.parent.how} '#{@parent.parent.identifier}'#{within(@parent.parent.scope)} to have a cell "
        message += @content ? "with content '#{@content}'" : "at row #{@row} column #{@column}"
        message
end
has_content?(content) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 62
def has_content?(content)
        @element.text =~ /#{content}/
end
has_content_message(content) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 73
def has_content_message(content)
        parent = @parent.is_a?(TableHead) ? 'head' : 'body'
        message = "#{parent} cell at row #{@row} column #{@column} of table #{@parent.parent.how} '#{@parent.parent.identifier}'#{within(@parent.parent.scope)}"
        message += " to have content '#{content}'"
        message
end
should_contain(element, identifier, how) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 43
def should_contain(element, identifier, how)
        self.should_exist
        raise UnmetExpectation, "Expected #{self.contains_message(element, identifier, how)}" unless self.contains?(element, identifier, how)
end
should_exist() click to toggle source
Calls superclass method Wrapybara::Element#should_exist
# File lib/wrapybara/elements/table_cell.rb, line 25
def should_exist
        super "Expected #{self.exists_message}"
end
should_have_content(content) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 33
def should_have_content(content)
        self.should_exist
        raise UnmetExpectation, "Expected #{self.has_content_message(content)}" unless self.has_content?(content)
end
should_not_contain(element, identifier, how) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 48
def should_not_contain(element, identifier, how)
        self.should_exist
        raise UnmetExpectation, "Did not expect #{self.contains_message(element, identifier, how)}" if self.contains?(element, identifier, how)
end
should_not_content(content) click to toggle source
# File lib/wrapybara/elements/table_cell.rb, line 38
def should_not_content(content)
        self.should_exist
        raise UnmetExpectation, "Did not expect #{self.has_content_message(content)}" if self.has_content?(content)
end
should_not_exist() click to toggle source
Calls superclass method Wrapybara::Element#should_not_exist
# File lib/wrapybara/elements/table_cell.rb, line 29
def should_not_exist
        super "Did not expect #{self.exists_message}"
end