Module: SmartRspec::Support::Model::Expectations

Defined in:
lib/smart_rspec/support/model/expectations.rb

Instance Method Summary collapse

Instance Method Details

#association_expectation(type, model) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/smart_rspec/support/model/expectations.rb', line 31

def association_expectation(type, model)
  if type == :has_many
    expect(subject).to respond_to("#{model.to_s.singularize}_ids")
  elsif type == :belongs_to
    %W(#{model}= #{model}_id #{model}_id=).each do |method|
      expect(subject).to respond_to(method)
    end
  end
end

#be_valid_expectation(attr, value = nil, mock = nil) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/smart_rspec/support/model/expectations.rb', line 5

def be_valid_expectation(attr, value = nil, mock = nil)
  mock ||= subject
  mock.send("#{attr}=", value)

  expect(mock).not_to be_valid
  expect(mock).to have_error_on(attr)
end

#default_expectation(attr, value) ⇒ Object



13
14
15
# File 'lib/smart_rspec/support/model/expectations.rb', line 13

def default_expectation(attr, value)
  expect(subject.send(attr)).to eq(value)
end

#enum_expectation(attr, value) ⇒ Object



17
18
19
# File 'lib/smart_rspec/support/model/expectations.rb', line 17

def enum_expectation(attr, value)
  expect(value).to include(subject.send(attr).to_sym)
end

#has_attributes_expectation(attr, options) ⇒ Object



26
27
28
29
# File 'lib/smart_rspec/support/model/expectations.rb', line 26

def has_attributes_expectation(attr, options) options.each do |key, value|
    send("#{key}_expectation", attr, value)
  end
end

#type_expectation(attr, value) ⇒ Object



21
22
23
24
# File 'lib/smart_rspec/support/model/expectations.rb', line 21

def type_expectation(attr, value)
  assert_type = value != :Boolean ? be_kind_of(Kernel.const_get(value)) : be_boolean
  expect(subject.send(attr)).to assert_type
end