diff --git a/lib/inspec/utils/filter.rb b/lib/inspec/utils/filter.rb index e08550425..435732dda 100644 --- a/lib/inspec/utils/filter.rb +++ b/lib/inspec/utils/filter.rb @@ -256,7 +256,7 @@ module FilterTable end def matches(x, y) - x === y # rubocop:disable Style/CaseEquality + y === x # rubocop:disable Style/CaseEquality end def filter_raw_data(current_raw_data, field, desired_value) diff --git a/test/unit/utils/filter_table_test.rb b/test/unit/utils/filter_table_test.rb index 681cf90c6..7f1238bd1 100644 --- a/test/unit/utils/filter_table_test.rb +++ b/test/unit/utils/filter_table_test.rb @@ -35,6 +35,11 @@ describe FilterTable do _(resource.new(nil).where { false }.params).must_equal [] end + it "supports range" do + factory.add_accessor(:where).connect(resource, :data) + _(instance.where({ foo: (3..5) }).params).must_equal [data[0]] + end + it "retrieves the resource from all entries" do factory.add_accessor(:where) .add(:baz?) { |x| x.resource } # rubocop: disable Style/SymbolProc @@ -181,4 +186,16 @@ describe FilterTable do _(instance.baz(/zzz/).params).must_equal [] end end + + describe "with a range filter" do + before { factory.add(:foo).connect(resource, :data) } + + it "filter and retrieves data with matching range" do + _(instance.foo((3..5)).params).must_equal [data[0]] + end + + it "filter and retrieves empty result if no data in matching range" do + _(instance.foo((4..5)).params).must_equal [] + end + end end