spec/rspec/matchers/matcher_spec.rb in rspec-expectations-2.99.0.beta2 vs spec/rspec/matchers/matcher_spec.rb in rspec-expectations-2.99.0.rc1
- old
+ new
@@ -64,10 +64,33 @@
expect(m).to be_a(Enumerable)
expect(m).to be_a(Comparable)
end
end
+ context "matching blocks" do
+ it 'warns when matching blocks by default' do
+ matcher = RSpec::Matchers::DSL::Matcher.new(:not_supporting_blocks) do
+ match { true }
+ end.for_expected
+
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 2, /block expectation/)
+ expect(3).to matcher
+ expect { 3 }.to matcher
+ end
+
+ it 'does not when if it declares `supports_block_expectations`' do
+ matcher = RSpec::Matchers::DSL::Matcher.new(:supporting_blocks) do
+ match { true }
+ supports_block_expectations
+ end.for_expected
+
+ expect_no_deprecation
+ expect(3).to matcher
+ expect { 3 }.to matcher
+ end
+ end
+
context "without overrides" do
before(:each) do
@matcher = RSpec::Matchers::DSL::Matcher.new(:be_a_multiple_of) do |multiple|
match do |actual|
actual % multiple == 0
@@ -602,7 +625,36 @@
expect(example).to __raise_no_method_error
end.to raise_error(/RSpec::Matchers::DSL::Matcher/)
end
end
+ describe "#matcher_execution_context" do
+ before { allow_deprecation }
+
+ let(:matcher) do
+ RSpec::Matchers::DSL::Matcher.new :foo do |expected|
+ end.for_expected(:bar)
+ end
+
+ it 'can be set' do
+ expect {
+ matcher.matcher_execution_context = :the_context
+ }.to change(matcher, :matcher_execution_context).to(:the_context)
+ end
+
+ it 'is the target of method_missing delegation' do
+ matcher.matcher_execution_context = double(:abcd => "efg")
+ expect(matcher.abcd).to eq("efg")
+ end
+
+ specify "the writer is deprecated" do
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /matcher_execution_context/)
+ matcher.matcher_execution_context = :the_context
+ end
+
+ specify "the reader is deprecated" do
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /matcher_execution_context/)
+ matcher.matcher_execution_context
+ end
+ end
end
end