Method: RSpec::Core::Configuration#prepend

Defined in:
lib/rspec/core/configuration.rb

#prepend(mod, *filters) ⇒ void

Tells RSpec to prepend example groups with mod. Methods defined in mod are exposed to examples (not example groups). Use filters to constrain the groups in which to prepend the module.

Similar to include, but module is included before the example group's class in the ancestor chain.

Examples:


module OverrideMod
  def override_me
    "overridden"
  end
end

RSpec.configure do |config|
  config.prepend(OverrideMod, :method => :prepend)
end

describe "overriding example's class", :method => :prepend do
  it "finds the user" do
    self.class.class_eval do
      def override_me
      end
    end
    override_me # => "overridden"
    # ...
  end
end

See Also:



1557
1558
1559
1560
1561
# File 'lib/rspec/core/configuration.rb', line 1557

def prepend(mod, *filters)
  define_mixed_in_module(mod, filters, @prepend_modules, :prepend) do |group|
    safe_prepend(mod, group)
  end
end