Module: TestRig::DynamicAssertions

Defined in:
lib/test_rig/dynamic_assertions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
# File 'lib/test_rig/dynamic_assertions.rb', line 5

def self.included(klass)
  klass.class_eval do
    alias_method_chain :method_missing, :dynamic_assertions
  end
end

Instance Method Details

#assert_not(*args) ⇒ Object



11
12
13
# File 'lib/test_rig/dynamic_assertions.rb', line 11

def assert_not(*args)
  assert !args.shift, *args
end

#method_missing_with_dynamic_assertions(method, *args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/test_rig/dynamic_assertions.rb', line 15

def method_missing_with_dynamic_assertions(method, *args)
  if method.to_s =~ /^assert_(not_)?([a-z_]+)/
    method_name = $2.to_sym
    if args.length == 1 && args.first.respond_to?(:"#{method_name}?")
      actual = args.first.send :"#{method_name}?"
      assert $1 ? !actual : actual
      return
    elsif args.length == 2 && args.last.respond_to?(method_name)
      send :"assert_#{$1}equal", args.first, args.last.send(method_name)
      return
    end
  end

  method_missing_without_dynamic_assertions(method, *args)
end