Module: Expected::Matchers

Defined in:
lib/expected/matchers.rb,
lib/expected/matchers/be_a_concern.rb,
lib/expected/matchers/inherit_from.rb,
lib/expected/matchers/extend_module.rb,
lib/expected/matchers/have_constant.rb,
lib/expected/matchers/include_module.rb,
lib/expected/matchers/have_attr_reader.rb,
lib/expected/matchers/have_attr_writer.rb,
lib/expected/matchers/have_attr_accessor.rb

Overview

:nodoc:

Defined Under Namespace

Classes: BeAConcernMatcher, ExtendModuleMatcher, HaveAttrAccessorMatcher, HaveAttrReaderMatcher, HaveAttrWriterMatcher, HaveConstantMatcher, IncludeModuleMatcher, InheritFromMatcher

Instance Method Summary collapse

Instance Method Details

#be_a_concernBeAConcernMatcher

Used to test inheritance

Examples:

Test if the subject is an ActiveSupport::Concern

it { is_expected.to be_a_concern }

Returns:



15
16
17
# File 'lib/expected/matchers/be_a_concern.rb', line 15

def be_a_concern
  BeAConcernMatcher.new
end

#extend_module(expected_module) ⇒ ExtendModuleMatcher

Used to test inheritance

Examples:

Test if the subject extends the supplied Module

it { is_expected.to extend(SomeClass) }

Parameters:

  • expected_module (Class)

Returns:



14
15
16
# File 'lib/expected/matchers/extend_module.rb', line 14

def extend_module(expected_module)
  ExtendModuleMatcher.new(expected_module)
end

#have_attr_accessor(attribute) ⇒ HaveAttrAccessorMatcher

Used to test inclusion of ‘attr_accessor :attribute` on the subject

Examples:

Test if the subject has ‘attr_accessor :attribute`

it { is_expected.to have_attr_accessor(:some_attribute) }

Parameters:

  • attribute (String, Symbol)

Returns:



18
19
20
# File 'lib/expected/matchers/have_attr_accessor.rb', line 18

def have_attr_accessor(attribute) # rubocop:disable Naming/PredicateName
  HaveAttrAccessorMatcher.new(attribute)
end

#have_attr_reader(attribute) ⇒ HaveAttrReaderMatcher

Used to test inclusion of ‘attr_reader :attribute` on the subject

Examples:

Test if the subject has ‘attr_reader :attribute`

it { is_expected.to have_attr_reader(:some_attribute) }

Parameters:

  • attribute (String, Symbol)

Returns:



16
17
18
# File 'lib/expected/matchers/have_attr_reader.rb', line 16

def have_attr_reader(attribute) # rubocop:disable Naming/PredicateName
  HaveAttrReaderMatcher.new(attribute)
end

#have_attr_writer(attribute) ⇒ HaveAttrWriterMatcher

Used to test inclusion of ‘attr_writer :attribute` on the subject

Examples:

Test if the subject has ‘attr_writer :attribute`

it { is_expected.to have_attr_writer(:some_attribute) }

Parameters:

  • attribute (String, Symbol)

Returns:



16
17
18
# File 'lib/expected/matchers/have_attr_writer.rb', line 16

def have_attr_writer(attribute) # rubocop:disable Naming/PredicateName
  HaveAttrWriterMatcher.new(attribute)
end

#have_constant(name) ⇒ HaveConstantMatcher

Used to test constants

Examples:

Test if a constant exists

it { is_expected.to have_constant(:FOO) }

Test if a constant has a specific value

it { is_expected.to have_constant(:FOO).with_value("bar") }

Test if a constant’s value is a specific type

it { is_expected.to have_constant(:FOO).of_type(String) }

Parameters:

  • name (String, Symbol)

Returns:



20
21
22
# File 'lib/expected/matchers/have_constant.rb', line 20

def have_constant(name) # rubocop:disable Naming/PredicateName
  HaveConstantMatcher.new(name)
end

#include_module(expected_module) ⇒ IncludeModuleMatcher

Used to test inheritance

Examples:

Test if the subject includes the supplied Module

it { is_expected.to include_module(SomeModule) }

Parameters:

  • expected_module (Module)

Returns:



14
15
16
# File 'lib/expected/matchers/include_module.rb', line 14

def include_module(expected_module)
  IncludeModuleMatcher.new(expected_module)
end

#inherit_from(expected_ancestor) ⇒ InheritFromMatcher

Used to test inheritance

Examples:

Test if the subject inherits from the supplied Class

it { is_expected.to inherit_from(SomeClass) }

Parameters:

  • expected_ancestor (Class)

Returns:



14
15
16
# File 'lib/expected/matchers/inherit_from.rb', line 14

def inherit_from(expected_ancestor)
  InheritFromMatcher.new(expected_ancestor)
end