source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | rspec/rspec | https://github.com/rspec/rspec | Gemfile | Ruby | mit | 93 | main | 1,294 | # frozen_string_literal: true
source "https://gem.coop"
%w[rspec rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
gem lib, :path => File.expand_path("../#{lib}", __FILE__)
end
group :coverage do
gem 'simplecov'
end
### deps for rdoc.info
group :documentation do
gem 'github-markup', :plat... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/rspec-mocks.gemspec | Ruby | mit | 93 | main | 1,964 | # -*- encoding: utf-8 -*-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "rspec/mocks/version"
Gem::Specification.new do |s|
s.name = "rspec-mocks"
s.version = RSpec::Mocks::Version::STRING
s.platform = Gem::Platform::RUBY
s.license = "MIT"
s.authors = ["Steven Baker", ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/Rakefile | Ruby | mit | 93 | main | 897 | require 'bundler'
Bundler.setup
Bundler::GemHelper.install_tasks
Bundler::GemHelper.tag_prefix = 'rspec-mocks-'
require 'rake'
require 'rspec/core/rake_task'
require 'rspec/mocks/version'
require 'cucumber/rake/task'
desc "Run all examples"
RSpec::Core::RakeTask.new(:spec) do |t|
t.ruby_opts = %w[-w]
end
Cucumber:... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/thread_safety.rb | Ruby | mit | 93 | main | 612 | $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'benchmark'
require 'rspec/mocks'
Benchmark.bm do |bm|
bm.report("fetching a proxy") do
RSpec::Mocks.with_temporary_scope do
o = Object.new
100_000.times {
RSpec::Mocks.space.proxy_for(o)
}
end
end
end
# Without... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/double_creation.rb | Ruby | mit | 93 | main | 2,371 | $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'benchmark'
require 'rspec/mocks'
n = 1000
puts "#{n} times - ruby #{RUBY_VERSION}"
puts
Benchmark.bm do |bm|
RSpec::Mocks.setup(self)
(0..9).each do |m|
attrs = m.times.inject({}) {|h, x|
h["method_#{x}"] = x
h
}
bm.r... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/find_original_method_early.rb | Ruby | mit | 93 | main | 2,141 | $LOAD_PATH.unshift "./lib"
require 'rspec/mocks'
require "rspec/mocks/standalone"
=begin
This benchmark script is for troubleshooting the performance of
#264. To use it, you have to edit the code in #264 a bit:
wrap the call in `MethodDouble#initialize` to `find_original_method`
in a conditional like `if $find_origina... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/each_value_v_values_each.rb | Ruby | mit | 93 | main | 1,213 | require 'benchmark'
n = 10_000
m = 1.upto(1000).inject({}) { |m, i| m[i] = i; m }
Benchmark.benchmark do |bm|
puts "#{n} times - ruby #{RUBY_VERSION}"
puts
puts "each_value"
3.times do
bm.report do
n.times do
m.each_value {}
end
end
end
puts
puts "values.each"
3.times ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/transfer_nested_constants.rb | Ruby | mit | 93 | main | 2,284 | $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
require 'benchmark'
require 'rspec/mocks'
N = ENV.fetch('N', 10_000).to_i
M = ENV.fetch('M', 5).to_i
puts "#{N} times, #{M} constants - ruby #{RUBY_VERSION}"
puts
class A
M.times do |x|
const_set("C#{x}", Object.new)
end
end
Benchmark.bm(20) do |b... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/method_defined_at_any_visibility.rb | Ruby | mit | 93 | main | 2,717 | require 'benchmark'
n = 1_000_000
Foo = Class.new do
1.upto(n) do |i|
define_method(:"public_method_#{i}") {}
define_method(:"protected_method_#{i}") {}
protected :"protected_method_#{i}"
define_method(:"private_method_#{i}") {}
private :"protected_method_#{i}"
end
end
Benchmark.benchmark do ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/accessing_configuration_via_method_vs_cache.rb | Ruby | mit | 93 | main | 1,297 | require 'benchmark'
n = 10_000
require 'rspec/mocks'
# precache config
RSpec::Mocks.configuration
Benchmark.benchmark do |bm|
puts "#{n} times - ruby #{RUBY_VERSION}"
puts
puts "directly"
3.times do
bm.report do
n.times do
original_state = RSpec::Mocks.configuration.temporarily_suppress_... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/allocations/lambda_vs_block_with_select.rb | Ruby | mit | 93 | main | 2,759 | require 'memory_profiler'
n = 10_000
def find_with_proc(argument)
lambda do |lambda_arg|
lambda_arg == argument
end
end
def find(argument, lambda_arg)
lambda_arg == argument
end
puts "#{n} items - ruby #{RUBY_VERSION}"
puts
puts "find_with_proc"
MemoryProfiler.report do
100.times do
1.upto(n).sele... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/allocations/1_object_1000_mocks.rb | Ruby | mit | 93 | main | 3,487 | require_relative "helper"
symbols = (1..1000).map { |x| :"#{x}" }
benchmark_allocations do
o = Object.new
symbols.each do |sym|
expect(o).to receive(sym)
end
symbols.each do |sym|
o.send(sym)
end
RSpec::Mocks.space.verify_all
RSpec::Mocks.space.reset_all
end
__END__
As of commit 9ee3e3adb52911... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/benchmarks/allocations/helper.rb | Ruby | mit | 93 | main | 474 | $LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)
require "allocation_stats"
require 'rspec/mocks/standalone'
def benchmark_allocations(burn: 1)
stats = AllocationStats.new(:burn => burn).trace do
yield
end
columns = if ENV['DETAIL']
[:sourcefile, :sourceline, :class_plus]
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks.rb | Ruby | mit | 93 | main | 4,364 | require 'rspec/support'
RSpec::Support.require_rspec_support 'caller_filter'
RSpec::Support.require_rspec_support 'warnings'
RSpec::Support.define_optimized_require_for_rspec(:mocks) { |f| require_relative f }
%w[
instance_method_stasher
method_double
argument_matchers
example_methods
proxy
test_double
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/error_generator.rb | Ruby | mit | 93 | main | 14,432 | RSpec::Support.require_rspec_support "object_formatter"
RSpec::Support.require_rspec_support 'ruby_features'
module RSpec
module Mocks
# Raised when a message expectation is not satisfied.
MockExpectationError = Class.new(Exception)
# Raised when a test double is used after it has been torn
# down (... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/space.rb | Ruby | mit | 93 | main | 6,534 | RSpec::Support.require_rspec_support 'reentrant_mutex'
module RSpec
module Mocks
# @private
# Provides a default space implementation for outside
# the scope of an example. Called "root" because it serves
# as the root of the space stack.
class RootSpace
def proxy_for(*_args)
raise_... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/method_reference.rb | Ruby | mit | 93 | main | 6,483 | module RSpec
module Mocks
# Represents a method on an object that may or may not be defined.
# The method may be an instance method on a module or a method on
# any object.
#
# @private
class MethodReference
def self.for(object_reference, method_name)
new(object_reference, method... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/message_expectation.rb | Ruby | mit | 93 | main | 30,114 | RSpec::Support.require_rspec_support 'reentrant_mutex'
module RSpec
module Mocks
# A message expectation that only allows concrete return values to be set
# for a message. While this same effect can be achieved using a standard
# MessageExpectation, this version is much faster and so can be used as an
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/argument_matchers.rb | Ruby | mit | 93 | main | 10,265 | # This cannot take advantage of our relative requires, since this file is a
# dependency of `rspec/mocks/argument_list_matcher.rb`. See comment there for
# details.
require 'rspec/support/matcher_definition'
module RSpec
module Mocks
# ArgumentMatchers are placeholders that you can include in message
# expec... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/message_chain.rb | Ruby | mit | 93 | main | 2,310 | module RSpec
module Mocks
# @private
class MessageChain
attr_reader :object, :chain, :block
def initialize(object, *chain, &blk)
@object = object
@chain, @block = format_chain(*chain, &blk)
end
# @api private
def setup_chain
if chain.length > 1
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/test_double.rb | Ruby | mit | 93 | main | 5,257 | module RSpec
module Mocks
# Implements the methods needed for a pure test double. RSpec::Mocks::Double
# includes this module, and it is provided for cases where you want a
# pure test double without subclassing RSpec::Mocks::Double.
module TestDouble
# Creates a new test double with a `name` (... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/instance_method_stasher.rb | Ruby | mit | 93 | main | 1,921 | module RSpec
module Mocks
# @private
class InstanceMethodStasher
def initialize(object, method)
@object = object
@method = method
# We don't want to create singleton class if it doesn't exist,
# so we don't use `object.singleton_class`.
@klass = (class << object; ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/verifying_message_expectation.rb | Ruby | mit | 93 | main | 1,988 | RSpec::Support.require_rspec_support 'method_signature_verifier'
module RSpec
module Mocks
# A message expectation that knows about the real implementation of the
# message being expected, so that it can verify that any expectations
# have the valid arguments.
# @api private
class VerifyingMessag... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/example_methods.rb | Ruby | mit | 93 | main | 19,350 | RSpec::Support.require_rspec_mocks 'object_reference'
module RSpec
module Mocks
# Contains methods intended to be used from within code examples.
# Mix this in to your test context (such as a test framework base class)
# to use rspec-mocks with your test framework. If you're using rspec-core,
# it'll... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/object_reference.rb | Ruby | mit | 93 | main | 4,505 | module RSpec
module Mocks
# @private
class ObjectReference
# Returns an appropriate Object or Module reference based
# on the given argument.
def self.for(object_module_or_name, allow_direct_object_refs=false)
case object_module_or_name
when Module
if anonymous_modu... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/proxy.rb | Ruby | mit | 93 | main | 16,461 | RSpec::Support.require_rspec_support "reentrant_mutex"
module RSpec
module Mocks
# @private
class Proxy
# @private
SpecificMessage = Struct.new(:object, :message, :args) do
def ==(expectation)
expectation.orig_object == object && expectation.matches?(message, *args)
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/verifying_proxy.rb | Ruby | mit | 93 | main | 7,160 | RSpec::Support.require_rspec_mocks 'verifying_message_expectation'
RSpec::Support.require_rspec_mocks 'method_reference'
module RSpec
module Mocks
# @private
class CallbackInvocationStrategy
def call(doubled_module)
RSpec::Mocks.configuration.verifying_double_callbacks.each do |block|
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/mutate_const.rb | Ruby | mit | 93 | main | 10,665 | RSpec::Support.require_rspec_support 'recursive_const_methods'
module RSpec
module Mocks
# Provides information about constants that may (or may not)
# have been mutated by rspec-mocks.
class Constant
extend Support::RecursiveConstMethods
# @api private
def initialize(name)
@na... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/configuration.rb | Ruby | mit | 93 | main | 5,114 | module RSpec
module Mocks
# Provides configuration options for rspec-mocks.
class Configuration
def initialize
@allow_message_expectations_on_nil = nil
@yield_receiver_to_any_instance_implementation_blocks = true
@verify_doubled_constant_names = false
@transfer_nested_con... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/order_group.rb | Ruby | mit | 93 | main | 2,206 | RSpec::Support.require_rspec_support 'reentrant_mutex'
module RSpec
module Mocks
# @private
class OrderGroup
def initialize
@expectations = []
@invocation_order = []
@invocation_order_mutex = Support::Mutex.new
@index = 0
end
# @private
def register(ex... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/minitest_integration.rb | Ruby | mit | 93 | main | 1,857 | require 'rspec/mocks'
module RSpec
module Mocks
# @private
module MinitestIntegration
include ::RSpec::Mocks::ExampleMethods
def before_setup
::RSpec::Mocks.setup
super
end
def after_teardown
super
# Only verify if there's not already an error. Other... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/targets.rb | Ruby | mit | 93 | main | 3,456 | module RSpec
module Mocks
# @private
module TargetDelegationClassMethods
def delegate_to(matcher_method)
define_method(:to) do |matcher, &block|
unless matcher_allowed?(matcher)
raise_unsupported_matcher(:to, matcher)
end
define_matcher(matcher, matcher_... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/method_double.rb | Ruby | mit | 93 | main | 10,861 | module RSpec
module Mocks
# @private
class MethodDouble
# @private
attr_reader :method_name, :object, :expectations, :stubs, :method_stasher
# @private
def initialize(object, method_name, proxy)
@method_name = method_name
@object = object
@proxy = proxy
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/argument_list_matcher.rb | Ruby | mit | 93 | main | 4,758 | # We intentionally do not use the `RSpec::Support.require...` methods
# here so that this file can be loaded individually, as documented
# below.
require 'rspec/mocks/argument_matchers'
require 'rspec/support/fuzzy_matcher'
module RSpec
module Mocks
# Wrapper for matching arguments against a list of expected val... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/version.rb | Ruby | mit | 93 | main | 203 | module RSpec
module Mocks
# Version information for RSpec mocks.
module Version
# Version of RSpec mocks currently in use in SemVer format.
STRING = '4.0.0.beta1'
end
end
end |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/marshal_extension.rb | Ruby | mit | 93 | main | 1,170 | module RSpec
module Mocks
# Support for `patch_marshal_to_support_partial_doubles` configuration.
#
# @private
class MarshalExtension
def self.patch!
return if Marshal.respond_to?(:dump_with_rspec_mocks)
Marshal.instance_eval do
class << self
def dump_with_... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/verifying_double.rb | Ruby | mit | 93 | main | 3,545 | RSpec::Support.require_rspec_mocks 'verifying_proxy'
module RSpec
module Mocks
# @private
module VerifyingDouble
def respond_to?(message, include_private=false)
return super unless null_object?
method_ref = __mock_proxy.method_reference[message]
case method_ref.visibility
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance.rb | Ruby | mit | 93 | main | 309 | %w[
any_instance/chain
any_instance/error_generator
any_instance/stub_chain
any_instance/stub_chain_chain
any_instance/expect_chain_chain
any_instance/expectation_chain
any_instance/message_chains
any_instance/recorder
any_instance/proxy
].each { |f| RSpec::Support.require_rspec_mocks(f) } |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/error_generator.rb | Ruby | mit | 93 | main | 1,200 | module RSpec
module Mocks
module AnyInstance
# @private
class ErrorGenerator < ::RSpec::Mocks::ErrorGenerator
def raise_second_instance_received_message_error(unfulfilled_expectations)
__raise "Exactly one instance should have received the following " \
"message(s) ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/message_chains.rb | Ruby | mit | 93 | main | 2,446 | module RSpec
module Mocks
module AnyInstance
# @private
class MessageChains
def initialize
@chains_by_method_name = Hash.new { |h, k| h[k] = [] }
end
# @private
def [](method_name)
@chains_by_method_name[method_name]
end
# @private
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/expectation_chain.rb | Ruby | mit | 93 | main | 1,237 | module RSpec
module Mocks
module AnyInstance
# @private
class ExpectationChain < Chain
def expectation_fulfilled?
@expectation_fulfilled || constrained_to_any_of?(:never)
end
def initialize(*args, &block)
@expectation_fulfilled = false
super
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/stub_chain_chain.rb | Ruby | mit | 93 | main | 488 | module RSpec
module Mocks
module AnyInstance
# @private
class StubChainChain < StubChain
def initialize(*args)
super
@expectation_fulfilled = false
end
private
def create_message_expectation_on(instance)
::RSpec::Mocks::StubChain.stub_chain... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/recorder.rb | Ruby | mit | 93 | main | 10,747 | module RSpec
module Mocks
module AnyInstance
# Given a class `TheClass`, `TheClass.any_instance` returns a `Recorder`,
# which records stubs and message expectations for later playback on
# instances of `TheClass`.
#
# Further constraints are stored in instances of [Chain](Chain).
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/proxy.rb | Ruby | mit | 93 | main | 4,545 | module RSpec
module Mocks
module AnyInstance
# @private
# The `AnyInstance::Recorder` is responsible for redefining the klass's
# instance method in order to add any stubs/expectations the first time
# the method is called. It's not capable of updating a stub on an instance
# that's ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/chain.rb | Ruby | mit | 93 | main | 2,997 | module RSpec
module Mocks
# @private
module AnyInstance
# @private
class Chain
def initialize(recorder, *args, &block)
@recorder = recorder
@expectation_args = args
@expectation_block = block
@argument_list_matcher = ArgumentListMatcher::MA... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/expect_chain_chain.rb | Ruby | mit | 93 | main | 674 | module RSpec
module Mocks
module AnyInstance
# @private
class ExpectChainChain < StubChain
def initialize(*args)
super
@expectation_fulfilled = false
end
def expectation_fulfilled?
@expectation_fulfilled
end
def playback!(instance... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/any_instance/stub_chain.rb | Ruby | mit | 93 | main | 1,400 | module RSpec
module Mocks
module AnyInstance
# @private
class StubChain < Chain
# @private
def expectation_fulfilled?
true
end
private
def create_message_expectation_on(instance)
proxy = ::RSpec::Mocks.space.proxy_for(instance)
meth... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/matchers/receive_messages.rb | Ruby | mit | 93 | main | 2,325 | module RSpec
module Mocks
module Matchers
# @private
class ReceiveMessages
include Matcher
def initialize(message_return_value_hash)
@message_return_value_hash = message_return_value_hash
@backtrace_line = CallerFilter.first_non_rspec_line
end
def ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/matchers/have_received.rb | Ruby | mit | 93 | main | 3,784 | module RSpec
module Mocks
module Matchers
# @private
class HaveReceived
include Matcher
COUNT_CONSTRAINTS = %w[exactly at_least at_most times time once twice thrice]
ARGS_CONSTRAINTS = %w[with]
CONSTRAINTS = COUNT_CONSTRAINTS + ARGS_CONSTRAINTS + %w[ordered]
d... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/matchers/receive_message_chain.rb | Ruby | mit | 93 | main | 2,459 | RSpec::Support.require_rspec_mocks 'matchers/expectation_customization'
module RSpec
module Mocks
module Matchers
# @private
class ReceiveMessageChain
include Matcher
def initialize(chain, &block)
@chain = chain
@block = block
@recorded_customizations =... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/matchers/receive.rb | Ruby | mit | 93 | main | 4,484 | RSpec::Support.require_rspec_mocks 'matchers/expectation_customization'
module RSpec
module Mocks
module Matchers
# @private
class Receive
include Matcher
def initialize(message, block)
@message = message
@block = block
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/lib/rspec/mocks/matchers/expectation_customization.rb | Ruby | mit | 93 | main | 433 | module RSpec
module Mocks
module Matchers
# @private
class ExpectationCustomization
attr_accessor :block
def initialize(method_name, args, block)
@method_name = method_name
@args = args
@block = block
end
def playback_onto(ex... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/spec_helper.rb | Ruby | mit | 93 | main | 3,566 | require 'rspec/support/spec'
# Preload io/console on MacOS JRuby to avoid warnings later due to https://github.com/jruby/jruby/issues/8271
require 'io/console' if RSpec::Support::Ruby.jruby? && RSpec::Support::OS.apple_silicon?
RSpec::Support::Spec::Coverage.setup do
minimum_coverage 98
end
require 'yaml'
begin
r... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/integration/rails_support_spec.rb | Ruby | mit | 93 | main | 1,513 | require File.expand_path('../../support/aruba', __FILE__)
RSpec.describe "Supporting Rails monkey patches", :type => :aruba do
it "works when Rails has monkey patched #with" do
write_file(
"spec/with_monkey_patch_spec.rb",
"""
class Object
# Rails monkey patches in **kwargs but this is ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks_spec.rb | Ruby | mit | 93 | main | 6,209 | require 'rspec/support/spec/library_wide_checks'
RSpec.describe RSpec::Mocks do
lib_preamble = [
# We define minitest constants because rspec/mocks/minitest_integration
# expects these constants to already be defined.
"module Minitest; class Assertion; end; module Test; end; end",
'require "rspec/moc... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/array_including_matcher_spec.rb | Ruby | mit | 93 | main | 2,659 | module RSpec
module Mocks
module ArgumentMatchers
RSpec.describe ArrayIncludingMatcher do
it "describes itself properly" do
expect(ArrayIncludingMatcher.new([1, 2, 3]).description).to eq "array_including(1, 2, 3)"
end
it "describes passed matchers" do
description... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/formatting_spec.rb | Ruby | mit | 93 | main | 3,465 | require 'rspec/matchers/fail_matchers'
require 'support/doubled_classes'
RSpec.describe "Test doubles format well in failure messages" do
include RSpec::Matchers::FailMatchers
RSpec::Matchers.define :format_in_failures_as do |expected|
match do |dbl|
values_match?(expected, actual_formatting(dbl))
e... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/thrice_counts_spec.rb | Ruby | mit | 93 | main | 2,394 | module RSpec
module Mocks
RSpec.describe "#thrice" do
before(:each) do
@double = double("test double")
end
it "passes when called thrice" do
expect(@double).to receive(:do_something).thrice
3.times { @double.do_something }
verify @double
end
it "pass... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/example_methods_spec.rb | Ruby | mit | 93 | main | 1,268 | module RSpec
module Mocks
RSpec.describe ExampleMethods do
it 'does not define private helper methods since it gets included into a ' \
'namespace where users define methods and could inadvertently overwrite ' \
'them' do
expect(ExampleMethods.private_instance_methods).to eq([])
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/hash_including_matcher_spec.rb | Ruby | mit | 93 | main | 3,863 | module RSpec
module Mocks
module ArgumentMatchers
RSpec.describe HashIncludingMatcher do
it "describes itself properly" do
message =
if RUBY_VERSION.to_f > 3.3
"hash_including(a: 1)"
else
"hash_including(:a=>1)"
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/mock_ordering_spec.rb | Ruby | mit | 93 | main | 3,557 | module RSpec
module Mocks
RSpec.describe "ordering" do
before { @double = double("test double") }
after { reset @double }
it "passes when messages are received in order" do
expect(@double).to receive(:one).ordered
expect(@double).to receive(:two).ordered
expect(@double)... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/combining_implementation_instructions_spec.rb | Ruby | mit | 93 | main | 6,799 | module RSpec
module Mocks
RSpec.describe "Combining implementation instructions" do
it 'can combine and_yield and and_return' do
dbl = double
allow(dbl).to receive(:foo).and_yield(5).and_return(3)
expect { |b|
expect(dbl.foo(&b)).to eq(3)
}.to yield_with_args(5)
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/serialization_spec.rb | Ruby | mit | 93 | main | 2,692 | module RSpec
module Mocks
RSpec.describe "Serialization of mocked objects" do
include_context "with monkey-patched marshal"
class SerializableObject < Struct.new(:foo, :bar); end
def self.with_yaml_loaded(&block)
context 'with YAML loaded' do
module_exec(&block)
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/spy_spec.rb | Ruby | mit | 93 | main | 3,214 | require "spec_helper"
RSpec.describe "the spy family of methods" do
describe "spy" do
it "responds to arbitrary methods" do
expect(spy.respond_to?(:foo)).to be true
end
it "takes a name" do
expect(spy(:bacon_bits).inspect).to include("bacon_bits")
end
it "records called methods" do
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/stash_spec.rb | Ruby | mit | 93 | main | 1,140 | module RSpec
module Mocks
RSpec.describe "only stashing the original method" do
let(:klass) do
Class.new do
def self.foo(_)
:original_value
end
end
end
it "keeps the original method intact after multiple expectations are added on the same method" ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb | Ruby | mit | 93 | main | 3,339 | module RSpec
module Mocks
RSpec.describe ".allow_message" do
let(:subject) { Object.new }
it "sets up basic message allowance" do
expect {
::RSpec::Mocks.allow_message(subject, :basic)
}.to change {
subject.respond_to?(:basic)
}.to(true)
expect(sub... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/marshal_extension_spec.rb | Ruby | mit | 93 | main | 2,193 | RSpec.describe Marshal, 'extensions' do
# An object that raises when code attempts to dup it.
#
# Because we manipulate the internals of RSpec::Mocks.space below, we need
# an object that simply blows up when #dup is called without using any
# partial mocking or stubbing from rspec-mocks itself.
class Undup... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/hash_excluding_matcher_spec.rb | Ruby | mit | 93 | main | 2,558 | module RSpec
module Mocks
module ArgumentMatchers
RSpec.describe HashExcludingMatcher do
it "describes itself properly" do
message =
if RUBY_VERSION.to_f > 3.3
"hash_not_including(a: 5)"
else
"hash_not_including(:a=>5)"
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/mock_expectation_error_spec.rb | Ruby | mit | 93 | main | 377 | module RSpec
module Mocks
RSpec.describe 'MockExpectationError' do
class Foo
def self.foo
bar
rescue StandardError
end
end
it 'is not caught by StandardError rescue blocks' do
expect(Foo).not_to receive(:bar)
expect_fast_failure_from(Foo) do
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/null_object_double_spec.rb | Ruby | mit | 93 | main | 3,880 | module RSpec
module Mocks
RSpec.describe "a double _not_ acting as a null object" do
before(:each) do
@double = double('non-null object')
end
it "says it does not respond to messages it doesn't understand" do
expect(@double).not_to respond_to(:foo)
end
it "says it r... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/stub_chain_spec.rb | Ruby | mit | 93 | main | 6,709 | module RSpec
module Mocks
RSpec.describe "A chained method stub" do
let(:object) { Object.new }
it 'does not get confused by symbol vs string usage for the messages' do
allow(object).to receive_message_chain(:foo, :bar => 1)
allow(object).to receive_message_chain("foo", :bazz => 2)
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/instance_method_stasher_spec.rb | Ruby | mit | 93 | main | 2,356 | module RSpec
module Mocks
RSpec.describe InstanceMethodStasher do
class ExampleClass
def hello
:hello_defined_on_class
end
end
def singleton_class_for(obj)
class << obj; self; end
end
def stasher_for(obj, method_name)
InstanceMethodStasher.... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/at_least_spec.rb | Ruby | mit | 93 | main | 5,265 | module RSpec
module Mocks
RSpec.describe "at_least" do
before(:each) { @double = double }
it "fails if method is never called" do
expect(@double).to receive(:do_something).at_least(4).times
expect {
verify @double
}.to raise_error(/expected: at least 4 times.*receive... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/precise_counts_spec.rb | Ruby | mit | 93 | main | 2,068 | module RSpec
module Mocks
RSpec.describe "PreciseCounts" do
before(:each) do
@double = double("test double")
end
it "fails when exactly n times method is called less than n times" do
expect(@double).to receive(:do_something).exactly(3).times
@double.do_something
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/block_return_value_spec.rb | Ruby | mit | 93 | main | 2,209 | RSpec.describe "a double declaration with a block handed to:" do
describe "expect(...).to receive" do
it "returns the value of executing the block" do
obj = Object.new
expect(obj).to receive(:foo) { 'bar' }
expect(obj.foo).to eq('bar')
end
it "works when a multi-return stub has already ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/and_return_spec.rb | Ruby | mit | 93 | main | 567 | module RSpec
module Mocks
RSpec.describe 'and_return' do
let(:obj) { double('obj') }
context 'when a block is passed' do
it 'raises ArgumentError' do
expect {
allow(obj).to receive(:foo).and_return('bar') { 'baz' }
}.to raise_error(ArgumentError, /implementatio... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/once_counts_spec.rb | Ruby | mit | 93 | main | 2,824 | module RSpec
module Mocks
RSpec.describe "#once" do
before(:each) do
@double = double
end
it "passes when called once" do
expect(@double).to receive(:do_something).once
@double.do_something
verify @double
end
it "passes when called once with specifie... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/double_spec.rb | Ruby | mit | 93 | main | 31,074 | module RSpec
module Mocks
RSpec.describe Double do
before(:each) { @double = double("test double") }
after(:each) { reset @double }
it "has method_missing as private" do
expect(RSpec::Mocks::Double.private_instance_methods).to include_method(:method_missing)
end
it "does n... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/mutex_spec.rb | Ruby | mit | 93 | main | 462 | module RSpec
module Mocks
RSpec.describe "Mocking Mutex" do
let(:mocked_mutex) { instance_double(Mutex) }
before do
allow(Mutex).to receive(:new).and_return(mocked_mutex)
allow(mocked_mutex).to receive(:synchronize).and_yield
end
it "successfully yields" do
called ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/and_call_original_spec.rb | Ruby | mit | 93 | main | 12,126 | require 'delegate'
RSpec.describe "and_call_original" do
context "on a partial double" do
let(:klass) do
Class.new do
def meth_1
:original
end
def meth_2(x)
yield x, :additional_yielded_arg
end
def meth_3(**kwargs)
kwargs
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/stubbed_message_expectations_spec.rb | Ruby | mit | 93 | main | 3,205 | RSpec.describe "expectation set on previously stubbed method" do
it "fails if message is not received after expectation is set" do
dbl = double(:msg => nil)
dbl.msg
expect(dbl).to receive(:msg)
expect { verify dbl }.to fail
end
it "outputs arguments of similar calls" do
dbl = double('double',... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/configuration_spec.rb | Ruby | mit | 93 | main | 635 | module RSpec
module Mocks
RSpec.describe Configuration do
let(:config) { Configuration.new }
describe "#when_declaring_verifying_double" do
include_context 'with isolated configuration'
it "captures the supplied blocks" do
block = proc { |ref| ref }
block2 = proc ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/error_generator_spec.rb | Ruby | mit | 93 | main | 2,857 | require "spec_helper"
module RSpec
module Mocks
RSpec.describe ErrorGenerator do
context "when inserting a backtrace line" do
def has_java_frames?
yield
rescue RSpec::Mocks::MockExpectationError => e
e.backtrace.grep(/\.java:/).any?
else
raise "got no e... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/space_spec.rb | Ruby | mit | 93 | main | 8,303 | module RSpec::Mocks
RSpec.describe Space do
let(:space) { Space.new }
let(:dbl_1) { Object.new }
let(:dbl_2) { Object.new }
describe "#verify_all" do
it "verifies all mocks within" do
verifies = []
allow(space.proxy_for(dbl_1)).to receive(:verify) { verifies << :dbl_1 }
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/multiple_invoke_handler_spec.rb | Ruby | mit | 93 | main | 4,255 | module RSpec
module Mocks
RSpec.describe "a message expectation with multiple invoke handlers and no specified count" do
let(:a_double) { double }
before(:each) do
expect(a_double).to receive(:do_something).and_invoke(lambda { 1 }, lambda { raise "2" }, lambda { 3 })
end
it "invo... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/at_most_spec.rb | Ruby | mit | 93 | main | 4,481 | module RSpec
module Mocks
RSpec.describe "at_most" do
before(:each) do
@double = double
end
it "passes when at_most(n) is called exactly 1 time" do
expect(@double).to receive(:do_something).at_most(1).time
@double.do_something
verify @double
end
it "... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/expiration_spec.rb | Ruby | mit | 93 | main | 2,542 | module RSpec
module Mocks
RSpec.describe "After a test double has been torn down" do
RSpec.shared_examples_for "expiration" do
before do
expect(dbl).to receive(:foo).at_least(:once)
allow(dbl).to receive(:bar)
dbl.foo
RSpec::Mocks.verify
RSpec::Mock... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/nil_expectation_warning_spec.rb | Ruby | mit | 93 | main | 2,081 | module RSpec
module Mocks
RSpec.describe "an expectation set on nil" do
it "issues a warning with file and line number information" do
expect {
expect(nil).to receive(:foo)
}.to output(a_string_including(
"An expectation of `:foo` was set on `nil`",
"#{__FILE__}... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/reraising_eager_raises_spec.rb | Ruby | mit | 93 | main | 5,222 | require "spec_helper"
RSpec.describe "Reraising eager raises during the verify step" do
it "does not reraise when a double receives a message that hasn't been allowed/expected" do
with_unfulfilled_double do |dbl|
expect { dbl.foo }.to fail
expect { verify_all }.not_to raise_error
end
end
con... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/and_invoke_spec.rb | Ruby | mit | 93 | main | 1,927 | module RSpec
module Mocks
RSpec.describe 'and_invoke' do
let(:obj) { double('obj') }
context 'when a block is passed' do
it 'raises ArgumentError' do
expect {
allow(obj).to receive(:foo).and_invoke('bar') { 'baz' }
}.to raise_error(ArgumentError, /implementatio... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/multiple_return_value_spec.rb | Ruby | mit | 93 | main | 4,708 | module RSpec
module Mocks
RSpec.describe "a double stubbed with multiple return values" do
let(:a_double) { double }
before do
allow(a_double).to receive(:foo).and_return(:val_1, nil)
end
it 'can still set a message expectation with a single return value' do
expect(a_doub... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/twice_counts_spec.rb | Ruby | mit | 93 | main | 3,395 | module RSpec
module Mocks
RSpec.describe "#twice" do
before(:each) do
@double = double("test double")
end
it "passes when called twice" do
expect(@double).to receive(:do_something).twice
@double.do_something
@double.do_something
verify @double
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/and_yield_spec.rb | Ruby | mit | 93 | main | 5,313 | RSpec.describe RSpec::Mocks::Double do
let(:obj) { double }
describe "#and_yield" do
context 'when the method double has been constrained by `with`' do
it 'uses the default stub if the provided args do not match' do
allow(obj).to receive(:foo) { 15 }
allow(obj).to receive(:foo).with(:yie... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/standalone_spec.rb | Ruby | mit | 93 | main | 671 | require 'rspec/support/spec/in_sub_process'
main = self
RSpec.describe "Loading rspec/mocks/standalone" do
include RSpec::Support::InSubProcess
it "exposes the RSpec::Mocks API on `main`" do
in_sub_process do
require 'rspec/mocks/standalone'
main.instance_eval do
dbl = double
expec... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/any_instance_spec.rb | Ruby | mit | 93 | main | 57,821 | require 'delegate'
module AnyInstanceSpec
class GrandparentClass
def foo(_a)
'bar'
end
def grandparent_method
1
end
end
class ParentClass < GrandparentClass
def foo
super(:a)
end
def caller_of_parent_aliased_method
parent_aliased_method
end
alias pa... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/stub_implementation_spec.rb | Ruby | mit | 93 | main | 3,840 | module RSpec
module Mocks
RSpec.describe "stub implementation" do
describe "with no args" do
it "execs the block when called" do
obj = double
allow(obj).to receive(:foo) { :bar }
expect(obj.foo).to eq :bar
end
end
describe "with one arg" do
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/test_double_spec.rb | Ruby | mit | 93 | main | 3,599 | module RSpec
module Mocks
RSpec.describe TestDouble do
shared_examples "reserved_method" do |name, responds:, value: nil|
it "can be overridden with a stub" do
allow(obj).to receive(name) { :non_nil_value }
expect(obj.send(name)).to be(:non_nil_value)
end
it "res... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/message_expectation_string_representation_spec.rb | Ruby | mit | 93 | main | 1,414 | module RSpec
module Mocks
RSpec.describe MessageExpectation, "has a nice string representation" do
let(:test_double) { double }
example "for a raw message expectation on a test double" do
expect(allow(test_double).to receive(:foo)).to have_string_representation(
"#<RSpec::Mocks::Mes... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/argument_matchers_spec.rb | Ruby | mit | 93 | main | 19,544 | module RSpec
module Mocks
RSpec.describe "argument matchers matching" do
let(:a_double) { double }
after(:each, :reset => true) do
reset a_double
end
describe "boolean" do
it "accepts true as boolean" do
expect(a_double).to receive(:random_call).with(boolean)
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/before_all_spec.rb | Ruby | mit | 93 | main | 1,755 | require 'support/before_all_shared_example_group'
RSpec.describe "Using rspec-mocks features in before(:all) blocks" do
describe "#stub_const" do
include_examples "fails in a before(:all) block"
def use_rspec_mocks
stub_const("SomeNewConst", Class.new)
end
it 'does not stub the const' do
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.