Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions bin/standardrb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'standardrb' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("standard", "standardrb")
45 changes: 36 additions & 9 deletions spec/lib/votd/bible_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,30 @@
end
end

context "When an error occurrs" do
before do
fake_a_broken_uri(uri_regex)
context "When an error occurs" do
context "with a malformed response body" do
before { fake_a_broken_uri(uri_regex) }
include_examples "falls back to defaults"
end

context "with a network timeout" do
before { stub_request(:get, uri_regex).to_timeout }
include_examples "falls back to defaults"
end

context "with a connection failure" do
before { stub_request(:get, uri_regex).to_raise(SocketError) }
include_examples "falls back to defaults"
end

context "with an HTTP 500 response" do
before { stub_request(:get, uri_regex).to_return(status: 500, body: "Internal Server Error") }
include_examples "falls back to defaults"
end

it "falls back to default VotD values" do
expect(votd.version).to eq Votd::Base::DEFAULT_BIBLE_VERSION
expect(votd.reference).to eq Votd::Base::DEFAULT_BIBLE_REFERENCE
expect(votd.text).to eq Votd::Base::DEFAULT_BIBLE_TEXT
context "with an empty response body" do
before { stub_request(:get, uri_regex).to_return(body: "") }
include_examples "falls back to defaults"
end
end

Expand Down Expand Up @@ -152,10 +167,22 @@
expect(votd_nlt.link).to eq "https://www.biblegateway.com/passage/?search=Colossians+3%3A16&version=51"
end

context "with an invalid version code" do
it "throws an error" do
context "with an invalid version argument" do
it "raises InvalidBibleVersion for an unknown symbol" do
expect { Votd::BibleGateway.new(:foo) }.to raise_error(Votd::InvalidBibleVersion)
end

it "raises InvalidBibleVersion for nil" do
expect { Votd::BibleGateway.new(nil) }.to raise_error(Votd::InvalidBibleVersion)
end

it "raises InvalidBibleVersion for a String" do
expect { Votd::BibleGateway.new("niv") }.to raise_error(Votd::InvalidBibleVersion)
end

it "raises InvalidBibleVersion for an Integer" do
expect { Votd::BibleGateway.new(31) }.to raise_error(Votd::InvalidBibleVersion)
end
end
end
end
27 changes: 21 additions & 6 deletions spec/lib/votd/netbible_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,29 @@
end

context "When an error occurs" do
before do
fake_a_broken_uri(Votd::NetBible::ENDPOINT_URL)
context "with a malformed response body" do
before { fake_a_broken_uri(Votd::NetBible::ENDPOINT_URL) }
include_examples "falls back to defaults"
end

context "with a network timeout" do
before { stub_request(:get, Votd::NetBible::ENDPOINT_URL).to_timeout }
include_examples "falls back to defaults"
end

context "with a connection failure" do
before { stub_request(:get, Votd::NetBible::ENDPOINT_URL).to_raise(SocketError) }
include_examples "falls back to defaults"
end

context "with an HTTP 500 response" do
before { stub_request(:get, Votd::NetBible::ENDPOINT_URL).to_return(status: 500, body: "Internal Server Error") }
include_examples "falls back to defaults"
end

it "falls back to default VotD values" do
expect(votd.version).to eq Votd::Base::DEFAULT_BIBLE_VERSION
expect(votd.reference).to eq Votd::Base::DEFAULT_BIBLE_REFERENCE
expect(votd.text).to eq Votd::Base::DEFAULT_BIBLE_TEXT
context "with an empty response body" do
before { stub_request(:get, Votd::NetBible::ENDPOINT_URL).to_return(body: "") }
include_examples "falls back to defaults"
end
end

Expand Down
27 changes: 21 additions & 6 deletions spec/lib/votd/ourmanna_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,29 @@
end

context "When an error occurs" do
before do
fake_a_broken_uri(Votd::OurManna::ENDPOINT_URL)
context "with a malformed response body" do
before { fake_a_broken_uri(Votd::OurManna::ENDPOINT_URL) }
include_examples "falls back to defaults"
end

context "with a network timeout" do
before { stub_request(:get, Votd::OurManna::ENDPOINT_URL).to_timeout }
include_examples "falls back to defaults"
end

context "with a connection failure" do
before { stub_request(:get, Votd::OurManna::ENDPOINT_URL).to_raise(SocketError) }
include_examples "falls back to defaults"
end

context "with an HTTP 500 response" do
before { stub_request(:get, Votd::OurManna::ENDPOINT_URL).to_return(status: 500, body: "Internal Server Error") }
include_examples "falls back to defaults"
end

it "falls back to default VotD values" do
expect(votd.version).to eq Votd::Base::DEFAULT_BIBLE_VERSION
expect(votd.reference).to eq Votd::Base::DEFAULT_BIBLE_REFERENCE
expect(votd.text).to eq Votd::Base::DEFAULT_BIBLE_TEXT
context "with an empty response body" do
before { stub_request(:get, Votd::OurManna::ENDPOINT_URL).to_return(body: "") }
include_examples "falls back to defaults"
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ def fake_a_uri(uri, fixture_path)
def fake_a_broken_uri(uri)
stub_request(:get, uri).to_return(body: "Oopsies")
end

RSpec.shared_examples "falls back to defaults" do
it "falls back to default VotD values" do
expect(votd.version).to eq Votd::Base::DEFAULT_BIBLE_VERSION
expect(votd.reference).to eq Votd::Base::DEFAULT_BIBLE_REFERENCE
expect(votd.text).to eq Votd::Base::DEFAULT_BIBLE_TEXT
end
end