Class: Rails3::PluginExtender::Matchers::BeExtendedWith
- Inherits:
-
Object
- Object
- Rails3::PluginExtender::Matchers::BeExtendedWith
- Includes:
- Util
- Defined in:
- lib/plugin_toolbox/rspec/matchers/be_extended_with.rb
Constant Summary
Constants included from Util
Util::ACTIVE_MODULES, Util::INIT
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.
9 10 11 12 13 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 9 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.
7 8 9 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 7 def bad_const @bad_const end |
#cause ⇒ Object (readonly)
Returns the value of attribute cause.
7 8 9 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 7 def cause @cause end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
7 8 9 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 7 def methods @methods end |
#module_const ⇒ Object (readonly)
Returns the value of attribute module_const.
7 8 9 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 7 def module_const @module_const end |
#rails_const ⇒ Object (readonly)
Returns the value of attribute rails_const.
7 8 9 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 7 def rails_const @rails_const end |
#rails_const_name ⇒ Object (readonly)
Returns the value of attribute rails_const_name.
7 8 9 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 7 def rails_const_name @rails_const_name end |
#submodules ⇒ Object (readonly)
Returns the value of attribute submodules.
7 8 9 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 7 def submodules @submodules end |
Instance Method Details
#base_class_methods ⇒ Object
30 31 32 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 30 def base_class_methods (rails_const == I18n) ? rails_const.methods : rails_const.instance_methods end |
#failure_message ⇒ Object
50 51 52 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 50 def "Expected the rails class #{rails_const_name} to be extended with the methods in #{bad_const}#{cause}" end |
#get_methods(name) ⇒ Object
46 47 48 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 46 def get_methods name get_constant(module_const, name).instance_methods end |
#match_submodules? ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 34 def match_submodules? submodules.each do |name| @bad_const = make_constant(module_const, name) return false if !methods_included? get_methods(name) end true end |
#matches?(type) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 15 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 extension module wasn't found" false end end |
#methods_included?(methods) ⇒ Boolean
42 43 44 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 42 def methods_included? methods (base_class_methods & methods) == methods end |
#negative_failure_message ⇒ Object
54 55 56 |
# File 'lib/plugin_toolbox/rspec/matchers/be_extended_with.rb', line 54 def "Did not expect the rails class #{rails_const_name} to be extended with the methods in #{bad_const}" end |