Module: NsOptions::AssertMacros::MacroMethods

Defined in:
lib/ns-options/assert_macros.rb

Instance Method Summary collapse

Instance Method Details

#have_namespaces(*namespaces) ⇒ Object Also known as: have_namespace



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ns-options/assert_macros.rb', line 15

def have_namespaces(*namespaces)
  called_from = caller.first
  macro_name = "have namespaces: #{namespaces.map{|ns| "'#{ns}'"}.join(', ')}"

  Assert::Macro.new(macro_name) do
    namespaces.each do |ns|
      should "have a namespace named '#{ns}'", called_from do
        assert_respond_to ns, subject
        assert_kind_of NsOptions::Namespace, subject.send(ns)
      end
    end
  end
end

#have_option(*args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ns-options/assert_macros.rb', line 44

def have_option(*args)
  called_from = caller.first
  rules, type_class, opt_name = NsOptions::Option.args(*args)
  test_name = [
    "have an option: '#{opt_name}'",
    "of type '#{type_class}'",
    "with rules '#{rules.inspect}'"
  ].join(', ')

  Assert::Macro.new(test_name) do

    should test_name do
      # name assertions
      assert_respond_to opt_name, subject

      opt = subject.options[opt_name]
      assert_kind_of NsOptions::Option, opt

      # type_class assertions
      assert_equal type_class, opt.type_class

      # rules assertions
      assert_equal rules, opt.rules
    end

  end
end

#have_options(*options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ns-options/assert_macros.rb', line 30

def have_options(*options)
  called_from = caller.first
  macro_name = "have options: #{options.map{|opt| "'#{opt}'"}.join(', ')}"

  Assert::Macro.new(macro_name) do
    options.each do |opt|
      should "have an option named '#{opt}'", called_from do
        assert_respond_to opt, subject
        assert_kind_of NsOptions::Option, subject.options[opt]
      end
    end
  end
end