Class: Chop::Form

Inherits:
Struct
  • Object
show all
Defined in:
lib/chop/form.rb

Defined Under Namespace

Classes: Checkbox, Default, Field, FieldFinder, MultipleCheckbox, MultipleFile, MultipleSelect, Radio, Select, SingleFile, Textarea, ViaJavascript

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



5
6
7
# File 'lib/chop/form.rb', line 5

def path
  @path
end

#sessionObject

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



5
6
7
# File 'lib/chop/form.rb', line 5

def session
  @session
end

#tableObject

Returns the value of attribute table

Returns:

  • (Object)

    the current value of table



5
6
7
# File 'lib/chop/form.rb', line 5

def table
  @table
end

Class Method Details

.diff!(selector, table, session: Capybara.current_session, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chop/form.rb', line 10

def self.diff! selector, table, session: Capybara.current_session, &block
  root = begin
    if selector.is_a?(Capybara::Node::Element)
      selector
    else
      session.find(selector)
    end
  rescue Capybara::ElementNotFound
    raise unless @allow_not_found
    Node("")
  end

  actual = root.all(Field.combined_css_selector)
    .filter_map { |field_element| Field.from(session, field_element) }
    .select(&:should_include_in_diff?)
    .uniq { |field| field.field[:name] }
    .filter_map(&:to_diff_row)

  block.call(actual, root) if block_given?
  table.diff! actual, surplus_row: false, misplaced_col: false
end

.fill_in!(table, session: Capybara.current_session, path: "features/support/fixtures") ⇒ Object



6
7
8
# File 'lib/chop/form.rb', line 6

def self.fill_in! table, session: Capybara.current_session, path: "features/support/fixtures"
  new(table, session, path).fill_in!
end

Instance Method Details

#fill_in!Object



33
34
35
36
37
# File 'lib/chop/form.rb', line 33

def fill_in!
  table.rows_hash.each do |label, value|
    Field.for(session, label, value, path).fill_in!
  end
end