module RSpec::Core::MemoizedHelpers
def self.define_helpers_on(example_group)
- Private: -
def self.define_helpers_on(example_group) example_group.__send__(:include, module_for(example_group)) end
def self.get_constant_or_yield(example_group, name)
- Private: -
def self.get_constant_or_yield(example_group, name) if example_group.const_defined?(name) example_group.const_get(name) else yield end end
def self.get_constant_or_yield(example_group, name)
- Private: -
def self.get_constant_or_yield(example_group, name) if example_group.const_defined?(name, (check_ancestors = false)) example_group.const_get(name, check_ancestors) else yield end end
def self.module_for(example_group)
- Private: -
def self.module_for(example_group) get_constant_or_yield(example_group, :LetDefinitions) do mod = Module.new do include(Module.new { example_group.const_set(:NamedSubjectPreventSuper, self) }) end example_group.const_set(:LetDefinitions, mod) mod end end
def __init_memoized
- Private: -
def __init_memoized @__memoized = if RSpec.configuration.threadsafe? ThreadsafeMemoized.new else NonThreadSafeMemoized.new end end
def enforce_value_expectation(matcher, method_name)
- Private: -
def enforce_value_expectation(matcher, method_name) return if matcher_supports_value_expectations?(matcher) RSpec.deprecate( "#{method_name} #{RSpec::Support::ObjectFormatter.format(matcher)}", :message => "The implicit block expectation syntax is deprecated, you should pass " \ "a block to `expect` to use the provided block expectation matcher " \ "(#{RSpec::Support::ObjectFormatter.format(matcher)}), " \ "or the matcher must implement `supports_value_expectations?`." ) end
def initialize(*)
- Private: -
def initialize(*) __init_memoized super end
def is_expected
- Note: - This only works if you are using rspec-expectations.
Other tags:
- See: #should_not -
See: #should -
See: #subject -
def is_expected expect(subject) end
def matcher_supports_value_expectations?(matcher)
def matcher_supports_value_expectations?(matcher) matcher.supports_value_expectations? rescue true end
def should(matcher=nil, message=nil)
- Note: - If you are using RSpec's newer expect-based syntax you may
Note: - This only works if you are using rspec-expectations.
Other tags:
- See: #is_expected -
See: #subject -
def should(matcher=nil, message=nil) enforce_value_expectation(matcher, 'should') RSpec::Expectations::PositiveExpectationHandler.handle_matcher(subject, matcher, message) end
def should_not(matcher=nil, message=nil)
- Note: - If you are using RSpec's newer expect-based syntax you may
Note: - This only works if you are using rspec-expectations.
Other tags:
- See: #is_expected -
See: #subject -
def should_not(matcher=nil, message=nil) enforce_value_expectation(matcher, 'should_not') RSpec::Expectations::NegativeExpectationHandler.handle_matcher(subject, matcher, message) end
def subject
- See: #is_expected -
See: #should_not -
See: #should -
Other tags:
- Note: - Because `subject` is designed to create state that is reset
Note: - `subject` was contributed by Joe Ferris to support the one-liner
def subject __memoized.fetch_or_store(:subject) do described = described_class || self.class.metadata.fetch(:description_args).first Class === described ? described.new : described end end