Skip to content

Commit b6460e5

Browse files
committed
Let :be_filtered pass on an array with 1 item
1 parent 09356fe commit b6460e5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/rspec-api/matchers/filter/matcher.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(options = {})
1313
end
1414

1515
def matches?(response)
16-
super && all_objects_have_field? && has_two_objects? && is_filtered?
16+
super && all_objects_have_field? && has_one_object? && is_filtered?
1717
end
1818

1919
def description
@@ -34,8 +34,8 @@ def all_objects_have_field?
3434
end
3535
end
3636

37-
def has_two_objects?
38-
if json.length < 2
37+
def has_one_object?
38+
if json.length < 1
3939
msg = "Cannot test filtering on an array with #{json.length} items"
4040
raise RSpec::Core::Pending::PendingDeclaredInExample.new msg
4141
else

spec/rspec-api/matchers/be_filtered_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
end
5151
end
5252

53-
it 'is pending given a JSON collection with less than 2 objects' do
54-
response.body = '[{"id": 1}]'
53+
it 'is pending given a JSON collection with less than 1 object' do
54+
response.body = '[]'
5555
expect {
5656
expect(response).to be_filtered by: :id
57-
}.to be_pending_with %r{Cannot test filtering on an array with 1 item}
57+
}.to be_pending_with %r{Cannot test filtering on an array with 0 items}
5858
end
5959

6060
it 'fails given a collection of objects without the filtering field' do

0 commit comments

Comments
 (0)