Class: Conformity::Form

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/conformity/form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = '', &steps) ⇒ Form

Returns a new instance of Form.



11
12
13
14
15
# File 'lib/conformity/form.rb', line 11

def initialize(host = '', &steps)
  @host = host
  @steps = steps
  instance_eval(&steps)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



50
51
52
53
# File 'lib/conformity/form.rb', line 50

def method_missing(name, *args, &block)
  # ignore actions
  super unless Actions::ACTIONS.include?(name)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#stepsObject (readonly)

Returns the value of attribute steps.



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

def steps
  @steps
end

Instance Method Details

#actionsObject



21
22
23
# File 'lib/conformity/form.rb', line 21

def actions
  @actions ||= Actions.new(fields_container)
end

#field(name, opts = {}) ⇒ Object



29
30
31
# File 'lib/conformity/form.rb', line 29

def field(name, opts = {})
  fields_container.add_new_field(name, opts)
end

#fieldsObject



46
47
48
# File 'lib/conformity/form.rb', line 46

def fields
  fields_container.fields
end

#fields_containerObject



17
18
19
# File 'lib/conformity/form.rb', line 17

def fields_container
  @fields_container ||= Fields.new
end

#fillObject



33
34
35
36
37
38
39
# File 'lib/conformity/form.rb', line 33

def fill
  Capybara.current_session.reset!
  set_host(host)

  actions.instance_eval(&steps)
  Capybara.page
end

#fill_with(field_hash) ⇒ Object



41
42
43
44
# File 'lib/conformity/form.rb', line 41

def fill_with(field_hash)
  fields_container.set_all(field_hash)
  fill
end

#select(*args) ⇒ Object

so Kernel#select isn’t called



56
57
# File 'lib/conformity/form.rb', line 56

def select(*args)
end

#success_conditionsObject



25
26
27
# File 'lib/conformity/form.rb', line 25

def success_conditions
  @success_conditions ||= SuccessConditions.new
end