Class: Rails3::Plugin::Extender::Matchers::BeExtendedWith
- Inherits:
-
Object
- Object
- Rails3::Plugin::Extender::Matchers::BeExtendedWith
- Includes:
- Util
- Defined in:
- lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb
Instance Attribute Summary collapse
-
#bad_const ⇒ Object
readonly
Returns the value of attribute bad_const.
-
#cause ⇒ Object
readonly
Returns the value of attribute cause.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#module_const ⇒ Object
readonly
Returns the value of attribute module_const.
-
#rails_const ⇒ Object
readonly
Returns the value of attribute rails_const.
-
#rails_const_name ⇒ Object
readonly
Returns the value of attribute rails_const_name.
-
#submodules ⇒ Object
readonly
Returns the value of attribute submodules.
Instance Method Summary collapse
- #base_class_methods ⇒ Object
- #failure_message ⇒ Object
- #get_methods(name) ⇒ Object
-
#initialize(module_const, submodules = nil) ⇒ BeExtendedWith
constructor
A new instance of BeExtendedWith.
- #match_submodules? ⇒ Boolean
- #matches?(type) ⇒ Boolean
- #methods_included?(methods) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods included from Util
#act_type?, #get_base_class, #get_constant, #get_load_type, #get_module, #make_constant, #rails_const_base
Constructor Details
#initialize(module_const, submodules = nil) ⇒ BeExtendedWith
Returns a new instance of BeExtendedWith.
10 11 12 13 14 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 10 def initialize(module_const, submodules=nil) @module_const = module_const raise ArgumentError, "List of submodules must be given as a collection of Symbols or Strings" if submodules && !submodules.respond_to?(:flatten) @submodules = submodules.flatten if submodules end |
Instance Attribute Details
#bad_const ⇒ Object (readonly)
Returns the value of attribute bad_const.
8 9 10 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 8 def bad_const @bad_const end |
#cause ⇒ Object (readonly)
Returns the value of attribute cause.
8 9 10 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 8 def cause @cause end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
8 9 10 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 8 def methods @methods end |
#module_const ⇒ Object (readonly)
Returns the value of attribute module_const.
8 9 10 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 8 def module_const @module_const end |
#rails_const ⇒ Object (readonly)
Returns the value of attribute rails_const.
8 9 10 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 8 def rails_const @rails_const end |
#rails_const_name ⇒ Object (readonly)
Returns the value of attribute rails_const_name.
8 9 10 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 8 def rails_const_name @rails_const_name end |
#submodules ⇒ Object (readonly)
Returns the value of attribute submodules.
8 9 10 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 8 def submodules @submodules end |
Instance Method Details
#base_class_methods ⇒ Object
31 32 33 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 31 def base_class_methods (rails_const == I18n) ? rails_const.methods : rails_const.instance_methods end |
#failure_message ⇒ Object
53 54 55 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 53 def "Expected the rails class #{rails_const_name} to be extended with the methods in #{bad_const}#{cause}" end |
#get_methods(name) ⇒ Object
49 50 51 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 49 def get_methods name get_constant(module_const, name).instance_methods end |
#match_submodules? ⇒ Boolean
35 36 37 38 39 40 41 42 43 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 35 def match_submodules? submodules.each do |name| @bad_const = make_constant(module_const, name) if !methods_included? get_methods(name) return false end end true end |
#matches?(type) ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 16 def matches? type begin @rails_const_name = get_base_class(type) @bad_const = module_const @rails_const = rails_const_name.constantize return match_submodules? if submodules methods_included? module_const.instance_methods rescue @cause = ", but the module #{rails_const_name} has not been registered" false end end |
#methods_included?(methods) ⇒ Boolean
45 46 47 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 45 def methods_included? methods (base_class_methods & methods) == methods end |
#negative_failure_message ⇒ Object
57 58 59 |
# File 'lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb', line 57 def "Did not expect the rails class #{rails_const_name} to be extended with the methods in #{bad_const}" end |