Module: SmartRspec::Support::Expectations

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

Instance Method Summary collapse

Instance Method Details

#association_expectation(type, model) ⇒ Object



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

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

#default_expectation(attr, value) ⇒ Object



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

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

#enum_expectation(attr, value) ⇒ Object



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

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

#has_attributes_expectation(attr, options) ⇒ Object



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

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

#type_expectation(attr, value) ⇒ Object



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

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

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



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

def validation_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