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, timeout: nil, &block) ⇒ Object

Capybara's #synchronize is not re-entrant, so the finds below get a single attempt each and have to retry out here instead — hence ElementNotFound in the error list. A block that post-processes actual should raise Capybara::ElementNotFound to ask for a re-read of a half-rendered form.



14
15
16
17
18
19
20
21
22
# File 'lib/chop/form.rb', line 14

def self.diff! selector, table, session: Capybara.current_session, timeout: nil, &block
  errors = session.driver.invalid_element_errors + [
    Cucumber::MultilineArgument::DataTable::Different,
    Capybara::ElementNotFound,
  ]
  session.document.synchronize timeout || Capybara.default_max_wait_time, errors: errors do
    diff_once! selector, table, session: session, &block
  end
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



47
48
49
50
51
# File 'lib/chop/form.rb', line 47

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