Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use optimized require #488

Merged
merged 3 commits into from
Mar 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Changelog.md
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,14 @@
### 3.0.0.rc1 Development ### 3.0.0.rc1 Development
[Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.0.0.beta2...master) [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.0.0.beta2...master)


Breaking Changes: Breaking Changes for 3.0.0:


* Remove `matcher_execution_context` attribute from DSL-defined * Remove `matcher_execution_context` attribute from DSL-defined
custom matchers. (Myron Marston) custom matchers. (Myron Marston)
* Remove `RSpec::Matchers::Pretty#_pretty_print`. (Myron Marston) * Remove `RSpec::Matchers::Pretty#_pretty_print`. (Myron Marston)
* Remove `RSpec::Matchers::Pretty#expected_to_sentence`. (Myron Marston) * Remove `RSpec::Matchers::Pretty#expected_to_sentence`. (Myron Marston)
* Rename `RSpec::Matchers::Configuration` constant to
`RSpec::Expectations::Configuration`. (Myron Marston)


Bug Fixes: Bug Fixes:


Expand Down
22 changes: 14 additions & 8 deletions lib/rspec/expectations.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,13 +1,19 @@
require 'rspec/support/caller_filter' require 'rspec/support'
require 'rspec/support/warnings' RSpec::Support.require_rspec_support "caller_filter"
RSpec::Support.require_rspec_support "warnings"


require 'rspec/matchers' require 'rspec/matchers'
require 'rspec/expectations/expectation_target'
require 'rspec/matchers/configuration' RSpec::Support.define_optimized_require_for_rspec(:expectations) { |f| require_relative(f) }
require 'rspec/expectations/fail_with'
require 'rspec/expectations/handler' %w[
require 'rspec/expectations/version' expectation_target
require 'rspec/expectations/diff_presenter' configuration
fail_with
handler
version
diff_presenter
].each { |file| RSpec::Support.require_rspec_expectations(file) }


module RSpec module RSpec
# RSpec::Expectations provides a simple, readable API to express # RSpec::Expectations provides a simple, readable API to express
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rspec/expectations/syntax' RSpec::Support.require_rspec_expectations "syntax"


module RSpec module RSpec
module Matchers module Expectations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this technically a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good point. I'll add it to the changelog and work on a 2.99 deprecation.

# Provides configuration options for rspec-expectations. # Provides configuration options for rspec-expectations.
# If you are using rspec-core, you can access this via a # If you are using rspec-core, you can access this via a
# block passed to `RSpec::Core::Configuration#expect_with`. # block passed to `RSpec::Core::Configuration#expect_with`.
Expand Down Expand Up @@ -125,8 +125,8 @@ def self.format_backtrace(backtrace)
end end
end end


# The configuration object # The configuration object.
# @return [RSpec::Matchers::Configuration] the configuration object # @return [RSpec::Expectations::Configuration] the configuration object
def self.configuration def self.configuration
@configuration ||= Configuration.new @configuration ||= Configuration.new
end end
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/expectations/diff_presenter.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'diff/lcs' require 'diff/lcs'
require "rspec/expectations/encoded_string"
require "rspec/expectations/differ"
require 'diff/lcs/hunk' require 'diff/lcs/hunk'
require 'pp' require 'pp'
RSpec::Support.require_rspec_expectations "encoded_string"
RSpec::Support.require_rspec_expectations "differ"


module RSpec module RSpec
module Expectations module Expectations
Expand Down
28 changes: 21 additions & 7 deletions lib/rspec/matchers.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,15 @@
require 'rspec/matchers/pretty' require 'rspec/support'
require 'rspec/matchers/composable' RSpec::Support.define_optimized_require_for_rspec(:matchers) { |f| require_relative(f) }
require 'rspec/matchers/built_in'
require 'rspec/matchers/generated_descriptions' %w[
require 'rspec/matchers/dsl' pretty
require 'rspec/matchers/matcher_delegator' composable
require 'rspec/matchers/aliased_matcher' built_in
generated_descriptions
dsl
matcher_delegator
aliased_matcher
].each { |file| RSpec::Support.require_rspec_matchers(file) }


# RSpec's top level namespace. All of rspec-expectations is contained # RSpec's top level namespace. All of rspec-expectations is contained
# in the `RSpec::Expectations` and `RSpec::Matchers` namespaces. # in the `RSpec::Expectations` and `RSpec::Matchers` namespaces.
Expand Down Expand Up @@ -843,6 +848,15 @@ def yield_successive_args(*args)
alias_matcher :a_block_yielding_successive_args, :yield_successive_args alias_matcher :a_block_yielding_successive_args, :yield_successive_args
alias_matcher :yielding_successive_args, :yield_successive_args alias_matcher :yielding_successive_args, :yield_successive_args


# Delegates to {RSpec::Expectations.configuration}.
# This is here because rspec-core's `expect_with` option
# looks for a `configuration` method on the mixin
# (`RSpec::Matchers`) to yield to a block.
# @return [RSpec::Expectations::Configuration] the configuration object
def self.configuration
Expectations.configuration
end

private private


BE_PREDICATE_REGEX = /^(be_(?:an?_)?)(.*)/ BE_PREDICATE_REGEX = /^(be_(?:an?_)?)(.*)/
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/matchers/built_in.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rspec/matchers/built_in/base_matcher' RSpec::Support.require_rspec_matchers "built_in/base_matcher"


module RSpec module RSpec
module Matchers module Matchers
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec/matchers/built_in/be.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'rspec/matchers/dsl'

module RSpec module RSpec
module Matchers module Matchers
module BuiltIn module BuiltIn
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/matchers/composable.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rspec/support/fuzzy_matcher' RSpec::Support.require_rspec_support "fuzzy_matcher"


module RSpec module RSpec
module Matchers module Matchers
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,14 +1,7 @@
require 'delegate' require 'delegate'


module RSpec module RSpec
module Matchers module Expectations
describe "RSpec::Matchers.configuration" do
it 'returns a memoized configuration instance' do
expect(RSpec::Matchers.configuration).to be_a(RSpec::Matchers::Configuration)
expect(RSpec::Matchers.configuration).to be(RSpec::Matchers.configuration)
end
end

describe Configuration do describe Configuration do
let(:config) { Configuration.new } let(:config) { Configuration.new }


Expand Down
7 changes: 7 additions & 0 deletions spec/rspec/matchers_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
describe RSpec::Matchers do describe RSpec::Matchers do
include ::RSpec::Support::InSubProcess 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.configuration).to be(RSpec::Matchers.configuration)
end
end

it 'can be mixed into `main`' do it 'can be mixed into `main`' do
in_sub_process do in_sub_process do
main.instance_eval do main.instance_eval do
Expand Down