Class: Rectify::StubForm

Inherits:
Object
  • Object
show all
Defined in:
lib/rectify/rspec/stub_form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ StubForm

Returns a new instance of StubForm.



5
6
7
8
# File 'lib/rectify/rspec/stub_form.rb', line 5

def initialize(attributes)
  @valid = attributes.fetch(:valid?, false)
  @attributes = attributes.except!(:valid?)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
21
22
23
24
25
26
27
# File 'lib/rectify/rspec/stub_form.rb', line 18

def method_missing(method_name, *args, &block)
  if attributes.key?(method_name)
    attributes[method_name]
  elsif method_name.to_s.ends_with?("=")
    attribute_name = method_name.to_s.chomp("=").to_sym
    attributes[attribute_name] = args.first
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/rectify/rspec/stub_form.rb', line 3

def attributes
  @attributes
end

#validObject (readonly)

Returns the value of attribute valid.



3
4
5
# File 'lib/rectify/rspec/stub_form.rb', line 3

def valid
  @valid
end

Instance Method Details

#invalid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rectify/rspec/stub_form.rb', line 14

def invalid?
  !valid?
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rectify/rspec/stub_form.rb', line 29

def respond_to_missing?(method_name, _include_private = false)
  attributes.key?(method_name)
end

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/rectify/rspec/stub_form.rb', line 10

def valid?
  valid
end