Class: PencilPusher::HaveRequiredField

Inherits:
Object
  • Object
show all
Includes:
Matchers
Defined in:
lib/pencil_pusher/have_required_field.rb

Instance Method Summary collapse

Methods included from Matchers

#have_errors, #have_int_field, #have_required_choice_field, #have_required_field, #have_required_float_field, #have_required_int_field, #have_required_text_field, #have_text_field

Constructor Details

#initialize(field_name, error) ⇒ HaveRequiredField

Returns a new instance of HaveRequiredField.



5
6
7
8
# File 'lib/pencil_pusher/have_required_field.rb', line 5

def initialize(field_name, error)
  @field_name = field_name
  @error = error
end

Instance Method Details

#descriptionObject



32
33
34
# File 'lib/pencil_pusher/have_required_field.rb', line 32

def description
  "have required field #{field_name}"
end

#failure_message_for_should(actual, two) ⇒ Object Also known as: failure_message



21
22
23
# File 'lib/pencil_pusher/have_required_field.rb', line 21

def failure_message_for_should(actual, two)
  @error
end

#failure_message_for_should_not(actual) ⇒ Object Also known as: failure_message_when_negated



25
26
27
# File 'lib/pencil_pusher/have_required_field.rb', line 25

def failure_message_for_should_not(actual)
  "expected #{actual} to not have required field #{field_name} but did"
end

#matches?(form) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
# File 'lib/pencil_pusher/have_required_field.rb', line 10

def matches?(form)
  begin
    builder = FormBuilder.builder(form)
    builder.call(field_name => '').should have_errors(field_name, [error])
  rescue => e
    @error = e.message
    raise e
  end
  true
end