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-expectations/spec/spec_helper.rb | Ruby | mit | 93 | main | 3,101 | # frozen_string_literal: true
require 'rspec/support/spec'
require 'rspec/support/spec/in_sub_process'
# 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::... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/integration/kw_argument_delegation_spec.rb | Ruby | mit | 93 | main | 467 | # frozen_string_literal: true
RSpec.describe "keyword argument delegation" do
# We erroneously introduced keyword argument helpers to try to remove
# the warnings generated with our normal delegation, these can cause
# the arguments to be cast as hash and need to not be
it "does not coerce to hash when passed... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations_spec.rb | Ruby | mit | 93 | main | 963 | # frozen_string_literal: true
require 'rspec/support/spec/library_wide_checks'
RSpec.describe "RSpec::Expectations" do
allowed_loaded_features = [
/stringio/, # Used by `output` matcher. Can't be easily avoided.
/rbconfig/ # required by rspec-support
]
# Truffleruby cext files
allowed_loaded_feature... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers_spec.rb | Ruby | mit | 93 | main | 3,765 | # frozen_string_literal: true
main = self
RSpec.describe RSpec::Matchers do
include ::RSpec::Support::InSubProcess
describe ".configuration" do
it 'returns a memoized configuration instance' do
expect(RSpec::Matchers.configuration).to be_a(RSpec::Expectations::Configuration)
expect(RSpec::Matchers... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations/expectation_target_spec.rb | Ruby | mit | 93 | main | 5,084 | # frozen_string_literal: true
module RSpec
module Expectations
RSpec.describe ExpectationTarget do
context 'when constructed via #expect' do
it 'constructs a new instance targetting the given argument' do
expect(expect(7).target).to eq(7)
end
it 'constructs a new instance... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations/block_snippet_extractor_spec.rb | Ruby | mit | 93 | main | 8,839 | # frozen_string_literal: true
require 'rspec/expectations/block_snippet_extractor'
module RSpec::Expectations
RSpec.describe BlockSnippetExtractor, :skip => !RSpec::Support::RubyFeatures.ripper_supported? do
subject(:extractor) do
BlockSnippetExtractor.new(proc_object, 'target_method')
end
let(:p... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations/failure_aggregator_spec.rb | Ruby | mit | 93 | main | 17,558 | # frozen_string_literal: true
module RSpec::Expectations
RSpec.describe FailureAggregator, "when used via `aggregate_failures`" do
it 'does not raise an error when no expectations fail' do
expect {
aggregate_failures do
expect(1).to be_odd
expect(2).to be_even
expect(3... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations/fail_with_spec.rb | Ruby | mit | 93 | main | 2,148 | # frozen_string_literal: true
RSpec.describe RSpec::Expectations, "#fail_with" do
let(:differ) { double("differ") }
before(:example) do
allow(RSpec::Matchers.configuration).to receive_messages(:color? => false)
allow(RSpec::Expectations).to receive(:differ) { differ }
end
it "includes a diff if expec... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations/configuration_spec.rb | Ruby | mit | 93 | main | 4,174 | # frozen_string_literal: true
module RSpec
module Expectations
RSpec.describe Configuration do
let(:config) { Configuration.new }
describe "#backtrace_formatter" do
let(:original_backtrace) { %w[ clean-me/a.rb other/file.rb clean-me/b.rb ] }
let(:cleaned_backtrace) { %w[ other/file.... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations/syntax_spec.rb | Ruby | mit | 93 | main | 2,686 | # frozen_string_literal: true
module RSpec
module Expectations
RSpec.describe 'Syntax' do
context "when passing a message to an expectation" do
let(:warner) { ::Kernel }
let(:string_like_object) do
Struct.new(:to_str, :to_s).new(*(["Ceci n'est pas une Chaine."]*2))
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations/minitest_integration_spec.rb | Ruby | mit | 93 | main | 634 | # frozen_string_literal: true
module RSpec
RSpec.describe Matchers do
let(:sample_matchers) do
[:be,
:be_instance_of,
:be_kind_of]
end
context "once required", :slow do
include MinitestIntegration
it "includes itself in Minitest::Test, and sets up our exceptions to be c... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/expectations/handler_spec.rb | Ruby | mit | 93 | main | 10,084 | # frozen_string_literal: true
module ExampleExpectations
class ArbitraryMatcher
def initialize(*args, &block)
if args.last.is_a? Hash
@expected = args.last[:expected]
end
@expected = yield if block
@block = block
end
def matches?(target)
@target = target
retur... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/multi_matcher_diff_spec.rb | Ruby | mit | 93 | main | 4,340 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe MultiMatcherDiff do
before do
stub_const("::RSpec::Matchers::MultiMatcherDiff::DESCRIPTION_MAX_LENGTH", 30)
end
class FakeDiffer
def self.diff(actual, expected)
[actual, expected].inspect
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/composable_spec.rb | Ruby | mit | 93 | main | 4,412 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe Composable do
RSpec::Matchers.define :matcher_using_surface_descriptions_in do |expected|
match { false }
failure_message { surface_descriptions_in(expected).to_s }
end
it "does not blow up when surfacing... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/aliased_matcher_spec.rb | Ruby | mit | 93 | main | 4,511 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe AliasedMatcher do
RSpec::Matchers.define :my_base_matcher do
match { |actual| actual == foo }
def foo
13
end
def description
"my base matcher description"
end
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/define_negated_matcher_spec.rb | Ruby | mit | 93 | main | 7,985 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe 'RSpec::Matchers.define_negated_matcher' do
RSpec::Matchers.define :my_base_non_negated_matcher do
match { |actual| actual == foo }
def foo
13
end
def description
"my base matcher... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/description_generation_spec.rb | Ruby | mit | 93 | main | 7,377 | # frozen_string_literal: true
RSpec.describe 'a matcher is expected to be able to have its description generated' do
after(:example) do
RSpec::Matchers.clear_generated_description
end
example "expect(...).to eq expected" do
expect("this").to eq "this"
expect(RSpec::Matchers.generated_description).to... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/dsl_spec.rb | Ruby | mit | 93 | main | 38,303 | # frozen_string_literal: true
RSpec.describe "a matcher defined using the matcher DSL" do
def question?
:answer
end
def ok
"ok"
end
it "supports calling custom matchers from within other custom matchers" do
RSpec::Matchers.define :be_ok do
match { |actual| actual == ok }
end
RSpe... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/english_phrasing_spec.rb | Ruby | mit | 93 | main | 2,848 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe EnglishPhrasing do
describe ".split_words" do
it "replaces underscores with spaces" do
expect(
described_class.split_words(:banana_creme_pie)
).to eq("banana creme pie")
end
it... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/aliases_spec.rb | Ruby | mit | 93 | main | 10,785 | # frozen_string_literal: true
module RSpec
RSpec.describe Matchers, "aliases", :order => :defined do
matcher :be_aliased_to do |old_matcher|
chain :with_description do |desc|
@expected_desc = desc
end
match do |aliased_matcher|
@actual_desc = aliased_matcher.description
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/start_and_end_with_spec.rb | Ruby | mit | 93 | main | 13,563 | # frozen_string_literal: true
RSpec.describe "expect(...).to start_with" do
it_behaves_like "an RSpec value matcher", :valid_value => "ab", :invalid_value => "bc" do
let(:matcher) { start_with("a") }
end
context "with a string" do
it "passes if it matches the start of the actual string" do
expect(... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/eq_spec.rb | Ruby | mit | 93 | main | 5,554 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe "eq" do
it_behaves_like "an RSpec value matcher", :valid_value => 1, :invalid_value => 2 do
let(:matcher) { eq(1) }
end
it "is diffable" do
expect(eq(1)).to be_diffable
end
it "matches when a... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/be_kind_of_spec.rb | Ruby | mit | 93 | main | 3,404 | # frozen_string_literal: true
module RSpec
module Matchers
[:be_a_kind_of, :be_kind_of].each do |method|
RSpec.describe "expect(actual).to #{method}(expected)" do
it_behaves_like "an RSpec value matcher", :valid_value => 5, :invalid_value => "a" do
let(:matcher) { send(method, Integer) }
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/be_between_spec.rb | Ruby | mit | 93 | main | 5,038 | # frozen_string_literal: true
module RSpec::Matchers::BuiltIn
RSpec.describe BeBetween do
class SizeMatters
include Comparable
attr_reader :str
def <=>(other)
str.size <=> other.str.size
end
def initialize(str)
@str = str
end
def inspect
@str
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/captures_spec.rb | Ruby | mit | 93 | main | 3,150 | # frozen_string_literal: true
RSpec.describe "expect(regex).to match(string).with_captures" do
context "with a string target" do
it "does match a regex with a missing capture" do
expect("a123a").to match(/(a)(b)?/).with_captures("a", nil)
end
it "does not match a regex with an incorrect match" do
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/be_spec.rb | Ruby | mit | 93 | main | 28,594 | # frozen_string_literal: true
RSpec.describe "expect(...).to be_predicate" do
it "passes when actual returns true for :predicate?" do
actual = double("actual", :happy? => true)
expect(actual).to be_happy
end
it 'allows composable aliases to be defined' do
RSpec::Matchers.alias_matcher :a_user_who_is... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/yield_spec.rb | Ruby | mit | 93 | main | 30,836 | # frozen_string_literal: true
module YieldHelpers
# these helpers are prefixed with an underscore to prevent
# collisions with the matchers (some of which have the same names)
def _dont_yield(&_block)
end
def _yield_with_no_args
yield
end
def _yield_with_args(*args, &_block)
yield(*args)
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/raise_error_spec.rb | Ruby | mit | 93 | main | 20,899 | # frozen_string_literal: true
RSpec.describe "expect { ... }.to raise_error" do
it_behaves_like "an RSpec block-only matcher" do
def valid_block
raise "boom"
end
def invalid_block
end
let(:matcher) { raise_error Exception }
end
it "passes if anything is raised" do
expect { raise "e... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/eql_spec.rb | Ruby | mit | 93 | main | 2,508 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe "eql" do
it_behaves_like "an RSpec value matcher", :valid_value => 1, :invalid_value => 2 do
let(:matcher) { eql(1) }
end
it "is diffable" do
expect(eql(1)).to be_diffable
end
it "matches whe... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/exist_spec.rb | Ruby | mit | 93 | main | 4,480 | # frozen_string_literal: true
RSpec.describe "exist matcher" do
it_behaves_like "an RSpec value matcher", :valid_value => Class.new { def exist?; true; end }.new,
:invalid_value => Class.new { def exist?; false; end }.new do
let(:matcher) { exist }
end
context "wh... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/respond_to_spec.rb | Ruby | mit | 93 | main | 41,648 | # frozen_string_literal: true
RSpec.describe "expect(...).to respond_to(:sym)" do
it_behaves_like "an RSpec value matcher", :valid_value => "s", :invalid_value => 5 do
let(:matcher) { respond_to(:upcase) }
end
it "passes if target responds to :sym" do
expect(Object.new).to respond_to(:methods)
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/compound_spec.rb | Ruby | mit | 93 | main | 32,295 | # frozen_string_literal: true
module RSpec::Matchers::BuiltIn
RSpec.describe Compound do
let(:matcher_without_diffable) { include("foo") }
before do
allow(RSpec::Matchers.configuration).to receive_messages(:color? => false)
allow(matcher_without_diffable).to receive(:diffable?).and_raise(NoMetho... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/equal_spec.rb | Ruby | mit | 93 | main | 3,908 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe "equal" do
it_behaves_like "an RSpec value matcher", :valid_value => :a, :invalid_value => :b do
let(:matcher) { equal(:a) }
end
def inspect_object(o)
"#<#{o.class}:#{o.object_id}> => #{o.inspect}"
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/match_spec.rb | Ruby | mit | 93 | main | 5,003 | # frozen_string_literal: true
RSpec.describe "expect(...).to match(expected)" do
it_behaves_like "an RSpec value matcher", :valid_value => 'ab', :invalid_value => 'bc' do
let(:matcher) { match(/a/) }
end
it "passes when target (String) matches expected (Regexp)" do
expect("string").to match(/tri/)
end... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/include_spec.rb | Ruby | mit | 93 | main | 39,751 | # frozen_string_literal: true
# This class fakes some behavior of
# ActiveSupport::HashWithIndifferentAccess.
# It doesn't convert recursively.
class FakeHashWithIndifferentAccess < Hash
class << self
def from_hash(hsh)
new_hsh = new
hsh.each do |key, value|
new_hsh[key] = value
end
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/cover_spec.rb | Ruby | mit | 93 | main | 2,038 | # frozen_string_literal: true
if (1..2).respond_to?(:cover?)
RSpec.describe "expect(...).to cover(expected)" do
it_behaves_like "an RSpec value matcher", :valid_value => (1..10), :invalid_value => (20..30) do
let(:matcher) { cover(5) }
end
context "for a range target" do
it "passes if target... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/base_matcher_spec.rb | Ruby | mit | 93 | main | 4,817 | # frozen_string_literal: true
module RSpec::Matchers::BuiltIn
RSpec.describe BaseMatcher do
describe "#match_unless_raises" do
let(:matcher) do
Class.new(BaseMatcher).new
end
it "returns true if there are no errors" do
expect(matcher.match_unless_raises {}).to be_truthy
e... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/be_within_spec.rb | Ruby | mit | 93 | main | 5,441 | # frozen_string_literal: true
module RSpec
module Matchers
RSpec.describe "expect(actual).to be_within(delta).of(expected)" do
it_behaves_like "an RSpec value matcher", :valid_value => 5, :invalid_value => -5 do
let(:matcher) { be_within(2).of(4.0) }
end
it "passes when actual == expec... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/contain_exactly_spec.rb | Ruby | mit | 93 | main | 18,531 | # frozen_string_literal: true
class UnsortableObject
def initialize(id)
@id = id
end
def inspect
@id.to_s
end
def ==(_other)
false
end
end
# AR::Relation is meant to act like a collection, but does
# not include `Enumerable`. It does implement `to_ary`.
class FakeActiveRecordRelation
def i... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/has_spec.rb | Ruby | mit | 93 | main | 6,637 | # frozen_string_literal: true
RSpec.describe "expect(...).to have_sym(*args)" do
it_behaves_like "an RSpec value matcher", :valid_value => { :a => 1 },
:invalid_value => {} do
let(:matcher) { have_key(:a) }
end
it "passes if #has_sym?(*args) returns true" do
e... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/have_attributes_spec.rb | Ruby | mit | 93 | main | 8,775 | # frozen_string_literal: true
RSpec.describe "#have_attributes matcher" do
Person = Struct.new(:name, :age)
class Person
def parent(parent_name)
@parent = parent_name
end
end
# This simulates a behaviour of Rails, see #1162.
class DynamicAttributes
def initialize(attributes)
@attrib... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/change_spec.rb | Ruby | mit | 93 | main | 36,373 | # frozen_string_literal: true
class SomethingExpected
attr_accessor :some_value
end
value_pattern = /(?:result|`.+?`)/
RSpec.describe "expect { ... }.to change ..." do
context "with a numeric value" do
before(:example) do
@instance = SomethingExpected.new
@instance.some_value = 5
end
it ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/satisfy_spec.rb | Ruby | mit | 93 | main | 3,842 | # frozen_string_literal: true
RSpec.describe "expect(...).to satisfy { block }" do
it_behaves_like "an RSpec value matcher", :valid_value => true, :invalid_value => false do
let(:matcher) { satisfy { |v| v } }
end
it "describes itself" do
expect(satisfy.description).to eq("satisfy block")
end
it "p... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/all_spec.rb | Ruby | mit | 93 | main | 8,393 | # frozen_string_literal: true
module RSpec::Matchers::BuiltIn
RSpec.describe All do
it_behaves_like 'an RSpec value matcher', :valid_value => ['A', 'A', 'A'], :invalid_value => ['A', 'A', 'B'], :disallows_negation => true do
let(:matcher) { all( eq('A') ) }
end
describe 'description' do
it ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/throw_symbol_spec.rb | Ruby | mit | 93 | main | 5,829 | # frozen_string_literal: true
module RSpec::Matchers::BuiltIn
RSpec.describe ThrowSymbol do
it_behaves_like "an RSpec block-only matcher" do
def valid_block
throw :foo
end
def invalid_block
end
let(:matcher) { throw_symbol(:foo) }
end
describe "with no args" do
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/output_spec.rb | Ruby | mit | 93 | main | 9,168 | # frozen_string_literal: true
RSpec.shared_examples "output_to_stream" do |stream_name, matcher_method, helper_module|
include helper_module
extend helper_module
it_behaves_like "an RSpec block-only matcher" do
let(:matcher) { output(/fo/).send(matcher_method) }
def valid_block
print_to_stream('fo... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/rspec/matchers/built_in/be_instance_of_spec.rb | Ruby | mit | 93 | main | 3,276 | # frozen_string_literal: true
module RSpec
module Matchers
[:be_an_instance_of, :be_instance_of].each do |method|
RSpec.describe "expect(actual).to #{method}(expected)" do
it_behaves_like "an RSpec value matcher", :valid_value => "a", :invalid_value => 5 do
let(:matcher) { send(method, St... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/support/matchers.rb | Ruby | mit | 93 | main | 1,104 | # frozen_string_literal: true
require 'rspec/matchers/fail_matchers'
RSpec::Matchers.define :include_method do |expected|
match do |actual|
actual.map { |m| m.to_s }.include?(expected.to_s)
end
end
RSpec::Matchers.define :custom_include do |*args|
match { |actual| expect(actual).to include(*args) }
end
RS... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/support/shared_examples/matcher.rb | Ruby | mit | 93 | main | 1,412 | # frozen_string_literal: true
RSpec.shared_examples "an RSpec matcher" do |options|
# Note: do not use `matcher` in 2 expectation expressions in a single
# example here. In some cases (such as `change { }.to(2)`), it will fail
# because using it a second time will apply `x += 2` twice, changing
# the value to ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/support/shared_examples/value_matcher.rb | Ruby | mit | 93 | main | 1,935 | # frozen_string_literal: true
RSpec.shared_examples "an RSpec value matcher" do |options|
let(:valid_value) { options.fetch(:valid_value) }
let(:invalid_value) { options.fetch(:invalid_value) }
matcher :always_passes do
match { |_actual| true }
end
matcher :always_fails do
match { |_actual| false... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-expectations/spec/support/shared_examples/block_matcher.rb | Ruby | mit | 93 | main | 2,926 | # frozen_string_literal: true
RSpec.shared_examples "an RSpec block-only matcher" do |**options|
# Note: do not use `matcher` in 2 expectation expressions in a single
# example here. In some cases (such as `change { x += 2 }.to(2)`), it
# will fail because using it a second time will apply `x += 2` twice,
# ch... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec/rspec.gemspec | Ruby | mit | 93 | main | 1,818 | # -*- encoding: utf-8 -*-
# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "rspec/version"
Gem::Specification.new do |s|
s.name = "rspec"
s.version = RSpec::Version::STRING
s.platform = Gem::Platform::RUBY
s.license = "MIT"
s.authors = ["Ste... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec/Rakefile | Ruby | mit | 93 | main | 533 | # frozen_string_literal: true
require "bundler"
Bundler.setup
Bundler::GemHelper.install_tasks
require 'rake'
require 'fileutils'
require 'pathname'
task :clobber do
rm_rf 'pkg'
end
task :default do
puts "Nothing to do for the default task"
end
task :verify_private_key_present do
private_key = File.expand_pa... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/rspec-core.gemspec | Ruby | mit | 93 | main | 1,972 | $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "rspec/core/version"
Gem::Specification.new do |s|
s.name = "rspec-core"
s.version = RSpec::Core::Version::STRING
s.platform = Gem::Platform::RUBY
s.license = "MIT"
s.authors = ["Steven Baker", "David Chelimsky", "Chad Hump... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/Rakefile | Ruby | mit | 93 | main | 1,148 | require "bundler"
Bundler.setup
Bundler::GemHelper.install_tasks
Bundler::GemHelper.tag_prefix = 'rspec-core-'
require "rake"
require "yaml"
require "rspec/core/rake_task"
require "cucumber/rake/task"
Cucumber::Rake::Task.new(:cucumber)
desc "Run all examples"
RSpec::Core::RakeTask.new(:spec) do |t|
t.ruby_opts =... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/features/step_definitions/additional_cli_steps.rb | Ruby | mit | 93 | main | 9,394 | require 'rspec/core' # to fix annoying "undefined method `configuration' for RSpec:Module (NoMethodError)"
require './spec/support/formatter_support'
# For Ruby 3.4.0 hash formatting
Then /^the output should print the (include|exclude)d tags {(\w+): (.*)}$/ do |word, key, value|
if RUBY_VERSION.to_f > 3.3
expe... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/features/step_definitions/core_standalone_steps.rb | Ruby | mit | 93 | main | 591 | Given(/^only rspec-core is installed$/) do
# Ensure the gem versions of rspec-mocks and rspec-expectations
# won't be loaded if available on the developers machine.
set_environment_variable('RUBYOPT', ENV['RUBYOPT'] + ' --disable-gems')
# This will make `require_expect_syntax_in_aruba_specs.rb` (loaded
# aut... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/features/support/send_sigint_during_bisect.rb | Ruby | mit | 93 | main | 758 | require 'rspec/core'
RSpec::Support.require_rspec_core "formatters/bisect_progress_formatter"
module RSpec::Core::Formatters
BisectProgressFormatter = Class.new(remove_const :BisectProgressFormatter) do
RSpec::Core::Formatters.register self
def bisect_round_started(notification)
return super unless @r... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/features/support/require_expect_syntax_in_aruba_specs.rb | Ruby | mit | 93 | main | 317 | if defined?(Cucumber)
require 'shellwords'
Before('not @with-clean-spec-opts') do
set_environment_variable('SPEC_OPTS', "-r#{Shellwords.escape(__FILE__)}")
end
else
if ENV['REMOVE_OTHER_RSPEC_LIBS_FROM_LOAD_PATH']
$LOAD_PATH.reject! { |x| /rspec-mocks/ === x || /rspec-expectations/ === x }
end
end |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/features/support/env.rb | Ruby | mit | 93 | main | 918 | require 'aruba/cucumber'
Before do
# Force ids to be printed unquoted for consistency
set_environment_variable('SHELL', '/usr/bin/bash')
end
Aruba.configure do |config|
config.exit_timeout =
if RUBY_PLATFORM =~ /java/ || defined?(Rubinius) || (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'truffleruby')
120... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/respond_to_v_defined.rb | Ruby | mit | 93 | main | 1,484 | require 'benchmark'
n = 1_000_000
puts "Kernel.respond_to?(:warn)"
Benchmark.benchmark do |bm|
3.times do
bm.report do
n.times do
Kernel.respond_to?(:warn)
end
end
end
end
puts "defined?(warn)"
Benchmark.benchmark do |bm|
3.times do
bm.report do
n.times do
defined... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/shuffle_vs_sort_by_for_random_ordering.rb | Ruby | mit | 93 | main | 4,092 | require 'benchmark/ips'
require 'digest/md5'
class Digest::Jenkins
MAX_32_BIT = 4294967295
def self.digest(string)
hash = 0
string.each_byte do |byte|
hash += byte
hash &= MAX_32_BIT
hash += ((hash << 10) & MAX_32_BIT)
hash &= MAX_32_BIT
hash ^= hash >> 6
end
hash +... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/eager_vs_lazy_metadata.rb | Ruby | mit | 93 | main | 7,004 | require 'benchmark'
# preload rspec since we don't want to benchmark that.
require 'rspec/core'
require 'rspec/mocks'
require 'rspec/expectations'
def run_benchmark(description, *args)
Benchmark.benchmark do |bm|
3.times.each do
bm.report(description) do
pid = fork do
RSpec::Core::Runner... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/precalculate_absolute_file_path_or_not.rb | Ruby | mit | 93 | main | 863 | require 'benchmark/ips'
metadata = { :file_path => "some/path.rb" }
meta_with_absolute = metadata.merge(:absolute_file_path => File.expand_path(metadata[:file_path]))
Benchmark.ips do |x|
x.report("fetch absolute path from hash") do
meta_with_absolute[:absolute_file_path]
end
x.report("calculate absolute p... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/keys_each_vs_each_key.rb | Ruby | mit | 93 | main | 1,319 | require 'benchmark/ips'
small_hash = { :key => true, :more_key => true, :other_key => true }
large_hash = (1...100).inject({}) { |hash, key| hash["key_#{key}"] = true; hash }
Benchmark.ips do |x|
x.report('keys.each with small hash') do
small_hash.keys.each { |value| value == true }
end
x.report('each_key ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/filter_object.rb | Ruby | mit | 93 | main | 544 | require 'benchmark'
require 'tmpdir'
path = File.join(Dir.tmpdir, "benchmark_example_spec.rb")
File.open(path, 'w') do |f|
f.puts %q|describe "something" do|
100.times do |n|
f.puts <<-TEXT
it "does something #{n}", :focus => true do
end
TEXT
end
100.times do |n|
f.puts <<-TEXT
it "does somethin... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/hash_functions.rb | Ruby | mit | 93 | main | 1,610 | require 'benchmark/ips'
require 'digest/md5'
MAX_32_BIT = 4294967295
def jenkins_iterative(string)
hash = 0
string.each_byte do |byte|
hash += byte
hash &= MAX_32_BIT
hash += ((hash << 10) & MAX_32_BIT)
hash &= MAX_32_BIT
hash ^= hash >> 6
end
hash += (hash << 3 & MAX_32_BIT)
hash &= M... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/several_regexps_v_one_big_one.rb | Ruby | mit | 93 | main | 1,722 | require 'benchmark'
$t = 3
$n = 100000
def report(header)
puts header
reals = []
Benchmark.bm do |bm|
$t.times do
reals << bm.report { $n.times { yield } }.real
end
end
[header, (reals.inject(&:+) / reals.count).round(5)]
end
multi = [
/\/lib\d*\/ruby\//,
/org\/jruby\//,
/bin\//,
%r|... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/to_proc_v_not_to_proc.rb | Ruby | mit | 93 | main | 11,531 | require 'benchmark'
$n = 5000
puts
def report(header)
reals = []
Benchmark.benchmark do |bm|
3.times do
reals << bm.report { $n.times { yield } }.real
end
end
[header, reals.inject(&:+) / reals.count]
end
avgs = []
def a(&block)
b(&block)
end
def b(&block)
block.call
end
def c(&block)
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/check_inclusion.rb | Ruby | mit | 93 | main | 3,631 | require 'benchmark'
n = 10_000
num_modules = 1000
class Foo; end
modules = num_modules.times.map { Module.new }
modules.each {|m| Foo.send(:include, m) }
Benchmark.benchmark do |bm|
3.times do
bm.report do
n.times do
Foo < modules.first
end
end
end
end
Benchmark.benchmark do |bm|
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/capture_block_vs_yield.rb | Ruby | mit | 93 | main | 6,189 | require 'benchmark/ips'
def yield_control
yield
end
def capture_block_and_yield(&block)
yield
end
def capture_block_and_call(&block)
block.call
end
puts "Using the block directly"
Benchmark.ips do |x|
x.report("yield ") do
yield_control { }
end
x.report("capture block and yield") ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/call_v_yield.rb | Ruby | mit | 93 | main | 1,321 | require 'benchmark'
n = 100_000
def call_block(&block)
block.call
end
def yield_control
yield
end
Benchmark.benchmark do |bm|
puts "#{n} times - ruby #{RUBY_VERSION}"
puts
puts "eval"
3.times do
bm.report do
n.times do
eval("2 + 3")
end
end
end
puts
puts "call block"... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/module_inclusion_filtering.rb | Ruby | mit | 93 | main | 3,093 | require_relative "../bundle/bundler/setup" # configures load paths
require 'rspec/core'
class << RSpec
attr_writer :world
end
# Here we are restoring the old implementation of `configure_group`, so that
# we can toggle the new vs old implementation in the benchmark by aliasing it.
module RSpecConfigurationOverrides... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/flat_map_vs_inject.rb | Ruby | mit | 93 | main | 1,683 | require 'benchmark/ips'
words = %w[ foo bar bazz big small medium large tiny less more good bad mediocre ]
def flat_map_using_yield(array)
array.flat_map { |item| yield item }
end
def flat_map_using_block(array, &block)
array.flat_map(&block)
end
Benchmark.ips do |x|
x.report("flat_map") do
words.flat_map... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/index_v_take_while.rb | Ruby | mit | 93 | main | 854 | require 'benchmark'
n = 10000
list = 1.upto(10).to_a
Benchmark.benchmark do |bm|
puts "take_while"
3.times do
bm.report do
n.times do
list.
take_while {|i| i < 6}.
map {|i| i}.
compact
end
end
end
puts
puts "list[0,n]"
3.times do
bm.report d... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/define_method_v_attr_reader_v_def.rb | Ruby | mit | 93 | main | 1,331 | require 'benchmark'
n = 1_000_000
puts "each sample runs #{n} times"
puts
class Foo
define_method :foo do
@foo
end
attr_reader :bar
def initialize
@foo = 'foo'
@bar = 'bar'
@baz = 'baz'
end
def baz
@baz
end
end
foo = Foo.new
puts "define_method"
Benchmark.benchmark do |bm|
3.... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/threadsafe_let_block.rb | Ruby | mit | 93 | main | 10,466 | require 'rspec/core'
require 'rspec/expectations'
# switches between these implementations - https://github.com/rspec/rspec-core/pull/1858/files
# benchmark requested in this PR - https://github.com/rspec/rspec-core/pull/1858
#
# I ran these from lib root by adding "gem 'benchmark-ips'" to ../Gemfile-custom
# ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/require_relative_v_require.rb | Ruby | mit | 93 | main | 2,485 | require 'benchmark'
n = 20
Benchmark.benchmark do |bm|
3.times.each do
bm.report do
n.times do
pid = fork do
require 'rspec/core'
end
Process.wait(pid)
end
end
end
end
# ###################################
# Ruby 1.9.3 - 3 x 20
# require
# $ bundle exec ruby ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/map_then_flatten_vs_flat_map_benchmarks.rb | Ruby | mit | 93 | main | 1,886 | require 'benchmark'
$n = 10000
size = 100
puts "size: #{size}"
puts
def report
reals = []
Benchmark.benchmark do |bm|
3.times do
reals << bm.report { $n.times { yield } }.real
end
end
reals.inject(&:+) / reals.count
end
avgs = []
puts "map then flatten"
avgs << report {
(1..size).
map ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/eager_vs_lazy_metadata/define_examples.rb | Ruby | mit | 93 | main | 434 | top_level_example_groups = 25
examples = 25
nested_groups = 25
nested_examples = 25
top_level_example_groups.times do |tlg|
RSpec.describe "Top level group #{tlg}", :foo => 3 do
examples.times do |e|
it("example #{e}", :bar => 4) { }
end
nested_groups.times do |ng|
context "nested #{ng}" do... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/singleton_example_groups/helper.rb | Ruby | mit | 93 | main | 4,632 | require_relative "../../bundle/bundler/setup" # configures load paths
require 'rspec/core'
require 'stackprof'
class << RSpec
attr_writer :world
end
RSpec::Core::Example.class_eval do
alias_method :new_with_around_and_singleton_context_hooks, :with_around_and_singleton_context_hooks
alias_method :old_with_aroun... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/singleton_example_groups/with_module_inclusions.rb | Ruby | mit | 93 | main | 1,048 | require_relative "helper"
RSpec.configure do |c|
1.upto(10) do
c.include Module.new, :apply_it
end
end
BenchmarkHelpers.run_benchmarks
__END__
No match -- without singleton group support
555.498 (±27.0%) i/s - 2.496k
No match -- with singleton group support
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/singleton_example_groups/with_config_hooks_module_inclusions_and_shared_context_inclusions.rb | Ruby | mit | 93 | main | 1,158 | require_relative "helper"
RSpec.configure do |c|
10.times do
c.before(:context, :apply_it) { }
c.after(:context, :apply_it) { }
c.include Module.new, :apply_it
end
end
1.upto(10) do |i|
RSpec.shared_context "context #{i}", :apply_it do
end
end
BenchmarkHelpers.run_benchmarks
__END__
No match -... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/singleton_example_groups/with_no_config_hooks_or_inclusions.rb | Ruby | mit | 93 | main | 947 | require_relative "helper"
BenchmarkHelpers.run_benchmarks
__END__
No match -- without singleton group support
565.198 (±28.8%) i/s - 2.438k
No match -- with singleton group support
539.781 (±18.9%) i/s - 2.496k
Example match -- without singleton group suppo... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/singleton_example_groups/with_config_hooks.rb | Ruby | mit | 93 | main | 1,055 | require_relative "helper"
RSpec.configure do |c|
10.times do
c.before(:context, :apply_it) { }
c.after(:context, :apply_it) { }
end
end
BenchmarkHelpers.run_benchmarks
__END__
No match -- without singleton group support
575.250 (±29.0%) i/s - 2.484k
No match -- with singlet... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/singleton_example_groups/with_shared_context_inclusions.rb | Ruby | mit | 93 | main | 1,061 | require_relative "helper"
1.upto(10) do |i|
RSpec.shared_context "context #{i}", :apply_it do
end
end
BenchmarkHelpers.run_benchmarks
# BenchmarkHelpers.profile(1000)
__END__
No match -- without singleton group support
563.304 (±29.6%) i/s - 2.385k
No match -- with singleton group ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/allocations/helper.rb | Ruby | mit | 93 | main | 936 | $LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)
require 'rspec/core'
require 'allocation_stats'
def benchmark_allocations(burn: 1, min_allocations: 0)
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-core/benchmarks/allocations/1_group_1000_examples.rb | Ruby | mit | 93 | main | 2,379 | require_relative "helper"
benchmark_allocations do
RSpec.describe "one example group" do
1000.times do |i|
example "example #{i}" do
end
end
end
end
__END__
Original stats:
class_plus count
---------------------------------------- -----
String ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/allocations/1000_groups_1_example.rb | Ruby | mit | 93 | main | 4,722 | require_relative "helper"
benchmark_allocations do
1000.times do |i|
RSpec.describe "group #{i}" do
it "has one example" do
end
end
end
end
__END__
Original allocations:
class_plus count
---------------------------------------- -----
String ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/allocations/running_1000_groups_1_example.rb | Ruby | mit | 93 | main | 8,175 | require_relative "helper"
1000.times do |i|
RSpec.describe "group #{i}" do
it "has one example" do
end
end
end
benchmark_allocations(burn: 0, min_allocations: 50) do
RSpec::Core::Runner.run([])
end
__END__
Before optimization:
class_plus ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/benchmarks/allocations/running_1_group_1000_examples.rb | Ruby | mit | 93 | main | 4,374 | require_relative "helper"
RSpec.describe "one example group" do
1000.times do |i|
example "example #{i}" do
end
end
end
benchmark_allocations(burn: 0) do
RSpec::Core::Runner.run([])
end
__END__
Original allocations:
class_plus ... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/spec_helper.rb | Ruby | mit | 93 | main | 2,416 | 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_core_without_stderr_monkey_patch = RSpec::Core::Configuration.new
class RSpec::Core... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/rspec/core_spec.rb | Ruby | mit | 93 | main | 11,027 | require 'rspec/support/spec/library_wide_checks'
RSpec.describe RSpec do
fake_libs = File.expand_path('../../support/fake_libs', __FILE__)
allowed_loaded_features = [
/optparse\.rb/, # Used by OptionParser.
/rbconfig\.rb/, # loaded by rspec-support for OS detection.
/shellwords\.rb/, # used by Conf... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/rspec/core/filterable_item_repository_spec.rb | Ruby | mit | 93 | main | 9,575 | module RSpec
module Core
RSpec.describe FilterableItemRepository, "#items_for" do
FilterableItem = Struct.new(:name)
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def self.it_behaves_like_a_filterable_item_repo(&when_the_repo_has_items_with_metadata)
let... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/rspec/core/shared_example_group_spec.rb | Ruby | mit | 93 | main | 19,462 | require 'rspec/support/spec/in_sub_process'
module RandomTopLevelModule
def self.setup!
RSpec.shared_examples_for("top level in module") {}
end
end
module RSpec
module Core
RSpec.describe SharedExampleGroup do
include RSpec::Support::InSubProcess
let(:registry) { RSpec.world.shared_example_... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/rspec/core/ruby_project_spec.rb | Ruby | mit | 93 | main | 1,578 | module RSpec
module Core
RSpec.describe RubyProject do
describe "#determine_root" do
context "with ancestor containing spec directory" do
it "returns ancestor containing the spec directory" do
allow(RubyProject).to receive(:ascend_until).and_return('foodir')
expec... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/rspec/core/metadata_spec.rb | Ruby | mit | 93 | main | 22,623 | module RSpec
module Core
RSpec.describe Metadata do
describe '.relative_path' do
let(:here) { File.expand_path(".") }
it "transforms absolute paths to relative paths" do
expect(Metadata.relative_path(here)).to eq "."
end
it "transforms absolute paths to relative p... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/rspec/core/output_wrapper_spec.rb | Ruby | mit | 93 | main | 831 | module RSpec::Core
RSpec.describe OutputWrapper do
let(:output) { StringIO.new }
let(:wrapper) { OutputWrapper.new(output) }
it 'redirects calls to the wrapped object' do
wrapper.puts('message')
wrapper.print('another message')
expect(output.string).to eq("message\nanother message").and... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/rspec/core/invocations_spec.rb | Ruby | mit | 93 | main | 6,623 | require 'rspec/core/drb'
require 'rspec/core/bisect/coordinator'
require 'rspec/core/project_initializer'
module RSpec::Core
RSpec.describe Invocations do
let(:configuration_options) { instance_double(ConfigurationOptions) }
let(:err) { StringIO.new }
let(:out) { StringIO.new }
def run_invocation
... |
github | rspec/rspec | https://github.com/rspec/rspec | rspec-core/spec/rspec/core/configuration_options_spec.rb | Ruby | mit | 93 | main | 22,255 | require 'rspec/core/drb'
RSpec.describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolated_home => true do
include ConfigOptionsHelper
it "does not mutate the provided args array" do
args = ['-e', 'some spec']
RSpec::Core::ConfigurationOptions.new(args).options
expect(args).to e... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.