diff --git a/lib/cosmos/script/extract.rb b/lib/cosmos/script/extract.rb index fa3bdea83..f25d86bc6 100644 --- a/lib/cosmos/script/extract.rb +++ b/lib/cosmos/script/extract.rb @@ -130,7 +130,7 @@ def extract_fields_from_check_text(text) return [target_name, packet_name, item_name, comparison_to_eval] if split_string.length == 3 raise "ERROR: Check improperly specified: #{text}" if split_string.length < 4 split_string = text.split(/ /) # Split on regex spaces to preserve spaces in comparison - index = split_string.index(item_name) + index = split_string.rindex(item_name) comparison_to_eval = split_string[(index + 1)..(split_string.length - 1)].join(" ") raise "ERROR: Use '==' instead of '=': #{text}" if split_string[3] == '=' return [target_name, packet_name, item_name, comparison_to_eval] diff --git a/spec/script/extract_spec.rb b/spec/script/extract_spec.rb index 34563d0ae..56bc4065d 100644 --- a/spec/script/extract_spec.rb +++ b/spec/script/extract_spec.rb @@ -148,6 +148,10 @@ module Cosmos expect(extract_fields_from_check_text("TARGET PACKET ITEM < 5")).to eql(['TARGET', 'PACKET', 'ITEM', '< 5']) end + it "should support target packet items named the same" do + expect(extract_fields_from_check_text("TEST TEST TEST == 5")).to eql(['TEST', 'TEST', 'TEST', '== 5']) + end + it "should complain about trying to do an = comparison" do expect { extract_fields_from_check_text("TARGET PACKET ITEM = 5") }.to raise_error(/ERROR: Use/) end @@ -160,4 +164,3 @@ module Cosmos end end -