Module: Testopia::Ohm::Macros

Defined in:
lib/testopia/ohm.rb

Instance Method Summary collapse

Instance Method Details

#should_assert_error(pair, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/testopia/ohm.rb', line 14

def should_assert_error(pair, options = {})
  value        = options[:given]
  field, error = pair

  should 'assert %s of %s' % [error, field] do
    subject.send '%s=' % field, value

    assert ! subject.valid?, '%s should not be valid' % subject.inspect
    assert subject.errors.include?(pair),
      '%s should have a %s error' % [field, error]
  end
end

#should_assert_member(att, set, invalid = '_SOME_FOOBAR_VALUE_') ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/testopia/ohm.rb', line 35

def should_assert_member(att, set, invalid = '_SOME_FOOBAR_VALUE_')
  should_assert_error [att, :not_member], :given => invalid

  set.each do |elem|
    should "assert_member :%s, %s" % [att, elem] do
      subject.send '%s=' % att, elem
      subject.valid?

      assert ! subject.errors.include?([att, :not_member]),
        '%s expected to be valid with "%s"' % [att, elem]
    end
  end
end

#should_assert_numeric(*atts) ⇒ Object



31
32
33
# File 'lib/testopia/ohm.rb', line 31

def should_assert_numeric(*atts)
  atts.each { |a| should_assert_error [a, :not_numeric], :given => 'aa' } 
end

#should_assert_present(*atts) ⇒ Object



27
28
29
# File 'lib/testopia/ohm.rb', line 27

def should_assert_present(*atts)
  atts.each { |a| should_assert_error [a, :not_present], :given => nil }
end

#subject(&block) ⇒ Object



8
9
10
11
12
# File 'lib/testopia/ohm.rb', line 8

def subject(&block)
  define_method :subject do
    @__subject__ ||= block.call 
  end
end