From 7734de193aa9ebb9c271d22b574f51eba95f0636 Mon Sep 17 00:00:00 2001 From: Steve Day Date: Thu, 6 Sep 2018 14:20:27 +0100 Subject: [PATCH] Improve check for paths as Hashes in CaptureOptions Closes #536 --- lib/wraith/helpers/capture_options.rb | 2 +- spec/helper_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/wraith/helpers/capture_options.rb b/lib/wraith/helpers/capture_options.rb index 9673b0d4..f84bdc32 100644 --- a/lib/wraith/helpers/capture_options.rb +++ b/lib/wraith/helpers/capture_options.rb @@ -47,6 +47,6 @@ def compare_urls(path) end def casper?(options) - options["path"] ? options["path"] : options + options.is_a?(String) ? options : options.fetch("path") end end diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb index 20566862..b6fea29c 100644 --- a/spec/helper_spec.rb +++ b/spec/helper_spec.rb @@ -28,4 +28,27 @@ end end + describe "CaptureOptions" do + let(:capture_options) { CaptureOptions.new('', nil) } + + describe "#casper?" do + it "returns options when options is a string" do + actual = capture_options.casper?('/test/path') + expected = '/test/path' + expect(actual).to eq expected + end + + context "when options is a Hash" do + it "returns options['path']" do + actual = capture_options.casper?({'path' => '/test/path'}) + expected = '/test/path' + expect(actual).to eq expected + end + + it "raises a KeyError if options['path'] is missing" do + expect { capture_options.casper?({}) }.to raise_error(KeyError) + end + end + end + end end