Module: Kelp::Helper

Included in:
Checkbox, Dropdown, Field
Defined in:
lib/kelp/helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) listify(items)

Convert a Cucumber::Ast::Table or multiline string into a list of strings



7
8
9
10
11
12
13
14
15
# File 'lib/kelp/helper.rb', line 7

def listify(items)
  if items.class == Cucumber::Ast::Table
    strings = items.raw.flatten
  elsif items.class == Cucumber::Ast::DocString
    strings = items.to_s.split(/[\r\n]+/)
  else
    strings = items.split(/[\r\n]+/)
  end
end

- (Object) nice_find_field(locator)

A slightly friendlier version of Capybara's find_field, which actually tells you which locator failed to match (instead of giving a useless Unable to find '#XPath::Union:0xXXXXXXX' message).

Raises:



27
28
29
30
31
32
33
34
# File 'lib/kelp/helper.rb', line 27

def nice_find_field(locator)
  begin
    field = find_field(locator)
  rescue Capybara::ElementNotFound
    raise Kelp::FieldNotFound,
      "Could not find field: '#{locator}'"
  end
end

- (Object) rspec_unexpected

Return the appropriate "ExpectationNotMetError" class for the current version of RSpec



39
40
41
42
43
44
45
# File 'lib/kelp/helper.rb', line 39

def rspec_unexpected
  if defined?(RSpec)
    RSpec::Expectations::ExpectationNotMetError
  else
    Spec::Expectations::ExpectationNotMetError
  end
end