Skip to content
This repository
  • 13 commits
  • 36 files changed
  • 0 comments
  • 4 contributors

Showing 36 changed files with 244 additions and 5 deletions. Show diff stats Hide diff stats

  1. +26 1 Changelog.md
  2. +1 1  lib/rspec/expectations.rb
  3. +30 0 lib/rspec/expectations/expectation_target.rb
  4. +9 2 lib/rspec/expectations/syntax.rb
  5. +1 1  lib/rspec/expectations/version.rb
  6. +1 0  lib/rspec/matchers/built_in/be_within.rb
  7. +1 0  lib/rspec/matchers/built_in/change.rb
  8. +1 0  lib/rspec/matchers/built_in/has.rb
  9. +1 0  lib/rspec/matchers/built_in/have.rb
  10. +1 0  lib/rspec/matchers/built_in/raise_error.rb
  11. +1 0  lib/rspec/matchers/built_in/respond_to.rb
  12. +1 0  lib/rspec/matchers/built_in/satisfy.rb
  13. +1 0  lib/rspec/matchers/built_in/throw_symbol.rb
  14. +2 0  lib/rspec/matchers/built_in/yield.rb
  15. +4 0 spec/rspec/matchers/be_instance_of_spec.rb
  16. +4 0 spec/rspec/matchers/be_kind_of_spec.rb
  17. +4 0 spec/rspec/matchers/be_within_spec.rb
  18. +6 0 spec/rspec/matchers/change_spec.rb
  19. +42 0 spec/rspec/matchers/configuration_spec.rb
  20. +4 0 spec/rspec/matchers/cover_spec.rb
  21. +4 0 spec/rspec/matchers/eq_spec.rb
  22. +4 0 spec/rspec/matchers/eql_spec.rb
  23. +3 0  spec/rspec/matchers/equal_spec.rb
  24. +6 0 spec/rspec/matchers/exist_spec.rb
  25. +5 0 spec/rspec/matchers/has_spec.rb
  26. +3 0  spec/rspec/matchers/have_spec.rb
  27. +4 0 spec/rspec/matchers/include_spec.rb
  28. +4 0 spec/rspec/matchers/match_array_spec.rb
  29. +4 0 spec/rspec/matchers/match_spec.rb
  30. +5 0 spec/rspec/matchers/raise_error_spec.rb
  31. +3 0  spec/rspec/matchers/respond_to_spec.rb
  32. +4 0 spec/rspec/matchers/satisfy_spec.rb
  33. +8 0 spec/rspec/matchers/start_with_end_with_spec.rb
  34. +5 0 spec/rspec/matchers/throw_symbol_spec.rb
  35. +28 0 spec/rspec/matchers/yield_spec.rb
  36. +13 0 spec/support/shared_examples.rb
27 Changelog.md
Source Rendered
... ... @@ -1,7 +1,32 @@
  1 +### 2.11.3 / 2012-09-04
  2 +[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.2...v.2.11.3)
  3 +
  4 +Bug fixes
  5 +
  6 +* Fix (and deprecate) `expect { }.should` syntax so that it works even
  7 + though it was never a documented or intended syntax. It worked as a
  8 + consequence of the implementation of `expect` in RSpec 2.10 and
  9 + earlier. (Myron Marston)
  10 +* Ensure #== is defined on build in matchers so that they can be composed.
  11 + For example:
  12 +
  13 + expect {
  14 + user.emailed!
  15 + }.to change { user.last_emailed_at }.to be_within(1.second).of(Time.zone.now)
  16 +
  17 +### 2.11.2 / 2012-07-25
  18 +[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.1...v2.11.2)
  19 +
  20 +Bug fixes
  21 +
  22 +* Define `should` and `should_not` on `Object` rather than `BasicObject`
  23 + on MacRuby. On MacRuby, `BasicObject` is defined but is not the root
  24 + of the object hierarchy. (Gabriel Gilder)
  25 +
