module Mackarel::Capybara

Public Instance Methods

alt_str(alt) click to toggle source
# File lib/mackarel/capybara.rb, line 63
def alt_str(alt)
  "@alt='#{alt}'" if alt
end
and_i_am_taken_to(path)
Alias for: i_am_taken_to
and_i_am_taken_to_the(path)
Alias for: i_am_taken_to
and_i_can_see(something)
Alias for: i_can_see
and_i_dont_find_a(selector, opts={})
Alias for: i_find_no
and_i_dont_find_an(selector, opts={})
Alias for: i_find_no
and_i_find(selector, opts={})
Alias for: i_find
and_i_find_a(selector, opts={})
Alias for: i_find
and_i_find_an(selector, opts={})
Alias for: i_find
and_i_find_no(selector, opts={})
Alias for: i_find_no
fill_autocomplete(field="input[data-autocomplete]", options) click to toggle source
# File lib/mackarel/capybara/form.rb, line 11
def fill_autocomplete(field="input[data-autocomplete]", options)
  fill_in field, with: options.delete(:with)
  page.execute_script %Q{ $('#{field}').trigger("focus") }
  page.execute_script %Q{ $('#{field}').trigger("keydown") }
  sleep 1
  page.execute_script %Q{ $('.ui-menu-item a:contains("#{with}")').trigger("mouseenter").trigger("click"); }
end
fill_the_form_with(attributes) click to toggle source
# File lib/mackarel/capybara/form.rb, line 3
def fill_the_form_with(attributes)
  attributes.each do |field_name, value|
    field = page.find_field(field_name)
    next if field.set(value)
    select_on_form(field_name, value)
  end
end
i_am_taken_to(path) click to toggle source
# File lib/mackarel/capybara.rb, line 5
def i_am_taken_to(path)
  expect(page).to have_current_path(path)
end
i_am_taken_to_the(path)
Alias for: i_am_taken_to
i_can_see(something) click to toggle source
# File lib/mackarel/capybara.rb, line 9
def i_can_see(something)
  expect(page).to have_content(something)
end
Also aliased as: and_i_can_see
i_cannot_see(something) click to toggle source
# File lib/mackarel/capybara.rb, line 13
def i_cannot_see(something)
  expect(page).not_to have_content(something)
end
i_dont_find_a(selector, opts={})
Alias for: i_find_no
i_dont_find_an(selector, opts={})
Alias for: i_find_no
i_find(selector, opts={}) click to toggle source
# File lib/mackarel/capybara.rb, line 17
def i_find(selector, opts={})
  text = opts.delete(:with_text)
  case selector
  when String
    expect(page).to have_selector selector, text: text
  when :link
    pointing_to = opts.delete(:pointing_to)
    if pointing_to.nil?
      expect(page).to have_link text
    else
      expect(page).to have_link text, href: pointing_to
    end
  when :image
    src = opts.delete(:with_src)
    expect(page).to have_xpath(image_path(src, text))
  end
end
i_find_a(selector, opts={})
Alias for: i_find
i_find_an(selector, opts={})
Alias for: i_find
i_find_no(selector, opts={}) click to toggle source
# File lib/mackarel/capybara.rb, line 35
def i_find_no(selector, opts={})
  text = opts.delete(:with_text)
  case selector
  when String
    expect(page).to have_no_selector selector, text: text
  when :link
    pointing_to = opts.delete(:pointing_to)
    if pointing_to.nil?
      expect(page).to have_no_link text
    else
      expect(page).to have_no_link text, href: pointing_to
    end
  when :image
    src = opts.delete(:with_src)
    expect(page).to have_no_xpath(image_path(src, text))
  end
end
image_filters(src, alt) click to toggle source
# File lib/mackarel/capybara.rb, line 57
def image_filters(src, alt)
  guts = [alt_str(alt), src_str(src)].compact
  guts = guts.join(" and ")
  guts.empty? ? "" : "[#{guts}]"
end
image_path(src, alt) click to toggle source
# File lib/mackarel/capybara.rb, line 53
def image_path(src, alt)
  "//img#{image_filters(src, alt)}"
end
select_on_form(field_name, value) click to toggle source
# File lib/mackarel/capybara/form.rb, line 19
def select_on_form(field_name, value)
  field = page.find_field(field_name)
  [value].flatten.each do |single_value|
    field.find(:option, single_value).select_option
  end
end
src_str(src) click to toggle source
# File lib/mackarel/capybara.rb, line 67
def src_str(src)
  "contains(@src, '#{src}')" if src
end
submit_the_form(selector="") click to toggle source
# File lib/mackarel/capybara/form.rb, line 26
def submit_the_form(selector="")
  page.find("form#{selector}").find(:button).click
end