Sha256: d64ebf2804cb89833452fb2f873d28682d74b239b89bbf2ae0f6c05f5940a36c
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
require 'ns-options' module NsOptions::AssertMacros # a set of Assert macros to help write namespace definition and # regression tests in Assert (https://github.com/teaminsight/assert) def self.included(receiver) receiver.class_eval { extend MacroMethods } end module MacroMethods 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 subject.has_namespace?(ns) end end end end alias_method :have_namespace, :have_namespaces 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 subject.has_option?(opt) end end end end def have_option(*args) called_from = caller.first opt_name, type_class, rules = 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, called_from do # have assertions assert subject.has_option?(opt_name) opt = subject.__data__.child_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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ns-options-1.1.6 | lib/ns-options/assert_macros.rb |
ns-options-1.1.5 | lib/ns-options/assert_macros.rb |