1 26 ### 2.11.1 / 2012-07-08
2 27 [full changelog](http://github.com/rspec/rspec-expectations/compare/v2.11.0...v2.11.1)
3 28
4   -Bug fix
  29 +Bug fixes
5 30
6 31 * Constrain `actual` in `be_within` matcher to values that respond to `-` instead
7 32 of requiring a specific type.
2  lib/rspec/expectations.rb
... ... @@ -1,7 +1,7 @@
1 1 require 'rspec/expectations/extensions'
2 2 require 'rspec/matchers'
3   -require 'rspec/matchers/configuration'
4 3 require 'rspec/expectations/expectation_target'
  4 +require 'rspec/matchers/configuration'
5 5 require 'rspec/expectations/fail_with'
6 6 require 'rspec/expectations/errors'
7 7 require 'rspec/expectations/deprecation'
30 lib/rspec/expectations/expectation_target.rb
@@ -10,6 +10,11 @@ module Expectations
10 10 # # with `to_not`
11 11 # expect(actual).to_not eq(3)
12 12 class ExpectationTarget
  13 + class << self
  14 + attr_accessor :deprecated_should_enabled
  15 + alias deprecated_should_enabled? deprecated_should_enabled
  16 + end
  17 +
13 18 # @api private
14 19 def initialize(target)
15 20 @target = target
@@ -44,6 +49,31 @@ def to_not(matcher=nil, message=nil, &block)
44 49 end
45 50 alias not_to to_not
46 51
  52 + def self.enable_deprecated_should
  53 + return if deprecated_should_enabled?
  54 +
  55 + def should(*args)
  56 + RSpec.deprecate "`expect { }.should`", "`expect { }.to`", 3
  57 + @target.should(*args)
  58 + end
  59 +
  60 + def should_not(*args)
  61 + RSpec.deprecate "`expect { }.should_not`", "`expect { }.to_not`", 3
  62 + @target.should_not(*args)
  63 + end
  64 +
  65 + self.deprecated_should_enabled = true
  66 + end
  67 +
  68 + def self.disable_deprecated_should
  69 + return unless deprecated_should_enabled?
  70 +
  71 + remove_method :should
  72 + remove_method :should_not
  73 +
  74 + self.deprecated_should_enabled = false
  75 + end
  76 +
47 77 private
48 78
49 79 def prevent_operator_matchers(verb, matcher)
11 lib/rspec/expectations/syntax.rb
@@ -40,8 +40,7 @@ module Syntax
40 40 # @api private
41 41 # Determines where we add `should` and `should_not`.
42 42 def default_should_host
43   - @default_should_host ||= defined?(::BasicObject) ?
44   - ::BasicObject : ::Kernel
  43 + @default_should_host ||= ::Object.ancestors.last
45 44 end
46 45
47 46 # @api private
@@ -58,6 +57,8 @@ def should_not(matcher=nil, message=nil, &block)
58 57 ::RSpec::Expectations::NegativeExpectationHandler.handle_matcher(self, matcher, message, &block)
59 58 end
60 59 end
  60 +
  61 + ::RSpec::Expectations::ExpectationTarget.enable_deprecated_should if expect_enabled?
61 62 end
62 63
63 64 # @api private
@@ -69,6 +70,8 @@ def disable_should(syntax_host = default_should_host)
69 70 undef should
70 71 undef should_not
71 72 end
  73 +
  74 + ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should
72 75 end
73 76
74 77 # @api private
@@ -83,6 +86,8 @@ def expect(*target, &target_block)
83 86 ::RSpec::Expectations::ExpectationTarget.new(target.first)
84 87 end
85 88 end
  89 +
  90 + ::RSpec::Expectations::ExpectationTarget.enable_deprecated_should if should_enabled?
86 91 end
87 92
88 93 # @api private
@@ -93,6 +98,8 @@ def disable_expect(syntax_host = ::RSpec::Matchers)
93 98 syntax_host.module_eval do
94 99 undef expect
95 100 end
  101 +
  102 + ::RSpec::Expectations::ExpectationTarget.disable_deprecated_should
96 103 end
97 104
98 105 # @api private
2  lib/rspec/expectations/version.rb
@@ -2,7 +2,7 @@ module RSpec
2 2 module Expectations
3 3 # @private
4 4 module Version
5   - STRING = '2.11.0'
  5 + STRING = '2.11.3'
6 6 end
7 7 end
8 8 end
1  lib/rspec/matchers/built_in/be_within.rb
@@ -12,6 +12,7 @@ def matches?(actual)
12 12 raise needs_subtractable unless @actual.respond_to? :-
13 13 (@actual - @expected).abs <= @delta
14 14 end
  15 + alias == matches?
15 16
16 17 def of(expected)
17 18 @expected = expected
1  lib/rspec/matchers/built_in/change.rb
@@ -18,6 +18,7 @@ def matches?(event_proc)
18 18
19 19 (!change_expected? || changed?) && matches_before? && matches_after? && matches_expected_delta? && matches_min? && matches_max?
20 20 end
  21 + alias == matches?
21 22
22 23 def raise_block_syntax_error
23 24 raise SyntaxError.new(<<-MESSAGE)
1  lib/rspec/matchers/built_in/has.rb
@@ -9,6 +9,7 @@ def initialize(expected, *args)
9 9 def matches?(actual)
10 10 actual.__send__(predicate(@expected), *@args)
11 11 end
  12 + alias == matches?
12 13
13 14 def failure_message_for_should
14 15 "expected ##{predicate(@expected)}#{failure_message_args_description} to return true, got false"
1  lib/rspec/matchers/built_in/have.rb
@@ -31,6 +31,7 @@ def matches?(collection_or_owner)
31 31 else @actual == @expected
32 32 end
33 33 end
  34 + alias == matches?
34 35
35 36 def determine_collection(collection_or_owner)
36 37 if collection_or_owner.respond_to?(@collection_name)
1  lib/rspec/matchers/built_in/raise_error.rb
@@ -35,6 +35,7 @@ def matches?(given_proc)
35 35 ensure
36 36 return (@raised_expected_error & @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
37 37 end
  38 + alias == matches?
38 39
39 40 def eval_block
40 41 @eval_block = true
1  lib/rspec/matchers/built_in/respond_to.rb
@@ -10,6 +10,7 @@ def initialize(*names)
10 10 def matches?(actual)
11 11 find_failing_method_names(actual, :reject).empty?
12 12 end
  13 + alias == matches?
13 14
14 15 def does_not_match?(actual)
15 16 find_failing_method_names(actual, :select).empty?
1  lib/rspec/matchers/built_in/satisfy.rb
@@ -11,6 +11,7 @@ def matches?(actual, &block)
11 11 @actual = actual
12 12 @block.call(actual)
13 13 end
  14 + alias == matches?
14 15
15 16 def failure_message_for_should
16 17 "expected #{@actual} to satisfy block"
1  lib/rspec/matchers/built_in/throw_symbol.rb
@@ -51,6 +51,7 @@ def matches?(given_proc)
51 51 end
52 52 end
53 53 end
  54 + alias == matches?
54 55
55 56 def failure_message_for_should
56 57 "expected #{expected} to be thrown, got #{caught}"
2  lib/rspec/matchers/built_in/yield.rb
@@ -115,6 +115,7 @@ def matches?(block)
115 115 @actual = @probe.single_yield_args
116 116 @probe.yielded_once?(:yield_with_args) && args_match?
117 117 end
  118 + alias == matches?
118 119
119 120 def failure_message_for_should
120 121 "expected given block to yield with arguments, but #{positive_failure_reason}"
@@ -184,6 +185,7 @@ def matches?(block)
184 185 @actual = @probe.successive_yield_args
185 186 args_match?
186 187 end
  188 + alias == matches?
187 189
188 190 def failure_message_for_should
189 191 "expected given block to yield successively with arguments, but yielded with unexpected arguments" +
4 spec/rspec/matchers/be_instance_of_spec.rb
@@ -4,6 +4,10 @@ module RSpec
4 4 module Matchers
5 5 [:be_an_instance_of, :be_instance_of].each do |method|
6 6 describe "actual.should #{method}(expected)" do
  7 + it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
  8 + let(:matcher) { send(method, Fixnum) }
  9 + end
  10 +
7 11 it "passes if actual is instance of expected class" do
8 12 5.should send(method, Fixnum)
9 13 end
4 spec/rspec/matchers/be_kind_of_spec.rb
@@ -4,6 +4,10 @@ module RSpec
4 4 module Matchers
5 5 [:be_a_kind_of, :be_kind_of].each do |method|
6 6 describe "actual.should #{method}(expected)" do
  7 + it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
  8 + let(:matcher) { send(method, Fixnum) }
  9 + end
  10 +
7 11 it "passes if actual is instance of expected class" do
8 12 5.should send(method, Fixnum)
9 13 end
4 spec/rspec/matchers/be_within_spec.rb
@@ -3,6 +3,10 @@
3 3 module RSpec
4 4 module Matchers
5 5 describe "[actual.should] be_within(delta).of(expected)" do
  6 + it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => -5 do
  7 + let(:matcher) { be_within(2).of(4.0) }
  8 + end
  9 +
6 10 it "matches when actual == expected" do
7 11 be_within(0.5).of(5.0).matches?(5.0).should be_true
8 12 end
6 spec/rspec/matchers/change_spec.rb
@@ -153,6 +153,12 @@ def ==(other)
153 153 end
154 154
155 155 describe "should change { block }" do
  156 + o = SomethingExpected.new
  157 + it_behaves_like "an RSpec matcher", :valid_value => lambda { o.some_value = 5 },
  158 + :invalid_value => lambda { } do
  159 + let(:matcher) { change { o.some_value } }
  160 + end
  161 +
156 162 before(:each) do
157 163 @instance = SomethingExpected.new
158 164 @instance.some_value = 5
42 spec/rspec/matchers/configuration_spec.rb
@@ -121,6 +121,48 @@ def sandboxed
121 121 expect(3).to eq(3)
122 122 end
123 123 end
  124 +
  125 + it 'does not add the deprecated #should to ExpectationTarget when only :should is enabled' do
  126 + et = Expectations::ExpectationTarget
  127 +
  128 + sandboxed do
  129 + configure_syntax :should
  130 + et.new(Proc.new {}).should be_an(et)
  131 + et.new(Proc.new {}).should_not be_a(Proc)
  132 + end
  133 + end
  134 +
  135 + it 'does not add the deprecated #should to ExpectationTarget when only :expect is enabled' do
  136 + sandboxed do
  137 + configure_syntax :expect
  138 + expect(expect(3)).not_to respond_to(:should)
  139 + expect(expect(3)).not_to respond_to(:should_not)
  140 + end
  141 + end
  142 +
  143 + context 'when both :expect and :should are enabled' do
  144 + before { RSpec.stub(:warn) }
  145 +
  146 + it 'allows `expect {}.should` to be used' do
  147 + sandboxed do
  148 + configure_syntax [:should, :expect]
  149 + expect { raise "boom" }.should raise_error("boom")
  150 + expect { }.should_not raise_error
  151 + end
  152 + end
  153 +
  154 + it 'prints a deprecation notice when `expect {}.should` is used' do
  155 + sandboxed do
  156 + configure_syntax [:should, :expect]
  157 +
  158 + RSpec.should_receive(:warn).with(/please use `expect \{ \}.to.*instead/)
  159 + expect { raise "boom" }.should raise_error("boom")
  160 +
  161 + RSpec.should_receive(:warn).with(/please use `expect \{ \}.to_not.*instead/)
  162 + expect { }.should_not raise_error
  163 + end
  164 + end
  165 + end
124 166 end
125 167
126 168 describe "configuring rspec-expectations directly" do
4 spec/rspec/matchers/cover_spec.rb
@@ -2,6 +2,10 @@
2 2
3 3 if (1..2).respond_to?(:cover?)
4 4 describe "should cover(expected)" do
  5 + it_behaves_like "an RSpec matcher", :valid_value => (1..10), :invalid_value => (20..30) do
  6 + let(:matcher) { cover(5) }
  7 + end
  8 +
5 9 context "for a range target" do
6 10 it "passes if target covers expected" do
7 11 (1..10).should cover(5)
4 spec/rspec/matchers/eq_spec.rb
@@ -3,6 +3,10 @@
3 3 module RSpec
4 4 module Matchers
5 5 describe "eq" do
  6 + it_behaves_like "an RSpec matcher", :valid_value => 1, :invalid_value => 2 do
  7 + let(:matcher) { eq(1) }
  8 + end
  9 +
6 10 it "is diffable" do
7 11 eq(1).should be_diffable
8 12 end
4 spec/rspec/matchers/eql_spec.rb
@@ -3,6 +3,10 @@
3 3 module RSpec
4 4 module Matchers
5 5 describe "eql" do
  6 + it_behaves_like "an RSpec matcher", :valid_value => 1, :invalid_value => 2 do
  7 + let(:matcher) { eql(1) }
  8 + end
  9 +
6 10 it "is diffable" do
7 11 eql(1).should be_diffable
8 12 end
3  spec/rspec/matchers/equal_spec.rb
@@ -2,6 +2,9 @@
2 2 module RSpec
3 3 module Matchers
4 4 describe "equal" do
  5 + it_behaves_like "an RSpec matcher", :valid_value => :a, :invalid_value => :b do
  6 + let(:matcher) { equal(:a) }
  7 + end
5 8
6 9 def inspect_object(o)
7 10 "#<#{o.class}:#{o.object_id}> => #{o.inspect}"
6 spec/rspec/matchers/exist_spec.rb
... ... @@ -1,6 +1,12 @@
1 1 require 'spec_helper'
  2 +require 'ostruct'
2 3
3 4 describe "exist matcher" do
  5 + it_behaves_like "an RSpec matcher", :valid_value => OpenStruct.new(:exist? => true),
  6 + :invalid_value => OpenStruct.new(:exist? => false) do
  7 + let(:matcher) { exist }
  8 + end
  9 +
4 10 context "when the object does not respond to #exist? or #exists?" do
5 11 subject { mock }
6 12
5 spec/rspec/matchers/has_spec.rb
... ... @@ -1,6 +1,11 @@
1 1 require 'spec_helper'
2 2
3 3 describe "should have_sym(*args)" do
  4 + it_behaves_like "an RSpec matcher", :valid_value => { :a => 1 },
  5 + :invalid_value => {} do
  6 + let(:matcher) { have_key(:a) }
  7 + end
  8 +
4 9 it "passes if #has_sym?(*args) returns true" do
5 10 {:a => "A"}.should have_key(:a)
6 11 end
3  spec/rspec/matchers/have_spec.rb
@@ -29,6 +29,9 @@ def create_collection_owner_with(n)
29 29 end
30 30
31 31 describe "should have(n).items" do
  32 + it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
  33 + let(:matcher) { have(2).items }
  34 + end
32 35
33 36 it "passes if target has a collection of items with n members" do
34 37 owner = create_collection_owner_with(3)
4 spec/rspec/matchers/include_spec.rb
@@ -6,6 +6,10 @@
6 6 end
7 7
8 8 describe "should include(with_one_arg)" do
  9 + it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
  10 + let(:matcher) { include(2) }
  11 + end
  12 +
9 13 context "for a string target" do
10 14 it "passes if target includes expected" do
11 15 "abc".should include("a")
4 spec/rspec/matchers/match_array_spec.rb
@@ -15,6 +15,10 @@ def ==(other)
15 15 end
16 16
17 17 describe "using match_array with expect" do
  18 + it_behaves_like "an RSpec matcher", :valid_value => [1, 2], :invalid_value => [1] do
  19 + let(:matcher) { match_array([2, 1]) }
  20 + end
  21 +
18 22 it "passes a valid positive expectation" do
19 23 expect([1, 2]).to match_array [2, 1]
20 24 end
4 spec/rspec/matchers/match_spec.rb
... ... @@ -1,6 +1,10 @@
1 1 require 'spec_helper'
2 2
3 3 describe "should match(expected)" do
  4 + it_behaves_like "an RSpec matcher", :valid_value => 'ab', :invalid_value => 'bc' do
  5 + let(:matcher) { match(/a/) }
  6 + end
  7 +
4 8 it "passes when target (String) matches expected (Regexp)" do
5 9 "string".should match(/tri/)
6 10 end
5 spec/rspec/matchers/raise_error_spec.rb
... ... @@ -1,6 +1,11 @@
1 1 require 'spec_helper'
2 2
3 3 describe "should raise_error" do
  4 + it_behaves_like("an RSpec matcher", :valid_value => lambda { raise "boom" },
  5 + :invalid_value => lambda { }) do
  6 + let(:matcher) { raise_error(/boom/) }
  7 + end
  8 +
4 9 it "passes if anything is raised" do
5 10 lambda {raise}.should raise_error
6 11 end
3  spec/rspec/matchers/respond_to_spec.rb
... ... @@ -1,6 +1,9 @@
1 1 require 'spec_helper'
2 2
3 3 describe "should respond_to(:sym)" do
  4 + it_behaves_like "an RSpec matcher", :valid_value => "s", :invalid_value => 5 do
  5 + let(:matcher) { respond_to(:upcase) }
  6 + end
4 7
5 8 it "passes if target responds to :sym" do
6 9 Object.new.should respond_to(:methods)
4 spec/rspec/matchers/satisfy_spec.rb
... ... @@ -1,6 +1,10 @@
1 1 require 'spec_helper'
2 2
3 3 describe "should satisfy { block }" do
  4 + it_behaves_like "an RSpec matcher", :valid_value => true, :invalid_value => false do
  5 + let(:matcher) { satisfy { |v| v } }
  6 + end
  7 +
4 8 it "describes itself" do
5 9 satisfy.description.should eq("satisfy block")
6 10 end
8 spec/rspec/matchers/start_with_end_with_spec.rb
... ... @@ -1,6 +1,10 @@
1 1 require "spec_helper"
2 2
3 3 describe "should start_with" do
  4 + it_behaves_like "an RSpec matcher", :valid_value => "ab", :invalid_value => "bc" do
  5 + let(:matcher) { start_with("a") }
  6 + end
  7 +
4 8 context "with a string" do
5 9 it "passes if it matches the start of the actual string" do
6 10 "this string".should start_with "this str"
@@ -87,6 +91,10 @@
87 91 end
88 92
89 93 describe "should end_with" do
  94 + it_behaves_like "an RSpec matcher", :valid_value => "ab", :invalid_value => "bc" do
  95 + let(:matcher) { end_with("b") }
  96 + end
  97 +
90 98 context "with a string" do
91 99 it "passes if it matches the end of the actual string" do
92 100 "this string".should end_with "is string"
5 spec/rspec/matchers/throw_symbol_spec.rb
@@ -2,6 +2,11 @@
2 2
3 3 module RSpec::Matchers::BuiltIn
4 4 describe ThrowSymbol do
  5 + it_behaves_like("an RSpec matcher", :valid_value => lambda { throw :foo },
  6 + :invalid_value => lambda { }) do
  7 + let(:matcher) { throw_symbol(:foo) }
  8 + end
  9 +
5 10 describe "with no args" do
6 11 before(:each) { @matcher = throw_symbol }
7 12
28 spec/rspec/matchers/yield_spec.rb
@@ -35,6 +35,13 @@ def each_arg(*args, &block)
35 35
36 36 describe "yield_control matcher" do
37 37 include YieldHelpers
  38 + extend YieldHelpers
  39 +
  40 + it_behaves_like "an RSpec matcher",
  41 + :valid_value => lambda { |b| _yield_with_no_args(&b) },
  42 + :invalid_value => lambda { |b| _dont_yield(&b) } do
  43 + let(:matcher) { yield_control }
  44 + end
38 45
39 46 it 'has a description' do
40 47 yield_control.description.should eq("yield control")
@@ -90,6 +97,13 @@ def each_arg(*args, &block)
90 97
91 98 describe "yield_with_no_args matcher" do
92 99 include YieldHelpers
  100 + extend YieldHelpers
  101 +
  102 + it_behaves_like "an RSpec matcher",
  103 + :valid_value => lambda { |b| _yield_with_no_args(&b) },
  104 + :invalid_value => lambda { |b| _dont_yield(&b) } do
  105 + let(:matcher) { yield_with_no_args }
  106 + end
93 107
94 108 it 'has a description' do
95 109 yield_with_no_args.description.should eq("yield with no args")
@@ -154,6 +168,13 @@ def each_arg(*args, &block)
154 168
155 169 describe "yield_with_args matcher" do
156 170 include YieldHelpers
  171 + extend YieldHelpers
  172 +
  173 + it_behaves_like "an RSpec matcher",
  174 + :valid_value => lambda { |b| _yield_with_args(1, &b) },
  175 + :invalid_value => lambda { |b| _dont_yield(&b) } do
  176 + let(:matcher) { yield_with_args }
  177 + end
157 178
158 179 it 'has a description' do
159 180 yield_with_args.description.should eq("yield with args")
@@ -283,6 +304,13 @@ def each_arg(*args, &block)
283 304
284 305 describe "yield_successive_args matcher" do
285 306 include YieldHelpers
  307 + extend YieldHelpers
  308 +
  309 + it_behaves_like "an RSpec matcher",
  310 + :valid_value => lambda { |b| [1, 2].each(&b) },
  311 + :invalid_value => lambda { |b| _dont_yield(&b) } do
  312 + let(:matcher) { yield_successive_args(1, 2) }
  313 + end
286 314
287 315 it 'has a description' do
288 316 yield_successive_args(1, 3).description.should eq("yield successive args(1, 3)")
13 spec/support/shared_examples.rb
... ... @@ -0,0 +1,13 @@
  1 +shared_examples_for "an RSpec matcher" do |options|
  2 + let(:valid_value) { options.fetch(:valid_value) }
  3 + let(:invalid_value) { options.fetch(:invalid_value) }
  4 +
  5 + it 'matches a valid value when using #== so it can be composed' do
  6 + expect(matcher).to eq(valid_value)
  7 + end
  8 +
  9 + it 'does not match an invalid value when using #== so it can be composed' do
  10 + expect(matcher).not_to eq(invalid_value)
  11 + end
  12 +end
  13 +

No commit comments for this range

Something went wrong with that request. Please try again.