class Object

Public Instance Methods

decision() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 34
def decision
  return @decision unless @decision.nil?
  @decision = catch(:decision) { passes? }
  remove_expected

  @decision
end
dont_remove_expected() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 93
def dont_remove_expected
  @remove_expected = false
end
expected_exists?() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 52
def expected_exists?
  Object.const_defined? expected
end
expected_should_exist() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 64
def expected_should_exist
  return true if expected_exists?

  self.message = "#{expected} did not get defined"
  throw :decision, false
end
expected_should_have_correct_type() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 71
def expected_should_have_correct_type
  return true if type.nil?

  const = Object.const_get(expected)
  const = const.class unless [Class, Module].include? const.class

  return true if const <= type

  self.message = "#{expected} is not of type #{type} its ancestors are #{const.ancestors}"
  throw :decision, false
end
expected_shouldnt_exist() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 56
def expected_shouldnt_exist
  return true unless expected_exists?

  dont_remove_expected
  self.message = "#{expected} was already defined"
  throw :decision, false
end
passes?() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 42
def passes?
  expected_shouldnt_exist
  actual.call
  expected_should_exist

  expected_should_have_correct_type

  throw :decision, true
end
remove_expected() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 83
def remove_expected
  return nil unless remove_expected? && expected_exists?
  Object.send(:remove_const, expected)
end
remove_expected?() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 88
def remove_expected?
  return true if @remove_expected.nil?
  @remove_expected
end
validate_input() click to toggle source
# File lib/rspec_matcher_define_constant/matcher.rb, line 29
def validate_input
  return :ok if actual.is_a? Proc
  fail ArgumentError, "define constant needs a proc"
end