Skip to content

Commit

Permalink
Improve check for paths as Hashes in CaptureOptions
Browse files Browse the repository at this point in the history
Closes bbc#536
  • Loading branch information
Steve Day authored and Steve Day committed Sep 6, 2018
1 parent f4859e5 commit 7734de1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/wraith/helpers/capture_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions spec/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7734de1

Please sign in to comment.