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 | rspec-mocks/spec/rspec/mocks/partial_double_using_mocks_directly_spec.rb | Ruby | mit | 93 | main | 2,535 | module RSpec::Mocks
RSpec.describe "PartialDoubleUsingMocksDirectly" do
let(:klass) do
Class.new do
module MethodMissing
remove_method :method_missing rescue nil
def method_missing(m, *a, &b)
if m == :captured_by_method_missing
"response generated by met... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/and_wrap_original_spec.rb | Ruby | mit | 93 | main | 3,394 | RSpec.describe "and_wrap_original" do
context "on a partial double" do
let(:klass) do
Class.new do
def results
(1..100).to_a
end
end
end
let(:instance) { klass.new }
shared_examples "using and_wrap_original" do
it "allows us to modify the results of the or... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/order_group_spec.rb | Ruby | mit | 93 | main | 1,377 | RSpec.describe 'OrderGroup' do
let(:order_group) { ::RSpec::Mocks::OrderGroup.new }
describe '#consume' do
let(:ordered_1) { double :ordered? => true }
let(:ordered_2) { double :ordered? => true }
let(:unordered) { double :ordered? => false }
before do
order_group.register unordered
or... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/modifying_invoked_expectations_spec.rb | Ruby | mit | 93 | main | 1,299 | require "spec_helper"
RSpec.describe "Modifying invoked expectations" do
shared_examples_for "a customization on an invoked expectation" do |customization_method, *args|
it "raises when the #{customization_method} method is called, indicating the expectation has already been invoked" do
dbl = double
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/failure_notification_spec.rb | Ruby | mit | 93 | main | 2,574 | RSpec.describe "Failure notification" do
def capture_errors(&block)
errors = []
RSpec::Support.with_failure_notifier(Proc.new { |e, _opts| errors << e }, &block)
errors
end
it "uses the rspec-support notifier to support `aggregate_failures`" do
dbl = double("Foo")
expect(capture_errors { dbl... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/stub_spec.rb | Ruby | mit | 93 | main | 20,051 | module RSpec
module Mocks
RSpec.describe "A method stub" do
before(:each) do
@class = Class.new do
class << self
def existing_class_method
existing_private_class_method
end
private
def existing_private_class_method
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/partial_double_spec.rb | Ruby | mit | 93 | main | 21,544 | module RSpec
module Mocks
RSpec.describe "A partial double" do
let(:object) { Object.new }
it 'does not create an any_instance recorder when a message is allowed' do
expect {
allow(object).to receive(:foo)
}.not_to change { RSpec::Mocks.space.any_instance_recorders }.from({}... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/diffing_spec.rb | Ruby | mit | 93 | main | 11,718 | require "spec_helper"
require "pp"
# Spacing in diffs is important so we turn off this rule.
# rubocop:disable Layout/LineContinuationLeadingSpace
RSpec.describe "Diffs printed when arguments don't match" do
before do
allow(RSpec::Mocks.configuration).to receive(:color?).and_return(false)
end
context "with ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/mutate_const_spec.rb | Ruby | mit | 93 | main | 24,555 | TOP_LEVEL_VALUE_CONST = 7
class TestClass
M = :m
N = :n
class Nested
class NestedEvenMore
end
end
end
class TestClassThatDefinesSend
C = :c
def self.send
end
end
class TestSubClass < TestClass
P = :p
end
module RSpec
module Mocks
RSpec.describe "Constant Mutating" do
include RS... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/instance_double_with_class_not_loaded_spec.rb | Ruby | mit | 93 | main | 2,318 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec.describe 'An instance double with the doubled class not loaded' do
include_context "with isolated configuration"
before do
RSpec::Mocks.configuration.verify_doubled_constant_names = false
end
it 'includes the doub... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/object_double_spec.rb | Ruby | mit | 93 | main | 5,583 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec.describe 'An object double' do
let(:loaded_instance) { LoadedClass.new(1, 2) }
it 'can replace an unloaded constant' do
o = object_double("LoadedClass::NOINSTANCE").as_stubbed_const
expect(LoadedClass::NOINSTANCE).to ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/class_double_with_class_not_loaded_spec.rb | Ruby | mit | 93 | main | 2,335 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec.describe 'A class double with the doubled class not loaded' do
include_context "with isolated configuration"
before do
RSpec::Mocks.configuration.verify_doubled_constant_names = false
end
it 'includes the double n... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/naming_spec.rb | Ruby | mit | 93 | main | 2,652 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec::Matchers.define :fail_expectations_as do |expected|
description { "include a meaningful name in the exception" }
def error_message_for(_)
expect(actual).to have_received(:defined_instance_and_class_method)
rescue MockEx... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/method_visibility_spec.rb | Ruby | mit | 93 | main | 4,971 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec.describe "Method visibility for verified doubles" do
include_context "with isolated configuration"
before do
RSpec::Mocks.configuration.verify_doubled_constant_names = true
end
context "for an instance double (whe... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/class_double_with_class_loaded_spec.rb | Ruby | mit | 93 | main | 7,912 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec.describe 'A class double with the doubled class loaded' do
include_context "with isolated configuration"
before do
RSpec::Mocks.configuration.verify_doubled_constant_names = true
end
it 'only allows class methods ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/construction_spec.rb | Ruby | mit | 93 | main | 6,270 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec.describe 'Constructing a verifying double' do
include_context 'with isolated configuration'
class ClassThatDynamicallyDefinesMethods
def self.define_attribute_methods!
define_method(:some_method_defined_dynamically) ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/expected_arg_verification_spec.rb | Ruby | mit | 93 | main | 6,257 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec.describe 'Expected argument verification (when `#with` is called)' do
# Note: these specs here aren't meant to be exhaustive. The specs in
# rspec-support for the method signature verifier are. Here we are just
# covering the cod... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/verifying_doubles/instance_double_with_class_loaded_spec.rb | Ruby | mit | 93 | main | 9,116 | require 'support/doubled_classes'
module RSpec
module Mocks
RSpec.describe 'An instance double with the doubled class loaded' do
include_context "with isolated configuration"
before do
RSpec::Mocks.configuration.verify_doubled_constant_names = true
end
it 'only allows instance m... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/matchers/have_received_spec.rb | Ruby | mit | 93 | main | 28,235 | module RSpec
module Mocks
# This shared example group is highly unusual as it is used to test how
# `have_received` works in two situations:
#
# * With rspec-mocks as a standalone library.
# * Together with rspec-expectations.
#
# To simulate the former, we've had to hack things a bit. Spe... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/matchers/receive_messages_spec.rb | Ruby | mit | 93 | main | 5,512 | module RSpec
module Mocks
RSpec.shared_examples "complains when given blocks" do
it "complains if a { } block is given" do
expect {
target.to receive_messages(:a => 1) { "implementation" }
}.to raise_error "Implementation blocks aren't supported with `receive_messages`"
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/matchers/receive_message_chain_spec.rb | Ruby | mit | 93 | main | 7,964 | module RSpec::Mocks::Matchers
RSpec.describe "receive_message_chain" do
let(:object) { double(:object) }
it "errors with a negative allowance" do
expect {
allow(object).not_to receive_message_chain(:to_a)
}.to raise_error(RSpec::Mocks::NegationUnsupportedError)
end
it "errors wit... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/matchers/receive_spec.rb | Ruby | mit | 93 | main | 27,254 | module RSpec
module Mocks
# rubocop:disable Naming/MethodParameterName
RSpec.describe Matchers::Receive do
# FIXME: this is defined here to prevent
# "warning: method redefined; discarding old kw_args_method"
# because shared examples are evaluated several times.
# When we flatten thos... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/rspec/mocks/any_instance/message_chains_spec.rb | Ruby | mit | 93 | main | 1,535 | RSpec.describe RSpec::Mocks::AnyInstance::MessageChains do
let(:recorder) { double }
let(:chains) { RSpec::Mocks::AnyInstance::MessageChains.new }
let(:stub_chain) { RSpec::Mocks::AnyInstance::StubChain.new recorder }
let(:expectation_chain) { RSpec::Mocks::AnyInstance::PositiveExpectationChain.new recorder }
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/support/aruba.rb | Ruby | mit | 93 | main | 235 | require 'aruba/rspec'
Aruba.configure do |config|
if RUBY_PLATFORM =~ /java/ || defined?(Rubinius) || (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'truffleruby')
config.exit_timeout = 60
else
config.exit_timeout = 5
end
end |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/support/doubled_classes.rb | Ruby | mit | 93 | main | 1,447 | class LoadedClass
M = :m
N = :n
INSTANCE = LoadedClass.new
# rubocop:disable Lint/RedundantCopDisableDirective,Style/RedundantInitialize
def initialize(_a, _b)
end
# rubocop:enable Lint/RedundantCopDisableDirective,Style/RedundantInitialize
class << self
def respond_to?(method_name, include_all=fa... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/support/before_all_shared_example_group.rb | Ruby | mit | 93 | main | 455 | RSpec.shared_examples "fails in a before(:all) block" do
the_error = nil
before(:all) do
begin
use_rspec_mocks
rescue
the_error = $!
end
end
it "raises an error with a useful message" do
expect(the_error).to be_a_kind_of(RSpec::Mocks::OutsideOfExampleError)
expect(the_error.mes... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/spec/support/matchers.rb | Ruby | mit | 93 | main | 395 | module RSpec
module Matchers
def fail(&block)
raise_error(RSpec::Mocks::MockExpectationError, &block)
end
def fail_with(*args, &block)
raise_error(RSpec::Mocks::MockExpectationError, *args, &block)
end
def fail_including(*snippets)
raise_error(
RSpec::Mocks::MockExpecta... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/features/step_definitions/additional_cli_steps.rb | Ruby | mit | 93 | main | 1,025 | Then /^the example(?:s)? should(?: all)? pass$/ do
step %q(the output should contain "0 failures")
step %q(the exit status should be 0)
end
Then /^the examples should all fail, producing the following output:$/ do |table|
step %q(the exit status should be 1)
examples, failures = all_output.match(/(\d+) example... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/features/support/rubinius.rb | Ruby | mit | 93 | main | 226 | # Required until https://github.com/rubinius/rubinius/issues/2430 is resolved
ENV['RBXOPT'] = "#{ENV["RBXOPT"]} -Xcompiler.no_rbc"
Around "@unsupported-on-rbx" do |_scenario, block|
block.call unless defined?(Rubinius)
end |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-mocks/features/support/env.rb | Ruby | mit | 93 | main | 1,041 | require 'aruba/cucumber'
require 'rspec/expectations'
Aruba.configure do |config|
if RUBY_PLATFORM =~ /java/ || defined?(Rubinius) || (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'truffleruby')
config.exit_timeout = 60
else
config.exit_timeout = 5
end
end
Before do
if RUBY_PLATFORM == 'java'
# disable... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/Rakefile | Ruby | mit | 93 | main | 1,056 | # frozen_string_literal: true
require 'bundler'
Bundler.setup
Bundler::GemHelper.install_tasks
Bundler::GemHelper.tag_prefix = 'rspec-expectations-'
require 'rake'
require 'rspec/core/rake_task'
require 'rspec/expectations/version'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:cucumber)
require 'rubocop/ra... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/rspec-expectations.gemspec | Ruby | mit | 93 | main | 2,067 | # frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "rspec/expectations/version"
Gem::Specification.new do |s|
s.name = "rspec-expectations"
s.version = RSpec::Expectations::Version::STRING
s.platform = Gem::Platform::RUBY
s.license = "MIT"
s.autho... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/features/step_definitions/additional_cli_steps.rb | Ruby | mit | 93 | main | 1,597 | # frozen_string_literal: true
# Useful for when the output is slightly different on different versions of ruby
Then(/^the output should contain "([^"]*)" or "([^"]*)"$/) do |string1, string2|
unless [string1, string2].any? { |s| all_output.include?(s) }
fail %(Neither "#{string1}" or "#{string2}" were found in:\... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/features/support/rubinius.rb | Ruby | mit | 93 | main | 257 | # frozen_string_literal: true
# Required until https://github.com/rubinius/rubinius/issues/2430 is resolved
ENV['RBXOPT'] = "#{ENV["RBXOPT"]} -Xcompiler.no_rbc"
Around "@unsupported-on-rbx" do |_scenario, block|
block.call unless defined?(Rubinius)
end |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/features/support/ruby_features.rb | Ruby | mit | 93 | main | 310 | # frozen_string_literal: true
Around "@skip-when-ripper-unsupported" do |scenario, block|
require 'rspec/support/ruby_features'
if ::RSpec::Support::RubyFeatures.ripper_supported?
block.call
else
skip_this_scenario "Skipping scenario #{scenario.name} because Ripper is not supported"
end
end |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/features/support/env.rb | Ruby | mit | 93 | main | 552 | # frozen_string_literal: true
require 'aruba/cucumber'
Aruba.configure do |config|
if RUBY_PLATFORM =~ /java/ || defined?(Rubinius)
config.exit_timeout = 60
else
config.exit_timeout = 10
end
end
Before do
if RUBY_PLATFORM == 'java'
# disable JIT since these processes are so short lived
set_en... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/expectations.rb | Ruby | mit | 93 | main | 3,384 | # frozen_string_literal: true
require 'rspec/support'
RSpec::Support.require_rspec_support "caller_filter"
RSpec::Support.require_rspec_support "warnings"
RSpec::Support.require_rspec_support "object_formatter"
require 'rspec/matchers'
RSpec::Support.define_optimized_require_for_rspec(:expectations) { |f| require_re... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers.rb | Ruby | mit | 93 | main | 37,869 | # frozen_string_literal: true
require 'rspec/support'
RSpec::Support.require_rspec_support 'matcher_definition'
RSpec::Support.define_optimized_require_for_rspec(:matchers) { |f| require_relative(f) }
%w[
english_phrasing
composable
built_in
generated_descriptions
dsl
matcher_delegator
aliased_matcher
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/expectations/minitest_integration.rb | Ruby | mit | 93 | main | 1,730 | # frozen_string_literal: true
require 'rspec/expectations'
Minitest::Test.class_eval do
include ::RSpec::Matchers
# This `expect` will only be called if the user is using Minitest < 5.6
# or if they are _not_ using Minitest::Spec on 5.6+. Minitest::Spec on 5.6+
# defines its own `expect` and will have the as... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/expectations/handler.rb | Ruby | mit | 93 | main | 2,667 | # frozen_string_literal: true
module RSpec
module Expectations
# @private
module ExpectationHelper
def self.check_message(msg)
unless msg.nil? || msg.respond_to?(:to_str) || msg.respond_to?(:call)
RSpec.warning(
"ignoring the provided expectation message argument" \
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/expectations/fail_with.rb | Ruby | mit | 93 | main | 1,277 | # frozen_string_literal: true
module RSpec
module Expectations
class << self
# @private
class Differ
# @private
OBJECT_PREPARER = lambda do |object|
RSpec::Matchers::Composable.surface_descriptions_in(object)
end
end
# @private
def differ
R... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/expectations/expectation_target.rb | Ruby | mit | 93 | main | 6,015 | # frozen_string_literal: true
module RSpec
module Expectations
# Wraps the target of an expectation.
#
# @example
# expect(something) # => ExpectationTarget wrapping something
# expect { do_something } # => ExpectationTarget wrapping the block
#
# # used with `to`
# expe... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/expectations/configuration.rb | Ruby | mit | 93 | main | 5,259 | # frozen_string_literal: true
module RSpec
module Expectations
# Provides configuration options for rspec-expectations.
# If you are using rspec-core, you can access this via a
# block passed to `RSpec::Core::Configuration#expect_with`.
# Otherwise, you can access it via RSpec::Expectations.configura... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/expectations/block_snippet_extractor.rb | Ruby | mit | 93 | main | 7,400 | # frozen_string_literal: true
module RSpec
module Expectations
# @private
class BlockSnippetExtractor # rubocop:disable Metrics/ClassLength
# rubocop should properly handle `Struct.new {}` as an inner class definition.
attr_reader :proc, :method_name
def self.try_extracting_single_line_bo... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/expectations/failure_aggregator.rb | Ruby | mit | 93 | main | 8,423 | # frozen_string_literal: true
module RSpec
module Expectations
# @private
class FailureAggregator
attr_reader :block_label, :metadata
# @private
class AggregatedFailure
# :nocov:
# `inspect` was apparently used by some versions early in ruby 3 while constructing
# N... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in.rb | Ruby | mit | 93 | main | 3,205 | # frozen_string_literal: true
RSpec::Support.require_rspec_matchers "built_in/base_matcher"
module RSpec
module Matchers
# Container module for all built-in matchers. The matcher classes are here
# (rather than directly under `RSpec::Matchers`) in order to prevent name
# collisions, since `RSpec::Matche... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/aliased_matcher.rb | Ruby | mit | 93 | main | 4,302 | # frozen_string_literal: true
module RSpec
module Matchers
# Decorator that wraps a matcher and overrides `description`
# using the provided block in order to support an alias
# of a matcher. This is intended for use when composing
# matchers, so that you can use an expression like
# `include( a_... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/matcher_delegator.rb | Ruby | mit | 93 | main | 1,557 | # frozen_string_literal: true
module RSpec
module Matchers
# Provides a base class with as little methods as possible, so that
# most methods can be delegated via `method_missing`.
#
# BasicObject could be used for this purpose, but it introduces
# some extra complexity with constant resolution, ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/dsl.rb | Ruby | mit | 93 | main | 20,139 | # frozen_string_literal: true
RSpec::Support.require_rspec_support "with_keywords_when_needed"
module RSpec
module Matchers
# Defines the custom matcher DSL.
module DSL
# Defines a matcher alias. The returned matcher's `description` will be overridden
# to reflect the phrasing of the new name, w... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/multi_matcher_diff.rb | Ruby | mit | 93 | main | 2,622 | # frozen_string_literal: true
module RSpec
module Matchers
# @api private
# Handles list of expected and actual value pairs when there is a need
# to render multiple diffs. Also can handle one pair.
class MultiMatcherDiff
# @private
# Default diff label when there is only one matcher in d... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/english_phrasing.rb | Ruby | mit | 93 | main | 1,249 | # frozen_string_literal: true
module RSpec
module Matchers
# Facilitates converting ruby objects to English phrases.
module EnglishPhrasing
# Converts a symbol into an English expression.
#
# split_words(:banana_creme_pie) #=> "banana creme pie"
#
def self.split_words(sym)
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/composable.rb | Ruby | mit | 93 | main | 6,372 | # frozen_string_literal: true
RSpec::Support.require_rspec_support "fuzzy_matcher"
module RSpec
module Matchers
# Mixin designed to support the composable matcher features
# of RSpec 3+. Mix it into your custom matcher classes to
# allow them to be used in a composable fashion.
#
# @api public
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/matcher_protocol.rb | Ruby | mit | 93 | main | 5,109 | # frozen_string_literal: true
module RSpec
module Matchers
# rspec-expectations can work with any matcher object that implements this protocol.
#
# @note This class is not loaded at runtime by rspec-expectations. It exists
# purely to provide documentation for the matcher protocol.
class Matche... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/generated_descriptions.rb | Ruby | mit | 93 | main | 1,227 | # frozen_string_literal: true
module RSpec
module Matchers
class << self
# @private
attr_accessor :last_matcher, :last_expectation_handler
end
# @api private
# Used by rspec-core to clear the state used to generate
# descriptions after an example.
def self.clear_generated_descrip... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/fail_matchers.rb | Ruby | mit | 93 | main | 1,298 | # frozen_string_literal: true
require 'rspec/expectations'
module RSpec
module Matchers
# Matchers for testing RSpec matchers. Include them with:
#
# require 'rspec/matchers/fail_matchers'
# RSpec.configure do |config|
# config.include RSpec::Matchers::FailMatchers
# end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/contain_exactly.rb | Ruby | mit | 93 | main | 11,149 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `contain_exactly` and `match_array`.
# Not intended to be instantiated directly.
# rubocop:disable Metrics/ClassLength
class ContainExactly < BaseMatcher
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/output.rb | Ruby | mit | 93 | main | 6,594 | # frozen_string_literal: true
require 'stringio'
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `output`.
# Not intended to be instantiated directly.
class Output < BaseMatcher
def initialize(expected)
@expected = exp... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/match.rb | Ruby | mit | 93 | main | 2,587 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `match`.
# Not intended to be instantiated directly.
class Match < BaseMatcher
def initialize(expected)
super(expected)
@expected_capture... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/eql.rb | Ruby | mit | 93 | main | 1,095 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `eql`.
# Not intended to be instantiated directly.
class Eql < BaseMatcher
# @api private
# @return [String]
def failure_message
if ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/has.rb | Ruby | mit | 93 | main | 4,649 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for dynamic predicate matchers.
# Not intended to be inherited directly.
class DynamicPredicate < BaseMatcher
include BeHelpers
def initialize(method_nam... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/include.rb | Ruby | mit | 93 | main | 6,665 | # frozen_string_literal: true
require 'rspec/matchers/built_in/count_expectation'
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `include`.
# Not intended to be instantiated directly.
class Include < BaseMatcher # rubocop:disable Metrics/Clas... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/compound.rb | Ruby | mit | 93 | main | 9,973 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Base class for `and` and `or` compound matchers.
class Compound < BaseMatcher
# @private
attr_reader :matcher_1, :matcher_2, :evaluator
def initialize(matcher_1, matcher_2)
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/satisfy.rb | Ruby | mit | 93 | main | 1,587 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `satisfy`.
# Not intended to be instantiated directly.
class Satisfy < BaseMatcher
def initialize(description=nil, &block)
@description = descriptio... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/eq.rb | Ruby | mit | 93 | main | 1,209 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `eq`.
# Not intended to be instantiated directly.
class Eq < BaseMatcher
# @api private
# @return [String]
def failure_message
if st... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/change.rb | Ruby | mit | 93 | main | 14,287 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `change`.
# Not intended to be instantiated directly.
class Change < BaseMatcher
# @api public
# Specifies the delta of the expected change.
d... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/be_kind_of.rb | Ruby | mit | 93 | main | 647 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `be_a_kind_of`.
# Not intended to be instantiated directly.
class BeAKindOf < BaseMatcher
private
def match(expected, actual)
actual.kind_of?... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/raise_error.rb | Ruby | mit | 93 | main | 9,633 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `raise_error`.
# Not intended to be instantiated directly.
# rubocop:disable Metrics/ClassLength
# rubocop:disable Lint/RescueException
class RaiseError
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/all.rb | Ruby | mit | 93 | main | 2,506 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `all`.
# Not intended to be instantiated directly.
class All < BaseMatcher
# @private
attr_reader :matcher, :failed_objects
def initialize(ma... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/be.rb | Ruby | mit | 93 | main | 4,669 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `be_truthy`.
# Not intended to be instantiated directly.
class BeTruthy < BaseMatcher
# @api private
# @return [String]
def failure_message
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/base_matcher.rb | Ruby | mit | 93 | main | 6,511 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
#
# Used _internally_ as a base class for matchers that ship with
# rspec-expectations and rspec-rails.
#
# ### Warning:
#
# This class is for internal use, and subject to chan... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/be_within.rb | Ruby | mit | 93 | main | 1,874 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `be_within`.
# Not intended to be instantiated directly.
class BeWithin < BaseMatcher
def initialize(delta)
@delta = delta
end
# @a... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/equal.rb | Ruby | mit | 93 | main | 1,944 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `equal`.
# Not intended to be instantiated directly.
class Equal < BaseMatcher
# @api private
# @return [String]
def failure_message
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/cover.rb | Ruby | mit | 93 | main | 577 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `cover`.
# Not intended to be instantiated directly.
class Cover < BaseMatcher
def initialize(*expected)
@expected = expected
end
d... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/have_attributes.rb | Ruby | mit | 93 | main | 3,220 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `have_attributes`.
# Not intended to be instantiated directly.
class HaveAttributes < BaseMatcher
# @private
attr_reader :respond_to_failed
d... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/yield.rb | Ruby | mit | 93 | main | 9,904 | # frozen_string_literal: true
require 'rspec/matchers/built_in/count_expectation'
RSpec::Support.require_rspec_support 'method_signature_verifier'
module RSpec
module Matchers
module BuiltIn
# @private
# Object that is yielded to `expect` when one of the
# yield matchers is used. Provides inf... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/be_instance_of.rb | Ruby | mit | 93 | main | 794 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `be_an_instance_of`.
# Not intended to be instantiated directly.
class BeAnInstanceOf < BaseMatcher
# @api private
# @return [String]
def desc... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/throw_symbol.rb | Ruby | mit | 93 | main | 3,827 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `throw_symbol`.
# Not intended to be instantiated directly.
class ThrowSymbol
include Composable
def initialize(expected_symbol=nil, expected_arg=nil... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb | Ruby | mit | 93 | main | 6,957 | # frozen_string_literal: true
RSpec::Support.require_rspec_support "method_signature_verifier"
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `respond_to`.
# Not intended to be instantiated directly.
class RespondTo < BaseMatcher
def ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/start_or_end_with.rb | Ruby | mit | 93 | main | 2,569 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Base class for the `end_with` and `start_with` matchers.
# Not intended to be instantiated directly.
class StartOrEndWith < BaseMatcher
def initialize(*expected)
@actual_does_not_h... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/be_between.rb | Ruby | mit | 93 | main | 2,071 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `be_between`.
# Not intended to be instantiated directly.
class BeBetween < BaseMatcher
def initialize(min, max)
@min, @max = min, max
inc... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/exist.rb | Ruby | mit | 93 | main | 2,645 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Provides the implementation for `exist`.
# Not intended to be instantiated directly.
class Exist < BaseMatcher
def initialize(*expected)
@expected = expected
end
#... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/lib/rspec/matchers/built_in/count_expectation.rb | Ruby | mit | 93 | main | 4,910 | # frozen_string_literal: true
module RSpec
module Matchers
module BuiltIn
# @api private
# Abstract class to implement `once`, `at_least` and other
# count constraints.
module CountExpectation
# @api public
# Specifies that the method is expected to match once.
def... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/2.x_vs_3.x_matcher_dsl_implementation.rb | Ruby | mit | 93 | main | 10,135 | # frozen_string_literal: true
$LOAD_PATH.unshift "./lib"
require 'benchmark'
require 'rspec/expectations'
include RSpec::Expectations
include RSpec::Matchers
n = 1000
puts "3 runs of #{n} times for each example running rspec-expectations #{RSpec::Expectations::Version::STRING} -- #{RUBY_ENGINE}/#{RUBY_VERSION}"
pu... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/include_matcher.rb | Ruby | mit | 93 | main | 6,924 | # frozen_string_literal: true
require 'benchmark/ips'
require 'rspec/expectations'
include RSpec::Matchers
module RSpec
module Matchers
module BuiltIn
class OldInclude < BaseMatcher
def initialize(*expected)
@expected = expected
end
def matches?(actual)
@actua... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/method_to_proc.rb | Ruby | mit | 93 | main | 2,207 | # frozen_string_literal: true
require 'benchmark'
n = 10_000_000
puts "3 runs of #{n} times running #{RUBY_ENGINE}/#{RUBY_VERSION}"
def foo(x); end
def extract_method_proc(&b); b; end
Benchmark.benchmark do |bm|
puts "calling foo = method(:foo).to_proc"
foo_proc = method(:foo).to_proc
3.times do
bm.repo... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/count_vs_select_size.rb | Ruby | mit | 93 | main | 2,835 | # frozen_string_literal: true
require 'benchmark/ips'
[10, 100, 1000, 10_000, 100_000].each do |array_size|
array = (1..array_size).to_a
Benchmark.ips do |ips|
ips.report("#select { true }.size for #{array_size}") do
array.select { true }.size
end
ips.report("#count { true } for #{array_size}")... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/autoload_v_require.rb | Ruby | mit | 93 | main | 650 | # frozen_string_literal: true
require 'benchmark'
n = 10
Benchmark.benchmark do |bm|
3.times do
bm.report do
n.times do
`bin/rspec benchmarks/example_spec.rb`
end
end
end
end
# Before autoloading matcher class files
# 0.000000 0.010000 8.800000 ( 8.906383)
# 0.010000 0.0... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/include_v_superclass.rb | Ruby | mit | 93 | main | 768 | # frozen_string_literal: true
require 'benchmark'
n = 10_000
class Foo; end
module Bar; end
Benchmark.benchmark do |bm|
puts "Class.new(Foo)"
3.times do
bm.report do
n.times do
Class.new(Foo)
end
end
end
puts "Class.new { include Bar }"
3.times do
bm.report do
n.t... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/set_vs_array_include.rb | Ruby | mit | 93 | main | 2,604 | # frozen_string_literal: true
require 'benchmark'
require 'set'
n = 10_000_000
array = [
:@name, :@declarations, :@diffable, :@messages,
:@match_block, :@match_for_should_not_block,
:@expected_exception
]
set = array.to_set
puts "Positive examples: "
Benchmark.bm(25) do |x|
array.each_with_index do |var, i|... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/cloning_matchers.rb | Ruby | mit | 93 | main | 348 | # frozen_string_literal: true
require 'benchmark'
require 'rspec/expectations'
include RSpec::Matchers
n = 1_000_000
matcher = eq(3)
Benchmark.bm do |x|
x.report do
n.times { matcher.clone }
end
end
__END__
We can do about 1000 clones per ms:
user system total real
1.080000 0.030... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/output_stringio_vs_tempfile.rb | Ruby | mit | 93 | main | 1,017 | # frozen_string_literal: true
require 'rubygems'
require 'bundler/setup'
require 'benchmark'
require 'rspec/expectations'
include RSpec::Matchers
n = 100_000
Benchmark.bm(25) do |bm|
bm.report("to_stdout with StringIO") do
n.times { expect {}.not_to output('foo').to_stdout }
end
bm.report("to_stdout with ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/gsub_vs_tr_single_character.rb | Ruby | mit | 93 | main | 656 | # frozen_string_literal: true
require 'benchmark/ips'
Benchmark.ips do |x|
y = '1_2_3_4_5_6_7_8_9_10'
x.report('gsub') do |_times|
y.tr('_', ' ')
end
x.report('tr') do |_times|
y.tr('_', ' ')
end
x.compare!
end
__END__
Calculating -------------------------------------
gsub ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/matcher_dsl_vs_classes.rb | Ruby | mit | 93 | main | 5,012 | # frozen_string_literal: true
require 'benchmark'
require 'rspec/expectations'
include RSpec::Expectations
include RSpec::Matchers
RSpec::Matchers.define :eq_using_dsl do |expected|
match do |actual|
actual == expected
end
end
n = 1000
puts "3 runs of #{n} times for each example running #{RUBY_ENGINE}/#{RU... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/default_messages_as_methods_v_blocks.rb | Ruby | mit | 93 | main | 507 | # frozen_string_literal: true
require 'benchmark'
require 'rspec/expectations'
include RSpec::Expectations
include RSpec::Matchers
RSpec::Matchers.define :eq_using_dsl do |expected|
match do |actual|
actual == expected
end
end
n = 10_000
Benchmark.benchmark do |bm|
3.times do
bm.report do
n.tim... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/caller_vs_raise_for_backtrace.rb | Ruby | mit | 93 | main | 2,156 | # frozen_string_literal: true
require 'benchmark/ips'
def create_stack_trace(n, &block)
return create_stack_trace(n - 1, &block) if n > 0
yield
end
[10, 50, 100].each do |frames|
create_stack_trace(frames) do
Benchmark.ips do |x|
x.report("use caller (#{caller.count} frames)") do
exception = ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/match_array/failing_with_distinct_items.rb | Ruby | mit | 93 | main | 6,398 | # frozen_string_literal: true
$LOAD_PATH.unshift "./lib"
require 'benchmark'
require 'rspec/expectations'
require 'securerandom'
extend RSpec::Matchers
sizes = [10, 100, 1000, 2000, 4000]
puts "rspec-expectations #{RSpec::Expectations::Version::STRING} -- #{RUBY_ENGINE}/#{RUBY_VERSION}"
puts
puts "Failing `match_a... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/match_array/passing_with_distinct_items.rb | Ruby | mit | 93 | main | 7,026 | # frozen_string_literal: true
$LOAD_PATH.unshift "./lib"
require 'benchmark'
require 'rspec/expectations'
require 'securerandom'
extend RSpec::Matchers
sizes = [10, 100, 1000, 2000, 4000]
puts "rspec-expectations #{RSpec::Expectations::Version::STRING} -- #{RUBY_ENGINE}/#{RUBY_VERSION}"
puts
puts "Passing `match_a... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/match_array/failing_with_duplicate_items.rb | Ruby | mit | 93 | main | 4,752 | # frozen_string_literal: true
$LOAD_PATH.unshift "./lib"
require 'benchmark'
require 'rspec/expectations'
extend RSpec::Matchers
sizes = [10, 100, 1000]
puts "rspec-expectations #{RSpec::Expectations::Version::STRING} -- #{RUBY_ENGINE}/#{RUBY_VERSION}"
puts
puts "Failing `match_array` expectation with lists of int... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/match_array/passing_with_duplicate_items.rb | Ruby | mit | 93 | main | 5,812 | # frozen_string_literal: true
$LOAD_PATH.unshift "./lib"
require 'benchmark'
require 'rspec/expectations'
extend RSpec::Matchers
sizes = [10, 100, 1000, 2000]
puts "rspec-expectations #{RSpec::Expectations::Version::STRING} -- #{RUBY_ENGINE}/#{RUBY_VERSION}"
puts
puts "Passing `match_array` expectation with lists ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/benchmarks/match_array/rubyprof/passing_with_distinct_items.rb | Ruby | mit | 93 | main | 252 | # frozen_string_literal: true
$LOAD_PATH.unshift "./lib"
require 'rspec/expectations'
require 'securerandom'
extend RSpec::Matchers
actual = Array.new(1000) { SecureRandom.uuid }
expected = actual.shuffle
expect(actual).to match_array(expected) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.