GitHub PullRequestReviewCommentEvent at 2014-04-16 13:31:18
Repository: rspec-expectations
Actor: yelled3
Payload: {"comment":{"url":"https://api.github.com/repos/rspec/rspec-expectations/pulls/comments/11683603","id":11683603,"diff_hunk":"@@ -0,0 +1,230 @@\n+module RSpec::Matchers::BuiltIn\n+  describe All do\n+\n+    it_behaves_like 'an RSpec matcher', :valid_value => ['A', 'A', 'A'], :invalid_value => ['A', 'A', 'B'] do\n+      let(:matcher) { all( eq('A') ) }\n+    end\n+\n+    describe 'description' do\n+      it 'provides a description' do\n+        matcher = all( eq('A') )\n+        expect(matcher.description).to eq 'all eq \"A\"'\n+      end\n+    end\n+\n+    context 'when single matcher is given' do\n+\n+      describe 'expect(...).to all(expected)' do\n+\n+        it 'can pass' do\n+          expect(['A', 'A', 'A']).to all( eq('A') )\n+        end\n+\n+        describe 'failure message' do\n+\n+          context 'when the matcher has single-line failure message' do\n+            it 'returns the index of the failed object' do\n+              expect {\n+                expect(['A', 'A', 'A', 5, 'A']).to all( be_a(String) )\n+              }.to fail_with(dedent <<-EOS)\n+              |expected [\"A\", \"A\", \"A\", 5, \"A\"] to all be a kind of String\n+              |\n+              |   object at index 3 failed to match:\n+              |      expected 5 to be a kind of String\n+              EOS\n+            end\n+\n+            it 'returns the indexes of all failed objects, not just the first one' do\n+              expect {\n+                expect(['A', 'A', 'A', 5, 6]).to all( be_a(String) )\n+              }.to fail_with(dedent <<-EOS)\n+              |expected [\"A\", \"A\", \"A\", 5, 6] to all be a kind of String\n+              |\n+              |   object at index 3 failed to match:\n+              |      expected 5 to be a kind of String\n+              |\n+              |   object at index 4 failed to match:\n+              |      expected 6 to be a kind of String\n+              EOS\n+            end\n+          end\n+\n+\n+          context 'when the matcher has multi-line failure message' do\n+            it 'returns the index of the failed object' do\n+              expect {\n+                expect(['A', 'A', 'A', 'C', 'A']).to all( eq('A') )\n+              }.to fail_with(dedent <<-EOS)\n+              |expected [\"A\", \"A\", \"A\", \"C\", \"A\"] to all eq \"A\"\n+              |\n+              |   object at index 3 failed to match:\n+              |      expected: \"A\"\n+              |           got: \"C\"\n+              |\n+              |      (compared using ==)\n+              EOS\n+            end\n+\n+            it 'returns the indexes of all failed objects, not just the first one' do\n+              expect {\n+                expect(['A', 'B', 'A', 'C', 'A']).to all( eq('A') )\n+              }.to fail_with(dedent <<-EOS)\n+              |expected [\"A\", \"B\", \"A\", \"C\", \"A\"] to all eq \"A\"\n+              |\n+              |   object at index 1 failed to match:\n+              |      expected: \"A\"\n+              |           got: \"B\"\n+              |\n+              |      (compared using ==)\n+              |\n+              |   object at index 3 failed to match:\n+              |      expected: \"A\"\n+              |           got: \"C\"\n+              |\n+              |      (compared using ==)\n+              EOS\n+            end\n+          end\n+\n+        end\n+      end\n+    end\n+\n+    context 'when composed matcher is given' do\n+\n+      describe 'expect(...).to all(expected)' do\n+        it 'can pass' do\n+          expect([3, 4, 7, 8]).to all( be_between(2, 5).or be_between(6, 9) )\n+        end\n+      end\n+\n+      describe 'failure message' do\n+\n+        context 'when a single object fails' do\n+          it 'returns the index of the failed object for the composed matcher' do\n+            expect {\n+              expect([3, 4, 7, 28]).to all( be_between(2, 5).or be_between(6, 9) )\n+            }.to fail_with(dedent <<-EOS)\n+              |expected [3, 4, 7, 28] to all be between 2 and 5 (inclusive) or be between 6 and 9 (inclusive)\n+              |\n+              |   object at index 3 failed to match:\n+              |      expected 28 to be between 2 and 5 (inclusive) or expected 28 to be between 6 and 9 (inclusive)\n+            EOS\n+          end\n+        end\n+\n+        context 'when a multiple objects fails' do\n+          it 'returns the indexes of the failed objects for the composed matcher, not just the first one' do\n+            expect {\n+              expect([3, 4, 27, 22]).to all( be_between(2, 5).or be_between(6, 9) )\n+            }.to fail_with(dedent <<-EOS)\n+              |expected [3, 4, 27, 22] to all be between 2 and 5 (inclusive) or be between 6 and 9 (inclusive)\n+              |\n+              |   object at index 2 failed to match:\n+              |      expected 27 to be between 2 and 5 (inclusive) or expected 27 to be between 6 and 9 (inclusive)\n+              |\n+              |   object at index 3 failed to match:\n+              |      expected 22 to be between 2 and 5 (inclusive) or expected 22 to be between 6 and 9 (inclusive)\n+            EOS\n+          end\n+        end\n+      end\n+    end\n+\n+    RSpec::Matchers.define :custom_include do |*args|\n+      match { |actual| expect(actual).to include(*args) }\n+    end\n+\n+    shared_examples \"making a copy\" do |copy_method|\n+      context \"when making a copy via `#{copy_method}`\" do\n+\n+        let(:base_matcher) { eq(3) }\n+        let(:all_matcher) { all( base_matcher ) }\n+        let(:copied_matcher) { all_matcher.__send__(copy_method) }\n+\n+        it \"uses a copy of the base matcher\" do\n+          expect(copied_matcher).not_to equal(all_matcher)\n+          expect(copied_matcher.matcher).not_to equal(base_matcher)\n+          expect(copied_matcher.matcher).to be_a(base_matcher.class)\n+          expect(copied_matcher.matcher.expected).to eq(3)\n+        end\n+\n+        context 'when using a custom matcher' do\n+\n+          let(:base_matcher) { custom_include(3) }\n+\n+          it 'copies custom matchers properly so they can work even though they have singleton behavior' do\n+            expect(copied_matcher).not_to equal(all_matcher)\n+            expect(copied_matcher.matcher).not_to equal(base_matcher)\n+            expect([[3]]).to copied_matcher\n+            expect { expect([[4]]).to copied_matcher }.to fail_matching(\"expected [4]\")\n+          end\n+\n+        end\n+\n+      end\n+    end\n+\n+    include_examples 'making a copy', :clone\n+    include_examples 'making a copy', :dup\n+\n+    RSpec::Matchers.define :have_string_length do |expected|\n+      match do |actual|\n+        @actual = actual\n+        string_length == expected\n+      end\n+\n+      def string_length\n+        @string_length ||= @actual.length\n+      end\n+    end\n+\n+    context \"when using a matcher instance that memoizes state multiple times in a composed expression\" do\n+      it \"works properly in spite of the memoization\" do\n+        expect([\"foo\", \"bar\", \"xyz\"]).to all( have_string_length(3) )\n+      end","path":"spec/rspec/matchers/built_in/all_spec.rb","position":185,"original_position":185,"commit_id":"535f5eedb619fa5585f98bd1f181d46ff9e77112","original_commit_id":"535f5eedb619fa5585f98bd1f181d46ff9e77112","user":{"login":"yelled3","id":818124,"avatar_url":"https://avatars.githubusercontent.com/u/818124?","gravatar_id":"faa2eb4cbc87cd14cb2ee9a39c31d9d1","url":"https://api.github.com/users/yelled3","html_url":"https://github.com/yelled3","followers_url":"https://api.github.com/users/yelled3/followers","following_url":"https://api.github.com/users/yelled3/following{/other_user}","gists_url":"https://api.github.com/users/yelled3/gists{/gist_id}","starred_url":"https://api.github.com/users/yelled3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yelled3/subscriptions","organizations_url":"https://api.github.com/users/yelled3/orgs","repos_url":"https://api.github.com/users/yelled3/repos","events_url":"https://api.github.com/users/yelled3/events{/privacy}","received_events_url":"https://api.github.com/users/yelled3/received_events","type":"User","site_admin":false},"body":"cheers - used your example :-)","created_at":"2014-04-16T13:31:18Z","updated_at":"2014-04-16T13:31:18Z","html_url":"https://github.com/rspec/rspec-expectations/pull/491#discussion_r11683603","pull_request_url":"https://api.github.com/repos/rspec/rspec-expectations/pulls/491","_links":{"self":{"href":"https://api.github.com/repos/rspec/rspec-expectations/pulls/comments/11683603"},"html":{"href":"https://github.com/rspec/rspec-expectations/pull/491#discussion_r11683603"},"pull_request":{"href":"https://api.github.com/repos/rspec/rspec-expectations/pulls/491"}}}}