Class: PencilPusher::HaveRequiredTextField

Inherits:
Object
  • Object
show all
Includes:
Matchers, RSpec::Matchers
Defined in:
lib/pencil_pusher/have_required_text_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, valid_value, error) ⇒ HaveRequiredTextField

Returns a new instance of HaveRequiredTextField.



6
7
8
9
10
# File 'lib/pencil_pusher/have_required_text_field.rb', line 6

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

Instance Method Details

#descriptionObject



34
35
36
# File 'lib/pencil_pusher/have_required_text_field.rb', line 34

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

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



23
24
25
# File 'lib/pencil_pusher/have_required_text_field.rb', line 23

def failure_message_for_should(actual, two)
  @error
end

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



27
28
29
# File 'lib/pencil_pusher/have_required_text_field.rb', line 27

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

#matches?(builder) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'lib/pencil_pusher/have_required_text_field.rb', line 12

def matches?(builder)
  begin
    expect(builder).to have_required_field(field_name, error)
    expect(builder).to have_text_field(field_name, valid_value)
  rescue => e
    @error = e.message
    raise e
  end
  true
end