Class: RSpec::Expectations::ExpectationTarget
- Inherits:
-
Object
- Object
- RSpec::Expectations::ExpectationTarget
- Defined in:
- lib/rspec/expectations/expectation_target.rb
Overview
Wraps the target of an expectation.
Class Attribute Summary collapse
-
.deprecated_should_enabled ⇒ Object
(also: deprecated_should_enabled?)
Returns the value of attribute deprecated_should_enabled.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(target) ⇒ ExpectationTarget
constructor
private
A new instance of ExpectationTarget.
-
#not_to(matcher = nil, message = nil, &block) ⇒ Boolean
(also: #to_not)
Runs the given expectation, passing if
matcherreturns false. - #should(*args) ⇒ Object
- #should_not(*args) ⇒ Object
-
#to(matcher = nil, message = nil, &block) ⇒ Boolean
Runs the given expectation, passing if
matcherreturns true.
Constructor Details
#initialize(target) ⇒ ExpectationTarget
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ExpectationTarget.
19 20 21 |
# File 'lib/rspec/expectations/expectation_target.rb', line 19 def initialize(target) @target = target end |
Class Attribute Details
.deprecated_should_enabled ⇒ Object Also known as: deprecated_should_enabled?
Returns the value of attribute deprecated_should_enabled.
14 15 16 |
# File 'lib/rspec/expectations/expectation_target.rb', line 14 def deprecated_should_enabled @deprecated_should_enabled end |
Class Method Details
.disable_deprecated_should ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/rspec/expectations/expectation_target.rb', line 67 def self.disable_deprecated_should return unless deprecated_should_enabled? remove_method :should remove_method :should_not self.deprecated_should_enabled = false end |
.enable_deprecated_should ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rspec/expectations/expectation_target.rb', line 51 def self.enable_deprecated_should return if deprecated_should_enabled? def should(*args) RSpec.deprecate "`expect { }.should`", :replacement => "`expect { }.to`" @target.should(*args) end def should_not(*args) RSpec.deprecate "`expect { }.should_not`", :replacement => "`expect { }.not_to`" @target.should_not(*args) end self.deprecated_should_enabled = true end |
Instance Method Details
#not_to(matcher = nil, message = nil, &block) ⇒ Boolean Also known as: to_not
Runs the given expectation, passing if matcher returns false.
45 46 47 48 |
# File 'lib/rspec/expectations/expectation_target.rb', line 45 def not_to(matcher=nil, =nil, &block) prevent_operator_matchers(:not_to, matcher) RSpec::Expectations::NegativeExpectationHandler.handle_matcher(@target, matcher, , &block) end |
#should(*args) ⇒ Object
54 55 56 57 |
# File 'lib/rspec/expectations/expectation_target.rb', line 54 def should(*args) RSpec.deprecate "`expect { }.should`", :replacement => "`expect { }.to`" @target.should(*args) end |
#should_not(*args) ⇒ Object
59 60 61 62 |
# File 'lib/rspec/expectations/expectation_target.rb', line 59 def should_not(*args) RSpec.deprecate "`expect { }.should_not`", :replacement => "`expect { }.not_to`" @target.should_not(*args) end |
#to(matcher = nil, message = nil, &block) ⇒ Boolean
Runs the given expectation, passing if matcher returns true.
32 33 34 35 |
# File 'lib/rspec/expectations/expectation_target.rb', line 32 def to(matcher=nil, =nil, &block) prevent_operator_matchers(:to, matcher) RSpec::Expectations::PositiveExpectationHandler.handle_matcher(@target, matcher, , &block) end |